private void CheckDataValueInsert(DbWithHoldingTax WHTTax)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (string.IsNullOrEmpty(WHTTax.WhtCode))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("WhtCode"));
            }
            if (string.IsNullOrEmpty(WHTTax.WhtName))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("WhtName"));
            }
            if (WHTTax.Rate == 0)
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("Rate>0"));
            }
            if (ScgDbQueryProvider.DbWithHoldingTaxQuery.isDuplicationWHTCode(WHTTax.WhtCode))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("DuplicationWhtCode"));
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
        }
        private void CheckDataValueUpdate(DbWithHoldingTax WHTTax)
        {
            Literal ctlLblWhtCodeInGrid = ctlGridWithholdingTax.Rows[ctlGridWithholdingTax.EditIndex].FindControl("ctlLblWhtCode") as Literal;
            TextBox txtWHTCode          = ctlFormViewWHT.FindControl("ctlTxtWHTCode") as TextBox;

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (string.IsNullOrEmpty(WHTTax.WhtCode))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("WhtCode"));
            }
            if (string.IsNullOrEmpty(WHTTax.WhtName))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("WhtName"));
            }
            if (WHTTax.Rate == 0)
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("Rate>0"));
            }

            if (
                (ctlLblWhtCodeInGrid.Text != txtWHTCode.Text) &&
                (ScgDbQueryProvider.DbWithHoldingTaxQuery.isDuplicationWHTCode(WHTTax.WhtCode)))
            {
                errors.AddError("WHT.Error", new Spring.Validation.ErrorMessage("DuplicationWhtCode"));
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
        }
        protected void ctlFormViewWHT_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            short            WHTId  = UIHelper.ParseShort(ctlFormViewWHT.DataKey.Value.ToString());
            DbWithHoldingTax WHTTax = DbWithHoldingTaxService.FindByIdentity(WHTId);

            TextBox  txtWHTCode = ctlFormViewWHT.FindControl("ctlTxtWHTCode") as TextBox;
            TextBox  txtWHTName = ctlFormViewWHT.FindControl("ctlTxtWHTName") as TextBox;
            TextBox  txtRate    = ctlFormViewWHT.FindControl("ctlTxtRate") as TextBox;
            CheckBox chkActive  = ctlFormViewWHT.FindControl("chkActive") as CheckBox;
            TextBox  txtSeq     = ctlFormViewWHT.FindControl("ctlSeq") as TextBox;

            double douRate = 0;

            try
            { douRate = UIHelper.ParseDouble(txtRate.Text); }
            catch
            { douRate = 0; }

            WHTTax.WhtCode = txtWHTCode.Text;
            WHTTax.WhtName = txtWHTName.Text;
            WHTTax.Rate    = douRate;
            WHTTax.Active  = chkActive.Checked;
            if (!string.IsNullOrEmpty(txtSeq.Text))
            {
                WHTTax.Seq = Helper.UIHelper.ParseInt(txtSeq.Text);
            }
            else
            {
                WHTTax.Seq = null;
            }


            WHTTax.UpdPgm  = ProgramCode;
            WHTTax.UpdDate = DateTime.Now.Date;
            WHTTax.UpdBy   = UserAccount.UserID;

            try
            {
                CheckDataValueUpdate(WHTTax);
                DbWithHoldingTaxService.SaveOrUpdate(WHTTax);

                e.Cancel = true;
                ctlGridWithholdingTax.DataCountAndBind();
                ctlModalPopupWHT.Hide();
                updPanelGridView.Update();

                //ctlMessage.Message = GetMessage("SaveSuccessFully");
            }
            catch (ServiceValidationException ex)
            {
                ValidationErrors.MergeErrors(ex.ValidationErrors);
            }
        }
        protected void ctlGridWithholdingTax_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "WHTEdit")
            {
                int   rowIndex   = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                short WHTTaxCode = UIHelper.ParseShort(ctlGridWithholdingTax.DataKeys[rowIndex].Value.ToString());

                ctlGridWithholdingTax.EditIndex = rowIndex;
                IList <DbWithHoldingTax> WHTTaxList = new List <DbWithHoldingTax>();
                DbWithHoldingTax         WHTTax     = DbWithHoldingTaxService.FindByIdentity(WHTTaxCode);

                WHTTaxList.Add(WHTTax);

                ctlFormViewWHT.DataSource = WHTTaxList;
                ctlFormViewWHT.PageIndex  = 0;

                ctlFormViewWHT.ChangeMode(FormViewMode.Edit);
                ctlFormViewWHT.DataBind();

                updPanelFormView.Update();
                ctlModalPopupWHT.Show();
            }
            else if (e.CommandName == "WHTDelete")
            {
                int   rowIndex   = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                short WHTTaxCode = UIHelper.ParseShort(ctlGridWithholdingTax.DataKeys[rowIndex].Value.ToString());

                DbWithHoldingTax WHTTax = DbWithHoldingTaxService.FindByIdentity(WHTTaxCode);

                DbWithHoldingTaxService.Delete(WHTTax);
                ctlGridWithholdingTax.DataCountAndBind();
                updPanelGridView.Update();

                //ctlMessage.Message = GetMessage("DeleteSuccessFully");
            }
        }