Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Debuging.Info("Factor->Try to Page_Load");

                if (!Page.IsPostBack)
                {
                    BindDrpCustomer();

                    if (Page.RouteData.Values["Id"].ToSafeInt() != 0)
                    {
                        var factorId = Page.RouteData.Values["Id"].ToSafeInt();

                        var factorRepo = new FactorRepository();
                        var factor     = factorRepo.GetById(factorId);

                        txtFactorNumber.Text      = factor.FactorNo.ToString();
                        txtDescription.Text       = factor.Description;
                        drpCustomer.SelectedValue = factor.CustomerId.ToString();
                        txtDate.Text = factor.FactorDate.ToFaDate();

                        var factorDetailRepo = new FactorDetailRepository();

                        gridFactor.DataSource = Session["GridSource"] = factorDetailRepo.GetFactorDetails(factorId);
                        gridFactor.DataBind();
                    }
                    else
                    {
                        txtDate.Text          = DateTime.Now.ToFaDate();
                        gridFactor.DataSource = Session["GridSource"] = new List <FactorDetail>();
                        gridFactor.DataBind();

                        txtFactorNumber.Text = (new FactorRepository().GetMaxFactorNo() + 1).ToString();
                    }

                    //BindFooterGoodsUnitDrp();
                }
            }
            catch (Exception ex)
            {
                Debuging.Error(ex, MethodBase.GetCurrentMethod().Name);
            }
            Debuging.Info("Factor->End of Page_Load");
        }
Beispiel #2
0
        //private void BindFooterGoodsUnitDrp()
        //{
        //    try
        //    {
        //        if (gridFactor.FooterRow != null)
        //        {
        //            var footergoodsUnit = ((DropDownList)gridFactor.FooterRow.Cells[2].Controls[1]);
        //            var unitRepo = new GoodsUnitRepository();
        //            footergoodsUnit.DataSource = unitRepo.GetAll();
        //            footergoodsUnit.DataValueField = "Id";
        //            footergoodsUnit.DataTextField = "Name";
        //            footergoodsUnit.DataBind();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Debuging.Error(ex, MethodBase.GetCurrentMethod().Name);
        //    }
        //}

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateData())
                {
                    return;
                }

                if (Page.RouteData.Values["Id"].ToSafeInt() == 0)
                {
                    var uow = new UnitOfWork();

                    var factor = new Repository.Entity.Domain.Factor();

                    factor.FactorNo       = txtFactorNumber.Text.ToSafeInt();
                    factor.CustomerId     = drpCustomer.SelectedValue.ToSafeInt();
                    factor.InsertDateTime = DateTime.Now;
                    factor.FactorDate     = txtDate.Text.ToEnDate();
                    factor.Description    = txtDescription.Text;
                    var fd = ((List <FactorDetail>)Session["GridSource"]);
                    factor.TotalPrice    = fd.Sum(a => a.Count * a.Price);
                    factor.FactorDetails = fd;
                    uow.Factors.Create(factor);

                    var result = uow.SaveChanges();

                    if (result.IsSuccess)
                    {
                        RedirectFactorListActionResultWithMessage();
                    }
                    else
                    {
                        Debuging.Error(MethodBase.GetCurrentMethod().Name + "->" + result.ResultMessage);
                        ShowErrorMsg(MessageText.UNKNOWN_ERROR);
                    }
                }
                else
                {
                    var uow = new UnitOfWork();

                    var toBeEditedfactor = uow.Factors.Find(Page.RouteData.Values["Id"].ToSafeInt());

                    toBeEditedfactor.FactorNo       = txtFactorNumber.Text.ToSafeInt();
                    toBeEditedfactor.CustomerId     = drpCustomer.SelectedValue.ToSafeInt();
                    toBeEditedfactor.UpdateDateTime = DateTime.Now;
                    toBeEditedfactor.FactorDate     = txtDate.Text.ToEnDate();
                    toBeEditedfactor.Description    = txtDescription.Text;

                    var fd = ((List <FactorDetail>)Session["GridSource"]);

                    toBeEditedfactor.TotalPrice    = fd.Sum(a => a.Count * a.Price);
                    toBeEditedfactor.FactorDetails = fd;

                    var oldFdIds = new FactorDetailRepository().GetFactorDetails(toBeEditedfactor.Id).Select(a => a.Id);

                    uow.FactorDetails.Delete(a => oldFdIds.Contains(a.Id));

                    var result = uow.SaveChanges();

                    if (result.IsSuccess)
                    {
                        RedirectFactorListActionResultWithMessage();
                    }
                    else
                    {
                        Debuging.Error(MethodBase.GetCurrentMethod().Name + "->" + result.ResultMessage);
                        ShowErrorMsg(MessageText.UNKNOWN_ERROR);
                    }
                }
            }
            catch (Exception ex)
            {
                Debuging.Error(ex, MethodBase.GetCurrentMethod().Name);
                ShowErrorMsg(MessageText.UNKNOWN_ERROR);
            }
        }