Exemplo n.º 1
0
    protected void cmdSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) return;
        UpdateOrderData();
        if (!CheckPartNo(true)) return;

        PartSalesDAO.CleanUp();
        var db = DCFactory.GetDataContext<PartDataContext>();
        try
        {
            db.SubmitChanges();
        }
        catch { }

        if (PartSalesDAO.Parts.Count == 0) return;

        string svn = string.Empty;
        if (OrderId == 0)
        {
            var h = new SalesHeader
            {
                DealerCode = UserHelper.DealerCode,
                OrderDate = UserHelper.ParseDate(tbOrderDate.Text, false),
                CustomerName = cn.Text,
                Status = OrderStatus.OrderOpen,
                SalesPerson = UserHelper.Username,
                SubTotal = PartSalesDAO.Parts.Sum(i => i.Amount),
                TaxAmount = 0,
                Discount = PartSalesDAO.Parts.Sum(i => i.DiscountAmount),
                ModifiedDate = DateTime.Now,
                WarehouseId = UserHelper.WarehouseId,
                SalesComment = string.IsNullOrEmpty(tbComment.Text) ? null : tbComment.Text,
                SalesDate = GetSalesDate()
            };
            h.SalesOrderNumber = PartSalesDAO.GenSaleNumber(h);
            tbTSVN.Text = tbTSVN.Text.Trim();
            if (!string.IsNullOrEmpty(tbTSVN.Text)) h.ManualVoucherNumber = tbTSVN.Text;
            if (ddl1.SelectedIndex > 0) h.CustomerId = long.Parse(ddl1.SelectedValue);

            foreach (var item in PartSalesDAO.Parts)
            {
                var obj = new SalesDetail
                {
                    PartCode = item.PartCode,
                    PartInfoId = item.PartInfoId,
                    PartName = item.PartName,
                    OrderQuantity = item.Quantity,
                    UnitPrice = item.UnitPrice,
                    PercentDiscount = item.Discount,
                    LineTotal = item.Amount,
                    ModifiedDate = DateTime.Now,
                    PartType = item.PartType,
                    SalesHeader = h
                };
            }
            db.SalesHeaders.InsertOnSubmit(h);
            db.SubmitChanges();
            SalesOrderId = h.SalesHeaderId;
            svn = h.SalesOrderNumber;
        }
        else
        {
            foreach (var item in PartSalesDAO.Parts)
            {
                if (item.SalesDetailId != 0)
                {
                    var od = db.SalesDetails.SingleOrDefault(p => p.SalesDetailId == item.SalesDetailId);
                    if (string.IsNullOrEmpty(item.PartCode) || item.Quantity == 0)
                        db.SalesDetails.DeleteOnSubmit(od);
                    else
                    {
                        od.PartCode = item.PartCode;
                        od.PartName = item.PartName;
                        od.OrderQuantity = item.Quantity;
                        od.PercentDiscount = item.Discount;
                        od.ModifiedDate = DateTime.Now;
                        od.LineTotal = item.Amount;
                    };
                }
                else
                {
                    db.SalesDetails.InsertOnSubmit(new SalesDetail
                    {
                        PartCode = item.PartCode,
                        PartName = item.PartName,
                        OrderQuantity = item.Quantity,
                        UnitPrice = item.UnitPrice,
                        SalesHeaderId = OrderId,
                        PercentDiscount = item.Discount,
                        LineTotal = item.Amount,
                        ModifiedDate = DateTime.Now,
                        PartInfoId = item.PartInfoId,
                        PartType = item.PartType
                    });
                }
                db.SubmitChanges();
            }

            // update amount
            var oh = db.SalesHeaders.Single(p => p.SalesHeaderId == OrderId);
            oh.CustomerName = cn.Text;
            if (ddl1.SelectedIndex > 0) oh.CustomerId = long.Parse(ddl1.SelectedValue);

            oh.SubTotal = PartSalesDAO.Parts.Sum(i => i.Amount);
            oh.Discount = PartSalesDAO.Parts.Sum(i => i.DiscountAmount);
            db.SubmitChanges();

            SalesOrderId = OrderId;
            svn = tbSVN.Text;
        }

        lblSaveOk.Visible = true;
        tbSVN.Text = svn;
        if (sender != null)
        {
            PartSalesDAO.Clear();
            Response.Redirect(string.Format("Sale.aspx?id={0}&save=true&svn={1}", SalesOrderId, svn));
        }
        else
        {
            db.Dispose();
            DCFactory.RemoveDataContext<PartDataContext>();
        }
        //DisableButton();
    }
Exemplo n.º 2
0
    public SaleItem(SalesDetail sd)
    {
        this.UnitPrice = sd.UnitPrice;
        this.PartCode = sd.PartCode;
        this.Discount = sd.PercentDiscount;
        this.Quantity = sd.OrderQuantity;
        this.SaleHeaderId = sd.SalesHeaderId;

        this.SubAmount = (this.UnitPrice * this.Quantity);
        this.SubAmount = this.SubAmount - (this.SubAmount * this.Discount / 100);

        if (sd.SalesHeaderId > 0)
        {
            this.CustId = sd.SalesHeader.CustomerId == null ? 0 : (long)sd.SalesHeader.CustomerId;
            this.CustName = (sd.SalesHeader.CustomerId == null) ? sd.SalesHeader.CustomerName : sd.SalesHeader.Customer.Name;
            this.HeadStatus = sd.SalesHeader.Status;
            this.HeadVoucher = sd.SalesHeader.SalesOrderNumber;
            this.HeadManualVoucher = sd.SalesHeader.ManualVoucherNumber;
        }
    }
Exemplo n.º 3
0
 private void detach_SalesDetails(SalesDetail entity)
 {
     this.SendPropertyChanging();
     entity.PartInfo = null;
 }
Exemplo n.º 4
0
 private void detach_SalesDetails(SalesDetail entity)
 {
     this.SendPropertyChanging();
     entity.SalesHeader = null;
 }
 private void attach_SalesDetails(SalesDetail entity)
 {
     this.SendPropertyChanging("SalesDetails");
     entity.SalesHeader = this;
 }
 private void attach_SalesDetails(SalesDetail entity)
 {
     this.SendPropertyChanging("SalesDetails");
     entity.PartInfo = this;
 }
Exemplo n.º 7
0
 public SaleReportItem(SalesDetail sd)
 {
     this.PartCode = sd.PartCode;
     this.PartName = sd.PartName;
     this.Quantity = sd.OrderQuantity;
     this.UnitPrice = sd.UnitPrice;
     this.Discount = sd.PercentDiscount;
     this.SubAmount = this.UnitPrice * this.Quantity;
     this.DiscountAmount = this.SubAmount * this.Discount / 100;
     this.SubAmount -= this.DiscountAmount;
 }