protected void btn_paymentItemSetting_form_confirm_Click(object sender, EventArgs e)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            string id      = Request.QueryString["id"] as string;
            long   id_long = long.Parse(id);

            List <AccountItemViewModel.XXX_EP_ACC_COMB_V> accCombVList = this.accountItemSvc.getAccCombVList();

            if (!accCombVList.Exists(x => x.ACC_COMB_2 == ddl_paymentItemSetting_form_accountNo.SelectedValue))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("selected  ACC_COMB_2 value is not exist");
                return;
            }

            string accountName = accCombVList.First(x => x.ACC_COMB_2 == ddl_paymentItemSetting_form_accountNo.SelectedValue).ACC_COMB_2_NAME;


            dic.Add("applyTypeKey", this.ddl_paymentItemSetting_form_applyTypeKey.SelectedValue);
            dic.Add("itemName", this.txt_paymentItemSetting_form_itemName.Text);
            dic.Add("accountNo", this.ddl_paymentItemSetting_form_accountNo.SelectedValue);
            dic.Add("accountName", accountName);
            dic.Add("taxRate", Math.Round(float.Parse(this.txt_paymentItemSetting_form_taxRate.Text), 2));
            dic.Add("foreignIncomeTaxRate", Math.Round(float.Parse(this.txt_paymentItemSetting_form_foreignIncomeTaxRate.Text), 2));
            dic.Add("localIncomeTaxRate", Math.Round(float.Parse(this.txt_paymentItemSetting_form_localIncomeTaxRate.Text), 2));
            dic.Add("secondNHITaxRate", Math.Round(float.Parse(this.txt_paymentItemSetting_form_secondNHITaxRate.Text), 2));
            dic.Add("memo", this.txt_paymentItemSetting_form_memo.Text.Trim());
            dic.Add("code", this.txt_paymentItemSetting_form_code.Text.Trim());
            dic.Add("needCountersign", this.chk_paymentItemSetting_form_needCountersign.Checked);

            AccountItemViewModel.AccountItemTaxRateSettingResult update_ret = this.accountItemSvc.updateAccountItemTaxRateSetting(id_long, dic);

            if (update_ret.success)
            {
                Response.Redirect("PaymentItemSetting.aspx");
            }
        }
        protected void edit_init()
        {
            this.mv_paymentItemSetting.SetActiveView(this.vw_paymentItemSetting_edit);

            string id = Request.QueryString["id"] as string;

            if (string.IsNullOrEmpty(id))
            {
                Response.Redirect("PaymentItemSetting.aspx");
                return;
            }

            long id_long = 0;

            if (!long.TryParse(id, out id_long))
            {
                Response.Redirect("PaymentItemSetting.aspx");
                return;
            }

            AccountItemViewModel.AccountItemTaxRateSettingResult acc_ret = this.accountItemSvc.getAccountItemTaxRateSetting(id_long);

            if (!acc_ret.success)
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg(acc_ret.resultException.ToString());
                return;
            }


            AccountItemViewModel.CashApplyTypeListResult cashApplyListRet = this.accountItemSvc.getCashApplyTypeList();

            if (!cashApplyListRet.list.Exists(x => x.key == "tempPayment_writeOff"))
            {
                cashApplyListRet.list.Add(new AccountItemViewModel.CashApplyType()
                {
                    key = "tempPayment_writeOff", name = "暫支款沖銷"
                });
            }

            List <ListItem> cashApplyOptions = new List <ListItem>();

            cashApplyOptions.Add(new ListItem()
            {
                Text = "- 請選擇 -", Value = ""
            });
            foreach (var c in cashApplyListRet.list)
            {
                cashApplyOptions.Add(new ListItem()
                {
                    Text = c.name, Value = c.key
                });
            }

            this.ddl_paymentItemSetting_form_applyTypeKey.DataSource = cashApplyOptions;
            this.ddl_paymentItemSetting_form_applyTypeKey.DataBind();

            this.ddl_paymentItemSetting_form_applyTypeKey.SelectedValue = acc_ret.acc.applyTypeKey;

            this.txt_paymentItemSetting_form_itemName.Text = acc_ret.acc.accountName;



            List <ListItem> accCombVListOptions = new List <ListItem>();

            accCombVListOptions.Add(new ListItem()
            {
                Text = "- 請輸入會科代碼或名稱 -", Value = ""
            });

            List <AccountItemViewModel.XXX_EP_ACC_COMB_V> accCombVList = this.accountItemSvc.getAccCombVList();

            foreach (var c in accCombVList)
            {
                accCombVListOptions.Add(new ListItem()
                {
                    Text = c.ACC_COMB_2_NAME + " - (" + c.ACC_COMB_2 + ")", Value = c.ACC_COMB_2
                });
            }


            this.ddl_paymentItemSetting_form_accountNo.DataSource = accCombVListOptions;
            this.ddl_paymentItemSetting_form_accountNo.DataBind();
            this.ddl_paymentItemSetting_form_accountNo.SelectedValue   = acc_ret.acc.accountNo;
            this.txt_paymentItemSetting_form_itemName.Text             = acc_ret.acc.itemName;
            this.txt_paymentItemSetting_form_taxRate.Text              = acc_ret.acc.taxRate.ToString();
            this.txt_paymentItemSetting_form_foreignIncomeTaxRate.Text = acc_ret.acc.foreignIncomeTaxRate.ToString();
            this.txt_paymentItemSetting_form_localIncomeTaxRate.Text   = acc_ret.acc.localIncomeTaxRate.ToString();
            this.txt_paymentItemSetting_form_secondNHITaxRate.Text     = acc_ret.acc.secondNHITaxRate.ToString();
            this.txt_paymentItemSetting_form_code.Text = acc_ret.acc.code;
            this.chk_paymentItemSetting_form_needCountersign.Checked = acc_ret.acc.needCountersign;
            this.txt_paymentItemSetting_form_memo.Text = acc_ret.acc.memo;

            return;
        }
        protected void btn_paymentItemSetting_add_Click(object sender, EventArgs e)
        {
            this.lt_paymentItemSetting_msg.Text = "";

            /* validate form */

            if (string.IsNullOrEmpty(this.ddl_paymentItemSetting_accountItem.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("請選擇會計科目");
                return;
            }

            if (string.IsNullOrEmpty(this.ddl_paymentItemSetting_type.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("請選擇費用類型");
                return;
            }

            if (string.IsNullOrEmpty(this.txt_paymentItemSetting_foreignRate.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("請輸入外國人所得稅率");
                return;
            }

            if (string.IsNullOrEmpty(this.txt_paymentItemSetting_localRate.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("請輸入本國人所得稅率");
                return;
            }


            /*
             * if (string.IsNullOrEmpty(this.txt_paymentItemSetting_memo.Text)) {
             *  this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("請輸入說明文字");
             *  return;
             * }*/


            if (string.IsNullOrEmpty(this.txt_paymentItemSetting_name.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("品項不能為空值");
                return;
            }


            if (string.IsNullOrEmpty(this.txt_paymentItemSetting_secondNHITaxRate.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("二代健保稅率不能為空值");
                return;
            }

            if (string.IsNullOrEmpty(this.txt_paymentItemSetting_taxRate.Text))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("稅率不能為空值");
                return;
            }

            /* add account item */
            List <AccountItemViewModel.XXX_EP_ACC_COMB_V> accCombVList = this.accountItemSvc.getAccCombVList();

            if (!accCombVList.Exists(x => x.ACC_COMB_2 == this.ddl_paymentItemSetting_accountItem.SelectedValue))
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("selected  ACC_COMB_2 value is not exist");
                return;
            }
            AccountItemTaxRateSetting acc = new AccountItemTaxRateSetting();

            acc.accountNo            = this.ddl_paymentItemSetting_accountItem.SelectedValue;
            acc.accountName          = accCombVList.First(x => x.ACC_COMB_2 == acc.accountNo).ACC_COMB_2_NAME;
            acc.applyTypeKey         = this.ddl_paymentItemSetting_type.SelectedValue;
            acc.dateCreated          = DateTime.Now;
            acc.deleted              = false;
            acc.foreignIncomeTaxRate = Math.Round(float.Parse(this.txt_paymentItemSetting_foreignRate.Text), 2);
            acc.itemName             = this.txt_paymentItemSetting_name.Text.Trim();
            acc.localIncomeTaxRate   = Math.Round(float.Parse(this.txt_paymentItemSetting_localRate.Text), 2);
            acc.memo             = this.txt_paymentItemSetting_memo.Text;
            acc.secondNHITaxRate = Math.Round(float.Parse(this.txt_paymentItemSetting_secondNHITaxRate.Text), 2);
            acc.taxRate          = Math.Round(float.Parse(this.txt_paymentItemSetting_taxRate.Text), 2);
            acc.needCountersign  = this.chk_paymentItemSetting_needCountersign.Checked;
            acc.code             = this.txt_paymentItemSetting_code.Text;

            AccountItemViewModel.AccountItemTaxRateSettingResult accRet = this.accountItemSvc.addAccountItemTaxRateSetting(acc);

            if (accRet.success)
            {
                this.lt_paymentItemSetting_msg.Text = UtilitySvc.alertMsg("新增成功");
                this.clearForm();
                this.reloadAccountList();
            }
            else
            {
                this.lt_paymentItemSetting_msg.Text = accRet.resultException;
            }
        }