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_printbook_new : 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); 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 where contract_no = '" + CONTRACT_NO + "' "); string Sqlvat = @" select COOP_ID , CONTRACT_NO , DEBT_NO , SLIP_DATE ,slip_no, ENTRY_ID ,max( CALINT_FROM) as CALINT_FROM ,max( CALINT_TO) as CALINT_TO ,sum(nvl(PRINCIPAL_PAYMENT,0)) as PRINCIPAL_PAYMENT ,sum(nvl(PRINCIPAL_BALANCE,0)) as PRINCIPAL_BALANCE ,sum(nvl(INT_PAYMENT,0)) as INT_PAYMENT ,sum(nvl(FINE_PAYMENT,0)) as FINE_PAYMENT ,sum(nvl(INTYEAR_ARREAR_AMT,0)) as INTYEAR_ARREAR_AMT,sum(nvl(FINEYEAR_ARREAR_AMT,0)) as FINEYEAR_ARREAR_AMT,sum(nvl(FINE_ARREAR_AMT,0)) as FINE_ARREAR_AMT ,sum(nvl(FINE_PERIOD_AMT,0)) as FINE_PERIOD_AMT,sum(nvl(INTEREST_ARREAR_AMT,0)) as INTEREST_ARREAR_AMT ,sum(nvl(INTEREST_PERIOD_AMT,0)) as INTEREST_PERIOD_AMT,sum(nvl(PRINCIPAL_ARREAR_AMT,0)) as PRINCIPAL_ARREAR_AMT ,sum(nvl(BF_INTPERIOD,0)) as BF_INTPERIOD ,sum(nvl(BF_FINEPERIOD,0)) as BF_FINEPERIOD,sum(nvl(BFINTYEAR_ARREAR,0)) as BFINTYEAR_ARREAR,sum(nvl(BFFINEYEAR_ARREAR,0)) as BFFINEYEAR_ARREAR ,sum(nvl(BFINT_ARREAR,0)) as BFINT_ARREAR,sum(nvl(BFFINE_ARREAR,0)) as BFFINE_ARREAR ,sum(nvl(BFPRINCIPAL_ARREAR,0)) as BFPRINCIPAL_ARREAR, DEBTINCDEC_TYPE from stcontractlimitdet where coop_id = {0} and CONTRACT_NO = {1} and slip_status <> -9 and slip_date between {2} and {3} group by COOP_ID , CONTRACT_NO , DEBT_NO , SLIP_DATE ,slip_no, ENTRY_ID , DEBTINCDEC_TYPE order by slip_date,slip_no asc "; Sqlvat = WebUtil.SQLFormat(Sqlvat, state.SsCoopId, CONTRACT_NO, state.SsStartAccountYear_date, state.SsStartAccountYear_date.AddYears(1).AddDays(-1)); Sdt ds = WebUtil.QuerySdt(Sqlvat); int i = 1; decimal principal_balance = 0; while (ds.Next()) { if (ds.GetString("DEBTINCDEC_TYPE") == "001") { principal_balance += ds.GetDecimal("PRINCIPAL_PAYMENT"); } else if (ds.GetString("DEBTINCDEC_TYPE") == "B/F") { principal_balance = ds.GetDecimal("BFPRINCIPAL_ARREAR"); } else { //ชำระ principal_balance = principal_balance - ds.GetDecimal("PRINCIPAL_PAYMENT"); } string sql = @" insert into STCONTRACTCARD( COOP_ID , CONTRACT_NO ,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},{1},{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("SLIP_DATE"), ds.GetString("ENTRY_ID"), ds.GetDate(" CALINT_FROM"), ds.GetDate("CALINT_TO"), ds.GetDecimal("PRINCIPAL_PAYMENT"), principal_balance, ds.GetDecimal("INT_PAYMENT"), ds.GetDecimal("FINE_PAYMENT"), ds.GetDecimal("INTYEAR_ARREAR_AMT"), ds.GetDecimal("FINEYEAR_ARREAR_AMT"), ds.GetDecimal("FINE_ARREAR_AMT"), ds.GetDecimal("FINE_PERIOD_AMT"), ds.GetDecimal("INTEREST_ARREAR_AMT"), ds.GetDecimal("INTEREST_PERIOD_AMT"), ds.GetDecimal("PRINCIPAL_ARREAR_AMT"), ds.GetDecimal("BF_INTPERIOD"), ds.GetDecimal("BF_FINEPERIOD"), ds.GetDecimal("BFINTYEAR_ARREAR"), ds.GetDecimal("BFFINEYEAR_ARREAR") , ds.GetDecimal("BFINT_ARREAR"), ds.GetDecimal("BFFINE_ARREAR"), ds.GetDecimal("BFPRINCIPAL_ARREAR"), ds.GetString("DEBTINCDEC_TYPE")); WebUtil.QuerySdt(sql); i++; } Sdt d = WebUtil.QuerySdt("select lastrec_no_card,lastline_no_card from stcontract where contract_no = '" + HdAccountNo.Value + "'"); if (d.Next()) { if (d.GetDecimal("lastrec_no_card") > i) { WebUtil.QuerySdt("update stcontract set lastrec_no_card = " + i + " where contract_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_card")); Int16 page =1; Int16 line = Convert.ToInt16(DwPrintPrompt2.GetItemDecimal(1, "lastline_no_card")); 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_debt(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, "debt_bookcard", as_xml_return); Sdt d = WebUtil.QuerySdt("select lastrec_no_card,lastline_no_card from stcontract where contract_no = '" + as_member_no + "'"); if (d.Next()) { DwPrintPrompt2.SetItemDecimal(1, "lastpage_no_card", 1); DwPrintPrompt2.SetItemDecimal(1, "lastrec_no_card", d.GetDecimal("lastrec_no_card")); DwPrintPrompt2.SetItemDecimal(1, "lastline_no_card", d.GetDecimal("lastline_no_card")); } if (rePage > 0) { DwPrintPrompt2.SetItemDecimal(1, "lastrec_no_card", reReq); DwPrintPrompt2.SetItemDecimal(1, "lastline_no_card", 1); WebUtil.QuerySdt("update stcontract set lastline_no_card = 1 where contract_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 } }