예제 #1
0
        protected void gvEarningCode_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int         id          = 0;
            EarningCode earningCode = null;

            if (e.CommandName == "DoEdit")
            {
                id = Convert.ToInt32(e.CommandArgument);

                using (EarningCodeManager repository = new EarningCodeManager()) {
                    earningCode = repository.Get(id);
                }
                if (earningCode != null)
                {
                    showEditPanel();

                    this.txtEarningCode.Text = earningCode.Code;;

                    this.txtEarningDescription.Text = earningCode.CodeDescription;

                    ViewState["EarningCodeID"] = e.CommandArgument.ToString();
                }
            }
            else if (e.CommandName == "DoDelete")
            {
                try {
                    id = Convert.ToInt32(e.CommandArgument);

                    using (EarningCodeManager repository = new EarningCodeManager()) {
                        earningCode = repository.Get(id);

                        if (earningCode != null)
                        {
                            earningCode.IsActive = false;

                            earningCode = repository.Save(earningCode);

                            // refresh grid
                            bindData();
                        }
                    }
                }
                catch (Exception ex) {
                    Core.EmailHelper.emailError(ex);
                    showErrorMessage();
                }
            }
        }
예제 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            EarningCode earningCode = null;
            int         id          = 0;

            lblMessage.Text     = string.Empty;
            lblMessage.CssClass = string.Empty;

            id = Convert.ToInt32(ViewState["EarningCodeID"]);

            if (id == 0)
            {
                earningCode          = new EarningCode();
                earningCode.ClientID = this.clientID;
                earningCode.IsActive = true;
            }
            else
            {
                using (EarningCodeManager repository = new EarningCodeManager()) {
                    earningCode = repository.Get(id);
                }
            }

            if (earningCode != null)
            {
                earningCode.Code            = this.txtEarningCode.Text.Trim();
                earningCode.CodeDescription = this.txtEarningDescription.Text.Trim();

                try {
                    using (EarningCodeManager repository = new EarningCodeManager()) {
                        earningCode = repository.Save(earningCode);
                    }

                    showGridPanel();

                    // refresh grid
                    bindData();
                }
                catch (Exception ex) {
                    Core.EmailHelper.emailError(ex);
                    showErrorMessage();
                }
            }
        }