using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; //using Saving.WcfCommon; //using Saving.WcfDeposit; using CoreSavingLibrary.WcfNDeposit; // new deposit using CoreSavingLibrary.WcfNCommon; //new common using System.Web.Services.Protocols; using DataLibrary; using CoreSavingLibrary; namespace Saving.Applications.trading.dlg { public partial class w_dlg_dp_printcard_dept : PageWebDialog, WebDialog { // private DepositClient dep; private n_depositClient ndept; //new deposit private n_commonClient ncommon; //new common private String deptAccountNo; protected String postPrintBook; protected String jsPostPrintHeadCard; protected String postPrintBook2; protected String jsPostPrintNewBookSS; #region WebDialog Members public void InitJsPostBack() { postPrintBook = WebUtil.JsPostBack(this, "postPrintBook"); jsPostPrintHeadCard = WebUtil.JsPostBack(this, "jsPostPrintHeadCard"); postPrintBook2 = WebUtil.JsPostBack(this, "postPrintBook2"); jsPostPrintNewBookSS = WebUtil.JsPostBack(this, "jsPostPrintNewBookSS"); } public void WebDialogLoadBegin() { ndept = wcf.NDeposit; this.ConnectSQLCA(); if (!IsPostBack) { HdIsPostBack.Value = "false"; try { HdAccountNo.Value = Request["mem_no"]; deptAccountNo = HdAccountNo.Value; //DwStm.Retrieve(deptAccountNo, state.SsCoopControl); //String xmlInitDwNewBook = dep.InitPrintBook(state.SsWsPass, deptAccountNo, state.SsCoopId); GenStatement(Request["mem_no"]); // DwPrintPrompt2.InsertRow(0); DwUtil.RetrieveDataWindow(DwPrintPrompt2, "sl_print_book.pbl", null, state.SsCoopControl, deptAccountNo,state.SsStoreId); DwUtil.RetrieveDataWindow(DwDetail, "sl_contack.pbl", null, state.SsCoopControl, deptAccountNo); } catch (SoapException ex) { LtServerMessage.Text = WebUtil.ErrorMessage(WebUtil.SoapMessage(ex)); DwPrintPrompt2.InsertRow(0); //DwStm.InsertRow(0); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); DwPrintPrompt2.InsertRow(0); //DwStm.InsertRow(0); } } else { HdIsPostBack.Value = "true"; this.RestoreContextDw(DwPrintPrompt2); //this.RestoreContextDw(DwStm); } this.deptAccountNo = HdAccountNo.Value; } private void GenStatement(string CONTRACT_NO) { try { WebUtil.QuerySdt(" delete from STCONTRACTCARD_DEBT where debt_no = '" + CONTRACT_NO + "' "); Sdt ds = WebUtil.QuerySdt(@" select dt.debtdet_date ,dt.debt_no , dt.refdoc_no,dt.debtincdectype_code, (case dt.debtincdectype_code when '001' then dt.debtdet_amt else 0 end) debt_inc,' ' int_inc ,(case when dt.debtincdectype_code in ( '002', '004') then dt.debtdet_amt else 0 end) debt_desc,' ' int_dec ,dt.debtbalance_amt,' ' int_balance,dc.entry_id from stdebtdet dt left join stdebtdec dc on dc.debtdecdoc_no = dt.refdoc_no and dc.store_id = dt.store_id and dc.debttype_code = dt.debttype_code and dc.coop_id = dt.coop_id where dt.coop_id ='" + state.SsCoopId + @"' and dt.store_id ='" + state.SsStoreId + @"' and dt.debt_no ='" + CONTRACT_NO + @"' and dt.debtdet_status = 1 order by dt.debtdet_date,dt.seq_no"); // and dt.debt_no = '" + CONTRACT_NO + "' order by dt.debtdet_date,dt.seq_no "); int i = 1; decimal principal_pay = 0; while (ds.Next()) { if (ds.GetString("debtincdectype_code") == "001") { principal_pay += ds.GetDecimal("debt_inc"); } else if (ds.GetString("debtincdectype_code") == "B/F") { principal_pay = 0; } else { //ชำระ principal_pay = ds.GetDecimal("debt_desc"); } string sql = @" insert into STCONTRACTCARD_DEBT( COOP_ID ,SEQ_NO , DEBT_NO , SLIP_DATE , ENTRY_ID , CALINT_FROM , CALINT_TO ,PRINCIPAL_PAYMENT , PRINCIPAL_BALANCE , INT_PAYMENT , FINE_PAYMENT , INTYEAR_ARREAR_AMT , FINEYEAR_ARREAR_AMT , FINE_ARREAR_AMT , FINE_PERIOD_AMT , INTEREST_ARREAR_AMT , INTEREST_PERIOD_AMT , PRINCIPAL_ARREAR_AMT , BF_INTPERIOD , BF_FINEPERIOD , BFINTYEAR_ARREAR , BFFINEYEAR_ARREAR , BFINT_ARREAR , BFFINE_ARREAR , BFPRINCIPAL_ARREAR,DEBTINCDEC_TYPE) values ({0}, {2},{3},{4}, {5},{6},{7},{8},{9},{10},{11}, {12},{13},{14},{15},{16}, {17},{18},{19},{20},{21},{22}, {23},{24},{25},{26})"; sql = WebUtil.SQLFormat(sql, state.SsCoopId, CONTRACT_NO, i, ds.GetString("DEBT_NO"), ds.GetDate("debtdet_date"), state.SsUsername, ds.GetDate(" debtdet_date"), ds.GetDate("debtdet_date"), principal_pay, ds.GetDecimal("debtbalance_amt"), 0, 0, 0,0, 0, 0, 0, 0, ds.GetDecimal("debtbalance_amt"), 0,0, 0,0 , 0, 0, ds.GetDecimal("debtbalance_amt"), ds.GetString("debtincdectype_code")); WebUtil.QuerySdt(sql); i++; } Sdt d = WebUtil.QuerySdt("select lastrec_no_dept,lastline_no_dept from stdebtmaster where debt_no = '" + HdAccountNo.Value + "'"); if (d.Next()) { if (d.GetDecimal("lastrec_no_dept") > i) { WebUtil.QuerySdt("update stdebtmaster set lastrec_no_dept = " + i + " where debt_no='" + HdAccountNo.Value + "' and coop_id = '" + state.SsCoopControl + "' "); } } ds.Clear(); } catch (Exception e) { LtServerMessage.Text = WebUtil.ErrorMessage(e.ToString()); } } public void CheckJsPostBack(string eventArg) { if (eventArg == "jsPostPrintHeadCard") { //Printing.PrintHead_CardDept(this, HdAccountNo.Value, state.SsCoopControl); //Printing.Print_HesdCardDebt(this, state.SsCoopId, state.SsStoreId, HdAccountNo.Value, "st_headcard_debt"); } else if (eventArg == "postPrintBook2") { try { Int16 seq = Convert.ToInt16(DwPrintPrompt2.GetItemDecimal(1, "lastrec_no_dept")); Int16 page = 1; Int16 line = Convert.ToInt16(DwPrintPrompt2.GetItemDecimal(1, "lastline_no_dept")); String as_member_no = HdAccountNo.Value; // Int32 intlastline_no = 0; //XmlConfigService xml = new XmlConfigService(); int ai_status = 1;// xml.DepositPrintMode; String as_xml_return = ""; String as_return = ""; string printset = state.SsPrinterSet; //ndept.of_print_bookcard_debtinc(state.SsWsPass, as_member_no, seq, page, line, true, ref as_xml_return, ref as_return); String[] re = as_return.Split('@'); int rePage = int.Parse(re[0]); int reReq = int.Parse(re[1]); HdIsZeroPage.Value = rePage == 0 ? "true" : "false"; HdIsNewBook.Value = rePage == 1 ? "true" : "false"; //เพิ่มเพื่อรับค่าจาก pb srv ว่าขึ้นเล่มใหม่ HdIsZeroPage.Value = "false"; Printing.PrintApplet(this, "debtinc_bookcard", as_xml_return); Sdt d = WebUtil.QuerySdt("select lastrec_no_dept,lastline_no_dept from stdebtmaster where debt_no = '" + as_member_no + "'"); if (d.Next()) { DwPrintPrompt2.SetItemDecimal(1, "lastpage_no_dept", 1); DwPrintPrompt2.SetItemDecimal(1, "lastrec_no_dept", d.GetDecimal("lastrec_no_dept")); DwPrintPrompt2.SetItemDecimal(1, "lastline_no_dept", d.GetDecimal("lastrec_no_dept")); } if (rePage > 0) { DwPrintPrompt2.SetItemDecimal(1, "lastrec_no_dept", reReq); DwPrintPrompt2.SetItemDecimal(1, "lastline_no_dept", 1); WebUtil.QuerySdt("update stdebtmaster set lastline_no_dept = 1 where debt_no='" + as_member_no + "' and coop_id = '" + state.SsCoopControl + "' "); Page.ClientScript.RegisterStartupScript(this.GetType(), "rePrintShareCard", "rePrintShareCard('" + as_member_no + "')", true); } // Retrivess(); // this.SetOnLoadedScript("parent.RemoveIFrame();"); } catch (Exception ex) { // DwPrintPrompt.SetItemDecimal(1, "lastpage_no_pb", 1); LtServerMessage.Text = WebUtil.ErrorMessage(ex); } } } private void Retrivess() { try { HdAccountNo.Value = Request["mem_no"]; deptAccountNo = HdAccountNo.Value; //DwStm.Retrieve(deptAccountNo, state.SsCoopControl); //String xmlInitDwNewBook = dep.InitPrintBook(state.SsWsPass, deptAccountNo, state.SsCoopId); DwPrintPrompt2.InsertRow(0); //string smltest = DwPrintPrompt.Describe("Datawindow.Data.Xml"); //DwPrintPrompt.ImportString(xmlInitDwNewBook, Sybase.DataWindow.FileSaveAsType.Xml); DwUtil.RetrieveDataWindow(DwDetail, "sl_contack.pbl", null, state.SsCoopControl, deptAccountNo); DwUtil.RetrieveDataWindow(DwPrintPrompt2, "sl_print_book.pbl", null, state.SsCoopControl, deptAccountNo); } catch (SoapException ex) { LtServerMessage.Text = WebUtil.ErrorMessage(WebUtil.SoapMessage(ex)); DwPrintPrompt2.InsertRow(0); //DwStm.InsertRow(0); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); DwPrintPrompt2.InsertRow(0); //DwStm.InsertRow(0); } } public void WebDialogLoadEnd() { DwPrintPrompt2.SaveDataCache(); } #endregion } }