Ejemplo n.º 1
0
        protected void treelistCurrency_HtmlDataCellPrepared(object sender, TreeListHtmlDataCellEventArgs e)
        {
            try
            {
                ASPxTreeList tree = sender as ASPxTreeList;
                TreeListNode node = tree.FindNodeByKeyValue(e.NodeKey);
                NAS.DAL.Accounting.Currency.Currency currency = node.DataItem as NAS.DAL.Accounting.Currency.Currency;

                if (currency != null)
                {
                    //Setting Description for node
                    if (e.Column.Name == "Description" && e.Level > 1)
                    {
                        e.Cell.Text = String.Format("1 {0} = {1} {2}",
                                                    currency.ParentCurrencyId.Name,
                                                    currency.NumRequired,
                                                    currency.Name);
                    }
                    else if (e.Column.Name == "Description" && e.Level == 1)
                    {
                        e.Cell.Text = String.Format("Là đơn vị cao nhất");
                    }

                    if (e.Column.FieldName == "NumRequired" && e.Level == 1)
                    {
                        e.Cell.Text = string.Empty;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
 protected void Grid_ExchangeRate_Init(object sender, EventArgs e)
 {
     try
     {
         ASPxGridView grid           = sender as ASPxGridView;
         object       keyvalue       = GetMasterRowKeyValue(grid);
         CurrencyType currencyTypeid = session.GetObjectByKey <CurrencyType>(keyvalue);
         NAS.DAL.Accounting.Currency.Currency currencyId = session.FindObject <NAS.DAL.Accounting.Currency.Currency>(
             CriteriaOperator.And(
                 new BinaryOperator("CurrencyTypeId", currencyTypeid, BinaryOperatorType.Equal),
                 new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE),
                 new BinaryOperator("IsDefault", true, BinaryOperatorType.Equal)
                 ));
         if (currencyId != null)
         {
             CurrencyType_CurencyId = currencyId.CurrencyId.ToString();
             CurrencyType_Id        = currencyTypeid.CurrencyTypeId.ToString();
         }
         else
         {
             throw new Exception(String.Format("Bạn chưa chọn Đơn Vị Mặc Định của {0}", currencyTypeid.Name));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
        protected void Grid_ExchangeRate_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
        {
            try
            {
                ASPxGridView grid = sender as ASPxGridView;
                NAS.DAL.Accounting.Currency.Currency currency_true_master = BO.get_Currency_true_master(session, CurrencyType_Id, true, Utility.Constant.ROWSTATUS_ACTIVE);
                ExchangeRate exchangerate_DenomiratorCurrencyId           = BO.get_ExchangeRate(session, e.KeyValue.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                NAS.DAL.Accounting.Currency.Currency currencyId           = BO.get_CurrencyID(session, exchangerate_DenomiratorCurrencyId.DenomiratorCurrencyId.CurrencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);

                if (currencyId != null)
                {
                    //Setting Description for node
                    if (e.DataColumn.Name == "DenomiratorCurrencyId")
                    {
                        e.Cell.Text = String.Format("{0}", currencyId.Code);
                    }
                    if (e.DataColumn.Name == "Description_edit")
                    {
                        e.Cell.Text = String.Format("1 {0} = {1} {2}", currency_true_master.Code, exchangerate_DenomiratorCurrencyId.Rate, currencyId.Code);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
        protected void Grid_ExchangeRate_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                session.BeginTransaction();

                ASPxGridView grid = sender as ASPxGridView;

                ExchangeRate exchangeid     = session.GetObjectByKey <ExchangeRate>(Guid.Parse(e.Keys[0].ToString()));
                object       keyvalue       = grid.GetMasterRowKeyValue();
                CurrencyType currencyTypeid = session.GetObjectByKey <CurrencyType>(Guid.Parse(keyvalue.ToString()));
                NAS.DAL.Accounting.Currency.Currency currencyid = BO.get_Currency_true_master(session, currencyTypeid.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);

                //NAS.DAL.Accounting.Currency.Currency NumeratorCurrencyId = BO.get_CurrencyId_currencyId(session, currencyid.CurrencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                //NAS.DAL.Accounting.Currency.Currency DenomiratorCurrencyId = BO.get_CurrencyId_currencyId(session, Currency_Id.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                //if (!e.NewValues["BankId!Key"].ToString().Equals(e.OldValues["BankId!Key"].ToString()))
                //    if (BO.check_ExchangeRate_BankId(
                //        session,
                //        NumeratorCurrencyId.CurrencyId.ToString(),
                //        DenomiratorCurrencyId.CurrencyId.ToString(),
                //        bankid.BankId.ToString(),
                //        Utility.Constant.ROWSTATUS_ACTIVE
                //        ))
                //    {
                //        throw new Exception(String.Format("Ngân Hàng {0} Trùng, Yêu Cầu Nhập Lại Ngân Hàng", bankid.Code));
                //    }

                exchangeid.AffectedDate = DateTime.Parse(e.NewValues["AffectedDate"].ToString());
                if (e.NewValues["BankId!Key"] != null)
                {
                    Bank bankid = session.GetObjectByKey <Bank>(Guid.Parse(e.NewValues["BankId!Key"].ToString()));
                    if (bankid != null)
                    {
                        exchangeid.BankId.BankId = bankid.BankId;
                        exchangeid.Name          = bankid.Code;
                    }
                }
                exchangeid.Rate = float.Parse(e.NewValues["Rate"].ToString());
                if (e.NewValues["Description"] != null)
                {
                    exchangeid.Description = e.NewValues["Description"].ToString();
                }
                exchangeid.NumeratorCurrencyId   = BO.get_CurrencyId_currencyId(session, currencyid.CurrencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                exchangeid.DenomiratorCurrencyId = BO.get_CurrencyId_currencyId(session, Currency_Id.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                exchangeid.Status = short.Parse(e.NewValues["Status"].ToString());
                exchangeid.Save();

                session.CommitTransaction();
                grid.CancelEdit();
                grid.DataBind();
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
        }
Ejemplo n.º 5
0
        protected void Grid_ExchangeRate_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
        {
            try
            {
                ASPxGridView grid = sender as ASPxGridView;
                CurrencyType currencytype_true = BO.get_CurrencyType_true(session, true, Utility.Constant.ROWSTATUS_ACTIVE);
                NAS.DAL.Accounting.Currency.Currency currency_true = BO.get_Currency_true_master(session, currencytype_true.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);
                //ExchangeRate ex = session.FindObject<ExchangeRate>(
                //    CriteriaOperator.And(
                //        new BinaryOperator("DenomiratorCurrencyId", currencytype_true, BinaryOperatorType.Equal),
                //        new BinaryOperator("NumeratorCurrencyId", CurrencyType_CurencyId, BinaryOperatorType.Equal),
                //        new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal)
                //    ));
                if (e.Column.Name.Equals("AffectedDate") && grid.IsEditing)
                {
                    e.Editor.Focus();
                }
                if (e.Column.Name.Equals("AffectedDate") && grid.IsNewRowEditing)
                {
                    e.Editor.Focus();
                }
                if (currency_true != null)
                {
                    Currency_Id = currency_true.CurrencyId.ToString();
                    //if (ex != null)
                    //{
                    NAS.DAL.Accounting.Currency.Currency currencyId = BO.get_CurrencyID(session, CurrencyType_CurencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);


                    if (e.Column.Name.Equals("DenomiratorCurrencyId") && grid.IsEditing)
                    {
                        e.Editor.Value = String.Format("{0}", currency_true.Code.ToString());
                    }
                    if (e.Column.Name.Equals("DenomiratorCurrencyId") && grid.IsNewRowEditing)
                    {
                        e.Editor.Value = String.Format("{0}", currency_true.Code.ToString());
                    }

                    if (e.Column.Name.Equals("Description_edit") && grid.IsEditing)
                    {
                        e.Editor.Visible = false;
                    }
                    if (e.Column.Name.Equals("Description_edit") && grid.IsNewRowEditing)
                    {
                        e.Editor.Visible = false;
                    }
                    //}
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        protected void GridCurrencyUnit_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            try
            {
                #region ExchangeRate_IsMaster
                bool         CancelIsMaster  = true;
                CurrencyType currencyType_ID = bo.get_CurrencyType_true(session, true, Utility.Constant.ROWSTATUS_ACTIVE);              //truong hop da chon ismaster
                NAS.DAL.Accounting.Currency.Currency currency_ID = bo.get_Currency_true_master(session, currencyType_ID.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);
                CurrencyType currencyType_id = bo.get_CurrencyTypeId(session, e.Keys[0].ToString(), Utility.Constant.ROWSTATUS_ACTIVE); //truong hop chua chon ismaster
                NAS.DAL.Accounting.Currency.Currency currency_id = bo.get_Currency_true_master(session, currencyType_id.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);
                if (currency_id != null)
                {
                    if (bo.IsUsedInExchangeRate(session, currency_id.CurrencyId))
                    {
                        if (bo.IsUsedInExchangeRate(session, currency_ID.CurrencyId))
                        {
                            CancelIsMaster = false;
                        }

                        if (!CancelIsMaster)
                        {
                            throw new Exception(String.Format("Không được Xóa! Vì Tên Tiền Tệ {0} đã sử dụng trong Tỷ Giá", currencyType_ID.Name));
                        }
                    }
                }
                #endregion

                if (bo.checkIsCurrencyTypeIdInCurrency(session, e.Values["CurrencyTypeId"].ToString().Trim()))
                {
                    e.Cancel = true;
                    throw new Exception(String.Format("Lỗi không thể xóa vì có chứa Đơn Vị Tiền Tệ"));
                }
                else
                {
                    e.Cancel = true;
                    session.BeginTransaction(); //tao session luu gia tri hien tai

                    Guid a = Guid.Parse(e.Keys[0].ToString());
                    NAS.DAL.Accounting.Currency.CurrencyType currT = session.GetObjectByKey <NAS.DAL.Accounting.Currency.CurrencyType>(a);
                    currT.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                    currT.Save();
                    GridCurrencyUnit.DataBind();
                    session.CommitTransaction();
                }
            }
            catch (Exception)
            {
                session.RollbackTransaction();//loi session luu gia tri se rollback
                e.Cancel = true;
                throw;
            }
        }
Ejemplo n.º 7
0
        protected void treelistCurrency_NodeDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                session.BeginTransaction(); //tao session luu gia tri hien tai

                ASPxTreeList treelistCurrency = sender as ASPxTreeList;
                object       keyValue         = GetMasterRowKeyValue(treelistCurrency);

                #region Check ExchangeRate

                bool         CanInsert = true;
                CurrencyType type      = session.GetObjectByKey <CurrencyType>(keyValue);
                NAS.DAL.Accounting.Currency.Currency defaultCurrency = bo.get_Currency_true_master(session, type.CurrencyTypeId.ToString(), true, Constant.ROWSTATUS_ACTIVE);

                if (defaultCurrency != null)
                {
                    if (bo.IsUsedInExchangeRate(session, defaultCurrency.CurrencyId))
                    {
                        CanInsert = false;
                    }
                }
                else
                {
                    CanInsert = true;
                }
                if (!CanInsert)
                {
                    throw new Exception(String.Format("Không được Xóa! Vì Đơn Vị Tiền Tệ {0} đã sử dụng trong Tỷ Giá", defaultCurrency.Code));
                }

                #endregion

                Guid a = Guid.Parse(e.Keys[0].ToString());
                NAS.DAL.Accounting.Currency.Currency curr = session.GetObjectByKey <NAS.DAL.Accounting.Currency.Currency>(a);
                curr.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                curr.Save();
                session.CommitTransaction();
            }
            catch (Exception)
            {
                session.RollbackTransaction();//loi session luu gia tri se rollback
                e.Cancel = true;
                throw;
            }
        }
Ejemplo n.º 8
0
        protected void treelistCurrency_NodeUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            e.Cancel = true;
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                try
                {
                    ASPxTreeList treelistCurrency = sender as ASPxTreeList;
                    object       keyValue         = GetMasterRowKeyValue(treelistCurrency);

                    #region Check ExchangeRate

                    bool         CanInsert = true;
                    CurrencyType type      = session.GetObjectByKey <CurrencyType>(keyValue);
                    NAS.DAL.Accounting.Currency.Currency defaultCurrency = bo.get_Currency_true_master(session, type.CurrencyTypeId.ToString(), true, Constant.ROWSTATUS_ACTIVE);
                    if (e.NewValues["IsDefault"] != null)
                    {
                        if (e.NewValues["IsDefault"].Equals(true))
                        {
                            if (defaultCurrency != null)
                            {
                                if (bo.IsUsedInExchangeRate(session, defaultCurrency.CurrencyId))
                                {
                                    CanInsert = false;
                                }
                            }
                            else
                            {
                                CanInsert = true;
                            }
                        }
                        else
                        {
                            CanInsert = true;
                        }
                        if (!CanInsert)
                        {
                            throw new Exception(String.Format("Không được chọn Đơn Vị Mặc Định! Vì Đơn Vị Tiền Tệ {0} đã sử dụng trong Tỷ Giá", defaultCurrency.Code));
                        }
                    }
                    #endregion

                    #region CHECK CODE
                    CurrencyType cur = uow.GetObjectByKey <CurrencyType>(Guid.Parse(keyValue.ToString()));
                    if (!e.OldValues["Code"].Equals(e.NewValues["Code"]))
                    {
                        if (bo.checkCurrency_Code(session, e.NewValues["Code"].ToString().Trim(), cur.CurrencyTypeId.ToString()))
                        {
                            e.Cancel = true;
                            throw new Exception(String.Format("Lỗi Đơn Vị Tiền Tệ đã có"));
                        }
                    }
                    #endregion
                    object MasterKey = GetMasterRowKeyValue(treelistCurrency);
                    Guid   key       = Guid.Parse(e.Keys[0].ToString());
                    if (e.NewValues["IsDefault"] == null)
                    {
                        e.NewValues["IsDefault"] = false;
                    }

                    bool IsDefault = bool.Parse(e.NewValues["IsDefault"].ToString());

                    NAS.DAL.Accounting.Currency.Currency currency = uow.GetObjectByKey <NAS.DAL.Accounting.Currency.Currency>(key);
                    #region Currency.IsDefault
                    if (IsDefault)
                    {
                        //if (bo.changeIsDefaultCurrency(uow))//, Guid.Parse(treelistCurrency.FocusedNode.Key.ToString())
                        //{
                        currency.IsDefault = true;
                        //}
                        //bo.changeCoefficientCurrency(uow); // Coefficient = 0;
                        if (IsDefault)
                        {
                            bo.updateIsDefaultCurrency(uow, Guid.Parse(MasterKey.ToString()), key, IsDefault);
                        }

                        //if (cur != null)
                        //{
                        //    if (bo.changeIsMasterCurrencyType(uow))
                        //        cur.IsMaster = true;
                        //    cur.Save();
                        //}
                    }
                    else
                    {
                        bo.updateIsDefaultCurrency(uow, Guid.Parse(MasterKey.ToString()), key, IsDefault);
                        currency.IsDefault         = false;
                        e.NewValues["Description"] = "";
                    }
                    #endregion
                    currency.Code        = e.NewValues["Code"].ToString();
                    currency.Name        = e.NewValues["Name"].ToString();
                    currency.NumRequired = double.Parse(e.NewValues["NumRequired"].ToString());

                    uow.FlushChanges();
                    treelistCurrency.CancelEdit();
                    treelistCurrency.DataBind();
                    GridCurrencyUnit.DataBind();
                    treelistCurrency.JSProperties.Add("cpSaved", true);
                }
                catch (Exception)
                {
                    uow.RollbackTransaction();
                    throw;
                }
        }
Ejemplo n.º 9
0
        protected void GridCurrencyUnit_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                session.BeginTransaction();

                #region ExchangeRate_IsMaster
                bool         CancelIsMaster  = true;
                CurrencyType currencyType_ID = bo.get_CurrencyType_true(session, true, Utility.Constant.ROWSTATUS_ACTIVE);
                NAS.DAL.Accounting.Currency.Currency currency_ID = bo.get_Currency_true_master(session, currencyType_ID.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);
                if (currency_ID != null)
                {
                    if (e.NewValues["IsMaster"] != null)
                    {
                        if (e.NewValues["IsMaster"].Equals(true))
                        {
                            if (bo.IsUsedInExchangeRate(session, currency_ID.CurrencyId))
                            {
                                CancelIsMaster = false;
                            }
                        }
                    }
                    if (!CancelIsMaster)
                    {
                        throw new Exception(String.Format("Không được chọn Sử Dụng Chính! Vì Tên Tiền Tệ {0} đã sử dụng trong Tỷ Giá", currencyType_ID.Name));
                    }
                }
                #endregion

                CurrencyType ct = session.GetObjectByKey <CurrencyType>(Guid.Parse(e.Keys[0].ToString()));

                #region check Name
                if (!e.OldValues["Name"].Equals(e.NewValues["Name"]))
                {
                    if (bo.checkCurrencyType_Name(session, e.NewValues["Name"].ToString().Trim()))
                    {
                        e.Cancel = true;
                        throw new Exception(String.Format("Lỗi trùng đơn vị Tiền Tệ"));
                    }
                }
                #endregion

                if (e.NewValues["IsMaster"] == null)
                {
                    e.NewValues["IsMaster"] = false;
                }
                bool isMaster = bool.Parse(e.NewValues["IsMaster"].ToString());

                ct.Name = e.NewValues["Name"].ToString();
                if (e.NewValues["Description"] == null)
                {
                    e.NewValues["Description"] = "";
                }
                ct.Description = e.NewValues["Description"].ToString();
                #region ct.isMaster
                ct.IsMaster = bool.Parse(e.NewValues["IsMaster"].ToString());
                if (isMaster)
                {
                    if (bo.changeIsMasterCurrencyType(session))
                    {
                        e.NewValues["IsMaster"] = true;
                    }
                }
                ct.IsMaster = bool.Parse(e.NewValues["IsMaster"].ToString());
                #endregion
                session.FlushChanges();
                session.CommitTransaction();
                GridCurrencyUnit.DataBind();
                GridCurrencyUnit.CancelEdit();
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
        }