protected void grid_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e) { string par = e.Parameters; string[] ar = par.Split('_'); if (par == "OK") { #region Create Inv if (Request.QueryString["no"] != null) { try { bool action = false; string res = ""; string no = SafeValue.SafeString(Request.QueryString["no"]); string type = SafeValue.SafeString(Request.QueryString["type"]); if (type == "IMP" || type == "EXP") { string sql_c = string.Format(@"select count(*) from ctm_jobdet1 where JobNo='{0}' and StatusCode!='Completed'", no); int n = SafeValue.SafeInt(ConnectSql.ExecuteScalar(sql_c), 0); n = 0; if (n == 0) { action = true; } else { res = "Action Error!Not Completed Container,Can not Create Invoice"; } } else { action = true; } if (action) { #region Create Inv string docId = ""; if (list.Count > 0) { string billType = SafeValue.SafeString(cbb_BillType.Value); string jobNo = SafeValue.SafeString(Request.QueryString["no"]); string client = SafeValue.SafeString(Request.QueryString["client"]); string contType = SafeValue.SafeString(Request.QueryString["contType"]); string user = HttpContext.Current.User.Identity.Name; string acCode = EzshipHelper.GetAccArCode("", "SGD"); DateTime dtime = txt_DocDt.Date; string invN = C2Setup.GetNextNo("", "AR-IV", dtime); string termId = EzshipHelper.GetTerm(client); string term = EzshipHelper.GetTermCode(termId); string currency = cmb_CurrencyId.Text; decimal exrate = SafeValue.SafeDecimal(spin_ExRate.Value); string sql_att = string.Format(@"select ClientContact from ctm_job where JobNo='{0}'", jobNo); string contact = SafeValue.SafeString(ConnectSql.ExecuteScalar(sql_att)); string[] currentPeriod = EzshipHelper.GetAccPeriod(dtime); string acYear = currentPeriod[1]; string acPeriod = currentPeriod[0]; string sql = string.Format(@"insert into XAArInvoice (DocType,DocDate,PartyTo,DocNo,AcYear,AcPeriod,Term,DocDueDate,Description, CurrencyId,MastType,ExRate,ExportInd,CancelDate,CancelInd,UserId,EntryDate,Eta,AcCode,AcSource,MastRefNo,Contact) values('IV','{5:yyyy-MM-dd}','{4}','{0}','{6}','{7}','{8}','{5:yyyy-MM-dd}','', '{9}','CTM',{10},'N','19000101','N','{1}',getdate(),'17530101','{2}','DB','{3}','{11}') select @@IDENTITY", invN, user, acCode, jobNo, client, dtime, acYear, acPeriod, term, currency, exrate, contact); docId = ConnectSql_mb.ExecuteScalar(sql); C2Setup.SetNextNo("", "AR-IV", invN, dtime); string code = ""; for (int i = 0; i < list.Count; i++) { int id = list[i].id; string chgCode = list[i].chgCode; string chgcodeDes = list[i].chgCodedes; if (IsCostCreated(id)) { C2.ComMethod.CreateInv(invN, id, docId, i, billType, currency, exrate); } else { if (list.Count - i > 1) { code += chgcodeDes + " / "; } else { code += chgcodeDes; } } } for (int i = 0; i < list1.Count; i++) { int id = list1[i].id; string chgCode = list[i].chgCode; if (IsCostCreated(id)) { C2.ComMethod.CreateWhInv(invN, id, docId); } else { if (list.Count - i > 1) { code += chgCode + " / "; } else { code += chgCode; } } } C2.XAArInvoice.update_invoice_mast(SafeValue.SafeInt(docId, 0)); if (code.Length == 0) { e.Result = invN; } else { e.Result = "Action Error!" + code + " already exist !"; } } else { e.Result = "Action Error!Please keyin select cost "; } #endregion string userId = HttpContext.Current.User.Identity.Name; C2.CtmJobEventLog elog = new C2.CtmJobEventLog(); elog.Platform_isWeb(); elog.Controller = userId; elog.ActionLevel_isINVOICE(SafeValue.SafeInt(docId, 0)); elog.setActionLevel(SafeValue.SafeInt(docId, 0), CtmJobEventLogRemark.Level.Invoice, 3); elog.log(); } else { e.Result = res; } } catch { } } #endregion } if (par == "Update") { #region Update Inv if (Request.QueryString["no"] != null) { try { string no = SafeValue.SafeString(Request.QueryString["no"]); if (list.Count > 0) { string invN = lbl_DocNo.Text; string sql = string.Format(@"select SequenceId from XAArInvoice where DocNo='{0}'", invN); string docId = ConnectSql_mb.ExecuteScalar(sql); string currency = cmb_CurrencyId.Text; decimal exrate = SafeValue.SafeDecimal(spin_ExRate.Value); string code = ""; for (int i = 0; i < list.Count; i++) { int id = list[i].id; string chgCode = list[i].chgCode; string chgcodeDes = list[i].chgCodedes; if (IsCostCreated(id)) { C2.ComMethod.CreateInv(invN, id, docId, i, "", currency, exrate); } else { if (list.Count - i > 1) { code += chgcodeDes + " / "; } else { code += chgcodeDes; } } } if (code.Length == 0) { e.Result = invN; } else { e.Result = "Action Error!" + code + " already exist !"; } } else { e.Result = "Action Error!Please keyin select cost "; } } catch (Exception ex) { throw new Exception(ex.Message + ex.StackTrace); } } #endregion } if (par == "Save") { #region Save All if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { int id = list[i].id; string contNo = list[i].contNo; string contType = list[i].contType; decimal price = list[i].price; decimal qty = list[i].qty; string unit = list[i].unit; string code = list[i].chgCode; string des = list[i].chgCodedes; int lineIndex = list[i].lineIndex; string remark = list[i].remark; string groupBy = list[i].groupBy; decimal locAmt = SafeValue.ChinaRound(qty * SafeValue.SafeDecimal(price, 0), 2); string sql = string.Format(@"update job_cost set ContNo='{0}',ContType='{1}',Price={2},Qty={3},LocAmt={4},Unit='{6}',ChgCode='{7}',ChgCodeDes='{8}',LineIndex={9},Remark='{10}',GroupBy='{11}' where Id={5}", contNo, contType, price, qty, locAmt, id, unit, code, des, lineIndex, remark, groupBy); ConnectSql.ExecuteSql(sql); } e.Result = "Save Success"; } else { e.Result = "Action Error!Please keyin select cost "; } #endregion } if (par == "Delete") { #region if (list.Count > 0) { bool action = false; string no = SafeValue.SafeString(Request.QueryString["no"]); for (int i = 0; i < list.Count; i++) { int id = list[i].id; string sql = string.Format(@"select LineSource from job_cost where Id={0}", id); string status = SafeValue.SafeString(ConnectSql_mb.ExecuteScalar(sql)); if (status != "S") { action = true; sql = string.Format(@"delete from job_cost where Id={0}", id); ConnectSql.ExecuteSql(sql); } else { e.Result = "this can not delete "; } } if (action) { e.Result = "Action Success"; } } else { e.Result = "Please keyin select cost "; } #endregion } if (ar.Length >= 2) { if (ar[0].Equals("ChargeUpdateline")) { Update_Inline(e); } } }