using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CoreSavingLibrary; using CoreSavingLibrary.WcfNDeposit; using DataLibrary; using System.Drawing; namespace Saving.Applications.shrlon.dlg { public partial class w_dlg_sl_printcoll : PageWebDialog, WebDialog { private n_depositClient ndept; //new deposit private String pbl = "sl_print_book.pbl"; protected String postPrintBook; protected String Exit_ireport; protected String postPrintBook_new; string loancontract_no = ""; Sdt d; Sta ta; public void InitJsPostBack() { postPrintBook = WebUtil.JsPostBack(this, "postPrintBook"); Exit_ireport = WebUtil.JsPostBack(this, "Exit_ireport"); postPrintBook_new = WebUtil.JsPostBack(this, "postPrintBook_new"); } public void WebDialogLoadBegin() { ndept = wcf.NDeposit; this.ConnectSQLCA(); DwPrintPrompt.SetTransaction(sqlca); DwDetail.SetTransaction(sqlca); ta = new Sta(sqlca.ConnectionString); sqlca = new DwTrans(); sqlca.Connect(); if (!IsPostBack) { loancontract_no = Request["loancon"]; //JsPostAccountNo(loancontract_no); string[] arg = new string[2] { state.SsCoopControl, loancontract_no }; DwUtil.RetrieveDataWindow(DwDetail, pbl, null, arg); if (DwDetail.RowCount > 0) { decimal rai = 0,ngan=0,wa=0; for (int j = 1; j <= DwDetail.RowCount; j++) { if (j == 1) { DwDetail.SetItemDecimal(1, "dol_prince", DwDetail.GetItemDecimal(1, "mortgage_price")); DwDetail.SetItemString(1, "bd_tambol", DwDetail.GetItemString(1, "compute_2")); rai += DwDetail.GetItemDecimal(1, "size_rai"); ngan += DwDetail.GetItemDecimal(1, "size_ngan"); wa += DwDetail.GetItemDecimal(1, "size_wa"); } else { String type = DwDetail.GetItemString(j, "thai"); if (type == "ไถ่ถอน") //จำนอง { rai -= DwDetail.GetItemDecimal(j, "size_rai"); ngan -= DwDetail.GetItemDecimal(j, "size_ngan"); wa -= DwDetail.GetItemDecimal(j, "size_wa"); } else { rai += DwDetail.GetItemDecimal(j, "size_rai"); ngan += DwDetail.GetItemDecimal(j, "size_ngan"); wa += DwDetail.GetItemDecimal(j, "size_wa"); } //if (DwDetail.GetItemDecimal(j, "r_price") == 0) //จำนอง //{ // rai += DwDetail.GetItemDecimal(j, "size_rai"); // ngan += DwDetail.GetItemDecimal(j, "size_ngan"); // wa += DwDetail.GetItemDecimal(j, "size_wa"); //} //else //{ // rai -= DwDetail.GetItemDecimal(j, "size_rai"); // ngan -= DwDetail.GetItemDecimal(j, "size_ngan"); // wa -= DwDetail.GetItemDecimal(j, "size_wa"); //} if (wa < 0) { wa = 100 + wa; ngan = ngan - 1; } if (ngan < 0) { ngan = 4 + ngan; rai = rai - 1; } if ((wa / 100) > 1) { wa = wa - 100; ngan = ngan + 1; } if ((ngan / 4) > 1) { ngan = ngan - 4; rai = rai + 1; } DwDetail.SetItemString(j, "bd_tambol", rai+"-"+ngan + "-"+wa); DwDetail.SetItemDecimal(j, "dol_prince", DwDetail.GetItemDecimal(j - 1, "dol_prince") + (DwDetail.GetItemDecimal(j, "mortgage_price") - DwDetail.GetItemDecimal(j, "r_price"))); } //Color myRgbColor = new Color(); //myRgbColor = Color.FromArgb(255, 255, 255); } } DwPrintPrompt.InsertRow(0); DwPrintPrompt.SetItemDecimal(1, "lastrec_no", DwDetail.RowCount); DwPrintPrompt.SetItemDecimal(1, "last_stm_no", DwDetail.RowCount); DwPrintPrompt.SetItemDecimal(1, "lastline_no", DwDetail.RowCount); } else { this.RestoreContextDw(DwPrintPrompt); this.RestoreContextDw(DwDetail); } // DwPrintPrompt.InsertRow(0); } public void CheckJsPostBack(string eventArg) { if (eventArg == "postPrintBook") { int r = DwPrintPrompt.RowCount; //delete_ln_prinbook(Request["loancon"], state.SsCoopId); try { Sdt d = WebUtil.QuerySdt("select member_no from LNCOLLPRINTBOOK where rownum=1 "); if (!d.Next()) { //WebUtil.QuerySdt("CREATE TABLE LNCOLLPRINTBOOK (COOP_ID , COLL_DATE, LAND_SIZE , LAND_PRICE , REDEEM_SIZE , REDEEM_PRICE , LAND_BALANCE_SIZE , LAND_BLANCE_PRICE , ENTRY_ID , MEMBER_NO , COLLMAST_NO , SEQ_NO , COLLMAST_DESC) "); //WebUtil.QuerySdt("ALTER TABLE LNCOLLPRINTBOOK ADD ( CONSTRAINT book_pk555 PRIMARY KEY ( COOP_ID, SEQ_NO, MEMBER_NO ))"); } } catch (Exception e) { WebUtil.QuerySdt("CREATE TABLE LNCOLLPRINTBOOK (COOP_ID VARCHAR2(10), COLL_DATE DATE, LAND_SIZE VARCHAR2(10), LAND_PRICE NUMBER(10,2), REDEEM_SIZE VARCHAR2(10), REDEEM_PRICE NUMBER(10,2), LAND_BALANCE_SIZE VARCHAR2(10), LAND_BLANCE_PRICE NUMBER(10,2), ENTRY_ID VARCHAR2(10), MEMBER_NO VARCHAR2(10), COLLMAST_NO VARCHAR2(10), SEQ_NO NUMBER(5,0), COLLMAST_DESC VARCHAR2(200)) "); WebUtil.QuerySdt("ALTER TABLE LNCOLLPRINTBOOK ADD ( CONSTRAINT book_pk555 PRIMARY KEY ( COOP_ID, SEQ_NO, MEMBER_NO ))"); } Int16 lastrec_no = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "lastrec_no")); //ตั้งแต่รายการที่ Int16 last_stm_no = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "last_stm_no"));//ถึงรายการที่ Int16 line = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "lastline_no"));//เริ่มบรรทัดที่ delete_ln_prinbook(Request["loancon"], state.SsCoopId); String coopid="",land_size="",redeem_size="",land_balance_size="",entry_id="",member_no="",collmast_no="",collmast_desc=""; Decimal LAND_PRICE=0,REDEEM_PRICE=0,LAND_BLANCE_PRICE=0,SEQ_NO=0; DateTime COLL_DATE= state.SsWorkDate; for (int i = 1; i <= last_stm_no; i++) { //ถึงรายการที่ try { loancontract_no = Request["loancon"]; if (i >= lastrec_no) { if (DwDetail.GetItemString(i, "thai") == "จำนอง") { try { land_size = DwDetail.GetItemString(i, "compute_2"); redeem_size = ""; } catch { } } else { try { redeem_size = DwDetail.GetItemString(i, "compute_2"); land_size = ""; } catch { } } try { COLL_DATE = DwDetail.GetItemDateTime(i, "s_date"); } catch { } try{ land_balance_size = DwDetail.GetItemString(i, "bd_tambol"); }catch{ } try{ collmast_no = DwDetail.GetItemString(i, "collmast_no"); }catch{ } try{ collmast_desc = DwDetail.GetItemString(i, "collmast_desc"); }catch{ } try{ LAND_PRICE = DwDetail.GetItemDecimal(i, "mortgage_price"); }catch{ } try{ REDEEM_PRICE = DwDetail.GetItemDecimal(i, "r_price"); }catch{ } try{ LAND_BLANCE_PRICE = DwDetail.GetItemDecimal(i, "dol_prince"); }catch{ } string Insert_prinBook = @"INSERT INTO LNCOLLPRINTBOOK (COOP_ID , COLL_DATE , LAND_SIZE , LAND_PRICE , REDEEM_SIZE , REDEEM_PRICE , LAND_BALANCE_SIZE , LAND_BLANCE_PRICE , ENTRY_ID , MEMBER_NO , COLLMAST_NO , SEQ_NO, COLLMAST_DESC) values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}) "; Insert_prinBook = WebUtil.SQLFormat(Insert_prinBook, state.SsCoopControl, COLL_DATE, land_size, LAND_PRICE, redeem_size, REDEEM_PRICE, land_balance_size, LAND_BLANCE_PRICE, state.SsUsername, loancontract_no,collmast_no,i,collmast_desc); WebUtil.QuerySdt(Insert_prinBook); } else { string Insert_prinBook2 = @"INSERT INTO LNCOLLPRINTBOOK (COOP_ID , COLL_DATE , LAND_SIZE , LAND_PRICE , REDEEM_SIZE , REDEEM_PRICE , LAND_BALANCE_SIZE , LAND_BLANCE_PRICE , ENTRY_ID , MEMBER_NO , COLLMAST_NO , SEQ_NO, COLLMAST_DESC) values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}) "; Insert_prinBook2 = WebUtil.SQLFormat(Insert_prinBook2, state.SsCoopControl, "", "", 0, "", 0, "", 0, "", loancontract_no, "", i, ""); WebUtil.QuerySdt(Insert_prinBook2); } } catch { } } prinbook_ireport(loancontract_no); } else if (eventArg == "Exit_ireport") { // Exit_ireport2(loancontract_no, state.SsCoopId); } else if (eventArg == "postPrintBook_new") { Insertreportcontcoll(); prinbook_ireport(loancontract_no); } } public void Insertreportcontcoll() { try { Sdt d2 = WebUtil.QuerySdt("select member_no from REPORT_COLLMASTER where rownum=1 "); if (d2.Next()) { } } catch (Exception e) { WebUtil.QuerySdt("CREATE TABLE REPORT_COLLMASTER (COOP_ID VARCHAR2(6), COLLMASTER_NO VARCHAR2(10), COLLMASTTYPE_CODE VARCHAR2(2), COLLMAST_DESC VARCHAR2(255), COLLMAST_AREA VARCHAR2(255), SLIP_DATE DATE, LANDESTIMATE_AMT NUMBER(10,2), ENTRY_ID VARCHAR2(10), DOL_PRINCE NUMBER(10,2), BALANCE_AREA VARCHAR2(50), SLIP_DATE2 VARCHAR2(50), MEMBER_NO CHAR(8), SEQ_NO NUMBER(10,0)) "); WebUtil.QuerySdt("ALTER TABLE REPORT_COLLMASTER ADD ( CONSTRAINT REPORT_COLLMASTER PRIMARY KEY ( COOP_ID, SEQ_NO, collmaster_no ))"); } // delete_coll_prinbook(Request["collmast_no"], state.SsCoopId); delete_coll_prinbook(Request["loancon"], state.SsCoopId); Int16 lastrec_no = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "lastrec_no")); //ตั้งแต่รายการที่ Int16 last_stm_no = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "last_stm_no"));//ถึงรายการที่ Int16 line = Convert.ToInt16(DwPrintPrompt.GetItemDecimal(1, "lastline_no"));//เริ่มบรรทัดที่ loancontract_no = Request["loancon"]; for (int i = 1; i < line; i++) { //ถึงรายการที่ try { string Insert_prinBook = @"INSERT INTO report_collmaster (coop_id,collmaster_no,seq_no,member_no)VALUES ('" + state.SsCoopId + "','" + Request["collmast_no"].ToString() + "','" + (i) + "','" + loancontract_no + "')"; WebUtil.QuerySdt(Insert_prinBook); } catch { } } string sql_seqno = @"select max(seq_no) as seq_no from report_collmaster where collmaster_no ={0} and coop_id={1}"; sql_seqno = WebUtil.SQLFormat(sql_seqno, Request["collmast_no"], state.SsCoopId); Sdt d = WebUtil.QuerySdt(sql_seqno); Int32 seq_no = 0; if(d.Next()){ seq_no = d.GetInt32("seq_no"); } for (int i = lastrec_no; i <= last_stm_no; i++) { //ถึงรายการที่ try { string collmaster_no = Request["collmast_no"]; string collmasttype_code = ""; string collmast_desc = ""; string collmast_area = ""; DateTime slip_date = DateTime.Today; string slip_date2 = ""; decimal landestimate_amt =0; string entry_id = state.SsUsername; decimal dol_prince = 0; string balance_area = ""; try { slip_date2 = DwDetail.GetItemString(i, "compute_3"); } catch { } try { if (DwDetail.GetItemString(i, "thai") == "จำนอง") { collmasttype_code = "0"; } else { collmasttype_code = "1"; //ไถ่ถอน } } catch { } try { collmast_desc = DwDetail.GetItemString(i, "collmast_desc"); } catch { } try { collmast_area = DwDetail.GetItemString(i, "compute_2"); } catch { } try { if (collmasttype_code == "1")// ไถ่ถอน { landestimate_amt = DwDetail.GetItemDecimal(i, "r_price"); } else { // จำนอง landestimate_amt = DwDetail.GetItemDecimal(i, "mortgage_price"); } } catch { } try { dol_prince = DwDetail.GetItemDecimal(i, "dol_prince"); } catch { } try { balance_area = DwDetail.GetItemString(i, "bd_tambol"); } catch { } string sql_insertcoll_master = @"insert into report_collmaster(coop_id,collmaster_no,seq_no,collmasttype_code,collmast_desc ,collmast_area,slip_date,landestimate_amt,entry_id,dol_prince,balance_area,slip_date2,member_no)values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12})"; sql_insertcoll_master = WebUtil.SQLFormat(sql_insertcoll_master, state.SsCoopId, collmaster_no, ++seq_no, collmasttype_code, collmast_desc, collmast_area, slip_date, landestimate_amt, entry_id, dol_prince, balance_area, slip_date2, loancontract_no); WebUtil.QuerySdt(sql_insertcoll_master); } catch { } } // string sql_insertcoll_master = @"insert into report_collmaster(coop_id,collmaster_no,seq_no,collmasttype_code,collmast_desc // ,collmast_area,slip_date,landestimate_amt,entry_id)values({0},{1},{2},{3},{4},{5},{6},{7},{8})"; // sql_insertcoll_master = WebUtil.SQLFormat(sql_insertcoll_master, loancontract_no,); // WebUtil.QuerySdt(sql_insertcoll_master); } public void delete_coll_prinbook(string collmaster_no, string coop_id) { try { //string sql_collmaster = "delete from report_collmaster where collmaster_no ={0} and coop_id={1}"; //sql_collmaster = WebUtil.SQLFormat(sql_collmaster, collmaster_no, coop_id); //WebUtil.QuerySdt(sql_collmaster); string sql_collmaster = "delete from report_collmaster where member_no ={0} and coop_id={1}"; sql_collmaster = WebUtil.SQLFormat(sql_collmaster, collmaster_no, coop_id); WebUtil.QuerySdt(sql_collmaster); } catch { } } public void delete_ln_prinbook(string loancontract_no, string coop_id) { string Deleteln_prinbook = @"delete from LNCOLLPRINTBOOK where member_no={0} and coop_id={1}"; //update แถวที่ตีสมุดใน lncontmaster Deleteln_prinbook = WebUtil.SQLFormat(Deleteln_prinbook, loancontract_no, coop_id); Sdt d = WebUtil.QuerySdt(Deleteln_prinbook); } public void prinbook_ireport(string loancontract_no) { //string payinslip_no = ""; //try //{ // payinslip_no = Request["payinslip_no"].ToString(); //} //catch //{ //} this.SetOnLoadedScript(" parent.PrintSlipoutCOLL(\"" + loancontract_no + "\"); parent.RemoveIFrame();"); } public void Exit_ireport2(string loancontract_no, string coop_id) { this.SetOnLoadedScript(" parent.ExitIFrame(\"" + loancontract_no + "\",\"" + Request["payinslip_no"] + "\"); parent.RemoveIFrame();"); } public void WebDialogLoadEnd() { DwDetail.SaveDataCache(); DwPrintPrompt.SaveDataCache(); } public void JsPostAccountNo(string loancontract_no) { String sql1 = @"select loanpassbook_no,loanpassbook_no from lncontmaster where loancontract_no = '" + loancontract_no + "'"; Sdt dt1 = WebUtil.QuerySdt(sql1); if (dt1.Next()) { DwUtil.RetrieveDataWindow(DwDetail, pbl, null, state.SsCoopControl, loancontract_no); } } } }