using System; using CoreSavingLibrary; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DataLibrary; namespace Saving.CriteriaIReport.genwithdraw_able { public partial class genwithdraw_able : PageWebReport, WebReport { protected String app; protected String gid; protected String rid; public void InitJsPostBack() { dsMain.InitDsMain(this); } public void WebSheetLoadBegin() { //--- Page Arguments try { app = Request["app"].ToString(); } catch { } if (app == null || app == "") { app = state.SsApplication; } try { gid = Request["gid"].ToString(); } catch { } try { rid = Request["rid"].ToString(); } catch { } //Report Name. try { Sta ta = new Sta(state.SsConnectionString); String sql = ""; sql = @"SELECT REPORT_NAME FROM WEBREPORTDETAIL WHERE ( GROUP_ID = '" + gid + @"' ) AND ( REPORT_ID = '" + rid + @"' )"; Sdt dt = ta.Query(sql); ReportName.Text = dt.Rows[0]["REPORT_NAME"].ToString(); ta.Close(); } catch { ReportName.Text = "[" + rid + "]"; } if (!IsPostBack) { dsMain.DdCoopId(); dsMain.DATA[0].adtm_calto = state.SsWorkDate; } } public void CheckJsPostBack(string eventArg) { } public void RunReport() { decimal payment = 0; string sql = @"select lncontstatement.loancontract_no as loancontract_no,sum(principal_payment) as principal_payment from lncontstatement inner join lncontmaster on lncontstatement.loancontract_no = lncontmaster.loancontract_no where (loanitemtype_code ='LRC' and item_status =1) and lncontmaster.principal_balance >0 and lncontstatement.coop_id= {0} group by loancontract_no"; sql = WebUtil.SQLFormat(sql,state.SsCoopId); Sdt dt = WebUtil.QuerySdt(sql); while (dt.Next()) { string sql2 = @"select loancontract_no,sum(period_payment) as period_payment from lncontperiodpaydet where loancontract_no ={0} and coop_id={1}"; sql2 = WebUtil.SQLFormat(sql2, dt.GetString("loancontract_no"),state.SsCoopId); Sdt dt2 = WebUtil.QuerySdt(sql2); if (dt2.Next()) { payment = dt2.GetDecimal("period_payment") - dt.GetDecimal("principal_payment"); if (payment >=0)//ถ้า จ่ายไม่หมด { try { string update = @" update lncontmaster set withdrawable_amt = {0} where loancontract_no ={1} and coop_id={2}"; update = WebUtil.SQLFormat(update, payment, dt.GetString("loancontract_no"), state.SsCoopId); WebUtil.QuerySdt(update); }catch{} } } } } public void WebSheetLoadEnd() { } } }