Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System.Data;

private BCE.AutoCount.Report.BaseReport __report;

private void Report_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
__report = Report as BCE.AutoCount.Report.BaseReport;

DataSet ds = (DataSet) Report.DataSource;

DataTable optionTable = ds.Tables["Report Option"];

if (optionTable.Rows[0]["ShowCriteria"].ToString() == "No")
{
PanelCriteria.Visible = false;
}

if (optionTable.Rows[0]["GroupBy"].ToString() == "None")
{
GroupHeader3.Visible = false;
}

new BCE.AutoCount.Report.ReportDrillDown(__report.DBSetting, Report, "DocType", "DocKey", new string[] {"xrLabel24", "xrLabel25", "xrLabel26", "xrLabel27", "xrInOutQty", "xrBalQty", "xrLabel4", "xrLabel31", "xrLabel32", "xrLabel37"});
}

private void Detail1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
decimal inQty = __report.DecimalSetting.RoundQuantity(DetailReport.GetCurrentColumnValue("InQty"));

if (inQty > 0)
xrInOutQty.Text = __report.DecimalSetting.FormatQuantity(inQty);
else
{
decimal outQty = __report.DecimalSetting.RoundQuantity(DetailReport.GetCurrentColumnValue("OutQty"));

xrInOutQty.Text = __report.DecimalSetting.FormatQuantity(outQty);
}

decimal balQty = __report.DecimalSetting.RoundQuantity(DetailReport.GetCurrentColumnValue("Balance"));

if (balQty < 0)
xrBalQty.ForeColor = Color.Red;
else
xrBalQty.ForeColor = Color.Black;

string AAA = DetailReport.GetCurrentColumnValue("DtlKey").ToString();
string ee = DetailReport.GetCurrentColumnValue("DocKey").ToString();
string type= DetailReport.GetCurrentColumnValue("DocType").ToString();
if (type =="IV")
{
xrLabel10.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Pltno from IVDTL WHERE DtlKey=?", AAA).ToString();
xrLabel41.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Rmk1 from IVDTL WHERE DtlKey=?", AAA).ToString();
xrLabel1.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Desc2 from IV WHERE DocKey=?", ee).ToString();

}
else if (type == "PI")
{ xrLabel10.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Pltno from PIDTL WHERE DtlKey=?", AAA).ToString();
xrLabel41.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Rmk1 from PIDTL WHERE DtlKey=?", AAA).ToString();
xrLabel1.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Desc2 from PI WHERE DocKey=?", ee).ToString();
}
else if (type == "DO")
{ xrLabel10.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Pltno from DODTL WHERE DtlKey=?", AAA).ToString();
xrLabel41.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Rmk1 from DODTL WHERE DtlKey=?", AAA).ToString();
xrLabel1.Text = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT UDF_Desc2 from DO WHERE DocKey=?", ee).ToString();

}
else
{ xrLabel10.Text ="";
xrLabel41.Text ="";
xrLabel1.Text ="";
}
}

private void xrLabel3_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
string docType = DetailReport.GetCurrentColumnValue("DocType").ToString();
string dtlKey = DetailReport.GetCurrentColumnValue("DtlKey").ToString();

string fromDocNo = GetTransferFromDocNo(docType, dtlKey);
string toDocNo = GetTransferToDocNo(docType, dtlKey);

(sender as XRLabel).Text = (fromDocNo == "" && toDocNo == "") ? "" :
(fromDocNo == "") ? string.Format("Trf.To: {0}", toDocNo) :
(toDocNo == "") ? string.Format("Trf.From: {0}", fromDocNo) :
string.Format("Trf.From: {0} Trf.To: {1}", fromDocNo, toDocNo);
}

