protected void ctlBankFormView_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            DbBank dbBank = new DbBank();

            TextBox  txtBankNo  = ctlBankFormView.FindControl("ctlTxtBankNo") as TextBox;
            TextBox  txtComment = ctlBankFormView.FindControl("ctlTxtComment") as TextBox;
            CheckBox chkActive  = ctlBankFormView.FindControl("chkActive") as CheckBox;

            dbBank.BankNo  = txtBankNo.Text;
            dbBank.Comment = txtComment.Text;
            dbBank.Active  = chkActive.Checked;

            dbBank.UpdPgm  = ProgramCode;
            dbBank.CreDate = DateTime.Now.Date;
            dbBank.UpdDate = DateTime.Now.Date;
            dbBank.CreBy   = UserAccount.UserID;
            dbBank.UpdBy   = UserAccount.UserID;

            try
            {
                DbBankService.Save(dbBank);
                e.Cancel = true;
                ctlGridBank.DataCountAndBind();
                ctlBankModalPopupExtender.Hide();
                UpdatePanelGridView.Update();
            }
            catch
            { }
            //catch (ServiceValidationException ex)
            //{
            //    ValidationErrors.MergeErrors(ex.ValidationErrors);
            //}
        }
        protected void ctlBankFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            short  bankId = UIHelper.ParseShort(ctlBankFormView.DataKey.Value.ToString());
            DbBank dbBank = DbBankService.FindByIdentity(bankId);

            TextBox  txtBankNo  = ctlBankFormView.FindControl("ctlTxtBankNo") as TextBox;
            TextBox  txtComment = ctlBankFormView.FindControl("ctlTxtComment") as TextBox;
            CheckBox chkActive  = ctlBankFormView.FindControl("chkActive") as CheckBox;

            dbBank.BankNo  = txtBankNo.Text;
            dbBank.Comment = txtComment.Text;
            dbBank.Active  = chkActive.Checked;

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

            try
            {
                DbBankService.SaveOrUpdate(dbBank);

                // Cancel insert with DataSource.
                e.Cancel = true;
                ctlGridBank.DataCountAndBind();
                ctlBankModalPopupExtender.Hide();
                UpdatePanelGridView.Update();
            }
            catch
            { }
            //catch ( ServiceValidationException ex)
            //{
            //    ValidationErrors.MergeErrors(ex.ValidationErrors);
            //}
        }
        protected void ctlGridBank_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "BankEdit")
            {
                int   rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                short bankId   = UIHelper.ParseShort(ctlGridBank.DataKeys[rowIndex].Value.ToString());

                ctlGridBank.EditIndex = rowIndex;
                IList <DbBank> bankList = new List <DbBank>();
                DbBank         bank     = DbBankService.FindByIdentity(bankId);

                bankList.Add(bank);

                ctlBankFormView.DataSource = bankList;
                ctlBankFormView.PageIndex  = 0;

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

                UpdatePanelBankForm.Update();
                ctlBankModalPopupExtender.Show();
                BankLangGridViewFinish();
            }
            else if (e.CommandName == "Select")
            {
                int   rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                short bankId   = UIHelper.ParseShort(ctlGridBank.DataKeys[rowIndex].Value.ToString());

                ctlBankLangGrid.DataSource = DbBankLangService.FindByBankId(bankId);
                ctlBankLangGrid.DataBind();

                if (ctlBankLangGrid.Rows.Count > 0)
                {
                    ctlSubmit.Visible          = true;
                    ctlCancel.Visible          = true;
                    ctlBankLangLangFds.Visible = true;
                }
                else
                {
                    ctlSubmit.Visible          = false;
                    ctlCancel.Visible          = false;
                    ctlBankLangLangFds.Visible = false;
                }
                ctlBankLangUpdatePanel.Update();
            }
        }
        protected void ctlBtnDeleteBank_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in ctlGridBank.Rows)
            {
                if ((row.RowType == DataControlRowType.DataRow) && ((CheckBox)row.FindControl("ctlSelect")).Checked)
                {
                    short bankId = UIHelper.ParseShort(ctlGridBank.DataKeys[row.RowIndex].Value.ToString());
                    if (!((CheckBox)row.FindControl("ctlChkActive")).Checked)//ไม่ Active
                    {
                        try
                        {
                            BankLangGridViewFinish();
                            DbBank bank = DbBankService.FindProxyByIdentity(bankId);
                            ScgDbDaoProvider.DbBankLangDao.DeleteAllBankLang(bankId);
                            DbBankService.Delete(bank);
                            UpdatePanelGridView.Update();
                        }
                        catch (Exception ex)
                        {
                            if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547)
                            {
                                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData",
                                                                        "alert('Bank ID : " + bankId.ToString() + " is Active. Can't Delete It');", true);
                            }
                        }
                    }
                    else//Active
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertActiveData",
                                                                "alert('Bank ID :" + bankId.ToString() + " is Active. Can't Delete It');", true);
                    }
                }
            }

            ctlGridBank.DataCountAndBind();
        }