Ejemplo n.º 1
0
        protected void GridACCPeriodType_RowUpdating1(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                //check Name
                if (!e.OldValues["Name"].Equals(e.NewValues["Name"]))
                {
                    if (bo.checkAccountingPeriodType_Name(uow, e.NewValues["Name"].ToString().Trim()))
                    {
                        e.Cancel = true;
                        throw new Exception(String.Format("Lỗi trùng Tên Chu Kỳ Thuế"));
                    }
                }
                //end check name

                AccountingPeriodType AccPt = uow.GetObjectByKey <AccountingPeriodType>(Guid.Parse(e.Keys[0].ToString()));

                #region update IsDefautl
                if (e.NewValues["IsDefault"] == null)
                {
                    e.NewValues["IsDefault"] = false;
                }
                bool IsDefault = bool.Parse(e.NewValues["IsDefault"].ToString());

                if (IsDefault)
                {
                    if (bo.changeIsDefaultAccountingPeriodType(uow))
                    {
                        e.NewValues["IsDefault"] = true;
                    }
                }
                #endregion

                AccPt.Name      = e.NewValues["Name"].ToString();
                AccPt.IsDefault = bool.Parse(e.NewValues["IsDefault"].ToString());
                if (e.NewValues["Description"] == null)
                {
                    e.NewValues["Description"] = "";
                }
                AccPt.Description = e.NewValues["Description"].ToString();
                uow.FlushChanges();
                GridACCPeriodType.DataBind();
                GridACCPeriodType.CancelEdit();
            }
            catch (Exception)
            {
                e.Cancel = true;
                throw;
            }
        }
Ejemplo n.º 2
0
        protected void GridACCPeriodType_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                if (bo.checkAccountingPeriodType_Name(uow, e.NewValues["Name"].ToString().Trim()))
                {
                    e.Cancel = true;
                    throw new Exception(String.Format("Lỗi trùng Tên Chu Kỳ Thuế"));
                }
                else
                {
                    AccountingPeriodType AccPT = new AccountingPeriodType(uow);

                    #region Add IsDefault
                    if (e.NewValues["IsDefault"] == null)
                    {
                        e.NewValues["IsDefault"] = false;
                    }
                    bool isDefault = bool.Parse(e.NewValues["IsDefault"].ToString());

                    if (isDefault)
                    {
                        if (bo.changeIsDefaultAccountingPeriodType(uow))
                        {
                            e.NewValues["IsDefault"] = true;
                        }
                    }
                    #endregion
                    AccPT.Name      = e.NewValues["Name"].ToString();
                    AccPT.IsDefault = bool.Parse(e.NewValues["IsDefault"].ToString());
                    AccPT.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE;
                    if (e.NewValues["Description"] == null)
                    {
                        e.NewValues["Description"] = "";
                    }
                    AccPT.Description = e.NewValues["Description"].ToString();
                    uow.FlushChanges();
                    GridACCPeriodType.DataBind();
                    GridACCPeriodType.CancelEdit();
                }
            }
            catch (Exception)
            {
                e.Cancel = true;
                throw;
            }
        }