private string GetTransferFromDocNo(string DocType, string DtlKey)
{
string docDtl = "";
string fromDocNo = "";
object oFromDocNo = null;

if (DocType == "DO")
docDtl = "DODTL";
else if (DocType == "IV")
docDtl = "IVDTL";
else if (DocType == "CS")
docDtl = "CSDTL";
else if (DocType == "CN")
docDtl = "CNDTL";
else if (DocType == "DR")
docDtl = "DRDTL";
else if (DocType == "GR")
docDtl = "GRDTL";
else if (DocType == "PI")
docDtl = "PIDTl";
else if (DocType == "PR")
docDtl = "PRDTL";
else if (DocType == "GT")
docDtl = "GTDTL";
else
docDtl = "";

if (docDtl != "")
oFromDocNo = BCE.AutoCount.Application.DBSetting.ExecuteScalar("SELECT FromDocNo FROM " + docDtl + " WHERE DtlKey=?", DtlKey);
if (oFromDocNo != null)
fromDocNo = oFromDocNo.ToString();
return fromDocNo;
}

private string GetTransferToDocNo(string DocType, string DtlKey)
{
string list = "";
if (DocType == "DO")
{
list = GetToDocNoList(list, "IV", DtlKey);
list = GetToDocNoList(list, "DR", DtlKey);
}
else if (DocType == "IV")
{
list = GetToDocNoList(list, "CN", DtlKey);
}
else if (DocType == "CS")
{
list = GetToDocNoList(list, "CN", DtlKey);
}
else if (DocType == "GR")
{
list = GetToDocNoList(list, "PI", DtlKey);
list = GetToDocNoList(list, "GT", DtlKey);
}
else if (DocType == "PI")
{
list = GetToDocNoList(list, "PR", DtlKey);
}

return list;
}

private string GetToDocNoList(string List, string Doc, string DtlKey)
{
string sqlTemp = "select distinct(a.DocNo) from {0} a join {0}dtl b on A.DocKey=B.DocKey where b.fromdocdtlkey=?";
DataTable dtDoc = BCE.AutoCount.Application.DBSetting.GetDataTable(string.Format(sqlTemp, Doc), false, DtlKey);

if (dtDoc == null) return List;

for (int i=0; i
Posted
Updated 5-Apr-15 16:44pm
v4
Comments
William Choo 5-Apr-15 22:47pm    
Newly update to all the script, sorry for i didn't have any knowledge for write script, this is the original script from Autocount software, but after an update it become fail to operate.

You cannot ask such questions every time you face this exception. It's very important to learn how to sort out such situations all by yourself.

You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown.

Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: either make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.

Please see also: want to display next record on button click. but got an error in if condition of next record function "object reference not set to an instance of an object".

Sometimes, you cannot do it under debugger, by one or another reason. One really nasty case is when the problem is only manifested if software is built when debug information is not available. In this case, you have to use the harder way. First, you need to make sure that you never block propagation of exceptions by handling them silently (this is a crime of developers against themselves, yet very usual). The you need to catch absolutely all exceptions on the very top stack frame of each thread. You can do it if you handle the exceptions of the type System.Exception. In the handler, you need to log all the exception information, especially the System.Exception.StackTrace:
http://msdn.microsoft.com/en-us/library/system.exception.aspx,
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx.

The stack trace is just a string showing the full path of exception propagation from the throw statement to the handler. By reading it, you can always find ends. For logging, it's the best (in most cases) to use the class System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx.

Good luck,
—SA
 
Share this answer
 
Comments
Abhinav S 5-Apr-15 22:26pm    
5!
Sergey Alexandrovich Kryukov 5-Apr-15 22:28pm    
Thank you, Abhinav.
—SA
C#
string docType = DetailReport.GetCurrentColumnValue("DocType").ToString();
string dtlKey = DetailReport.GetCurrentColumnValue("DtlKey").ToString();

If either of DetailReport.GetCurrentColumnValue("DocType") or DetailReport.GetCurrentColumnValue("DtlKey") is null and you try to convert null to string, you will get this error.

Here is an explanation - Why do I get the error "Object reference not set to an instance of an object"?[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900