Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn chắc chắc muốn lưu phiếu nhập này ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (dtTemp.Rows.Count > 0)
                    {
                        var codeId = db.sp_StockInput_GetCodeId().FirstOrDefault().CodeId.Value;

                        var p = new tStockInput();
                        p.StockInputCode = "PN" + DateTime.Now.ToString("ddMMyy") + (codeId + 1).ToString("D3");
                        p.BranchTypeId   = WindowsFormsApplication3.Form1.branch_type_id;
                        p.BranchId       = WindowsFormsApplication3.Form1.branch_id;
                        p.SupplierId     = int.Parse(cboSupplier.SelectedValue.ToString());
                        p.InputType      = 1;//nhap tu ncc
                        p.TotalPrice     = 0;
                        p.Note           = txtNote.Text.Trim();
                        p.Status         = 1;
                        p.CreateAt       = DateTime.Now;
                        p.CreateBy       = WindowsFormsApplication3.Form1.user_id;

                        db.tStockInputs.InsertOnSubmit(p);
                        db.SubmitChanges();

                        for (int i = 0; i < dtTemp.Rows.Count; i++)
                        {
                            var detail = new tStockInputDetail();
                            detail.StockInputId  = p.Id;
                            detail.ProductId     = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                            detail.Quantity      = int.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                            detail.Price         = 0;
                            detail.IsCombo       = false;
                            detail.ComboId       = 0;
                            detail.ComboQuantity = 0;
                            db.tStockInputDetails.InsertOnSubmit(detail);


                            var ton = new tStockInventory();
                            ton.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                            ton.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                            ton.ProductId    = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                            ton.QuantityIn   = byte.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                            ton.CreateAt     = DateTime.Now;
                            ton.Status       = 5;//4;//nhap tra lai;//5//nhap tu ncc//6//nhap dieu chuyen
                            db.tStockInventories.InsertOnSubmit(ton);
                        }
                        db.SubmitChanges();
                        dtTemp.Rows.Clear();
                        resetControl();
                        MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Không có sản phẩm nào trong đơn hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ax)
            {
                MessageBox.Show(ax.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn chắc chắc muốn lưu phiếu xuất này ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (dtTemp.Rows.Count > 0)
                    {
                        object total_price = dtTemp.Compute("SUM(Total)", "");
                        var    codeId      = db.sp_StockOutput_GetCodeId().FirstOrDefault().CodeId.Value;

                        var p = new tStockOutput();
                        p.StockCode    = "XKDC" + DateTime.Now.ToString("ddMMyy") + (codeId + 1).ToString("D3");
                        p.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                        p.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                        p.OutputType   = 2;//xuat noi bo
                        p.Note         = txtNote.Text.Trim();
                        p.BranchToId   = int.Parse(cboBranch.SelectedValue.ToString());
                        p.TotalPrice   = p.Total = double.Parse(total_price.ToString());
                        p.Status       = 2;
                        p.CreateAt     = DateTime.Now;
                        p.CreateBy     = WindowsFormsApplication3.Form1.user_id;
                        db.tStockOutputs.InsertOnSubmit(p);
                        db.SubmitChanges();

                        for (int i = 0; i < dtTemp.Rows.Count; i++)
                        {
                            if (int.Parse(dtTemp.Rows[i]["IsCombo"].ToString()) == 0)
                            {
                                var detail = new tStockOutputDetail();
                                detail.StockOutputId = p.Id;
                                detail.ProductId     = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                                detail.Quantity      = int.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                                detail.Price         = double.Parse(dtTemp.Rows[i]["Price"].ToString().Replace(",", ""));
                                detail.IsCombo       = false;
                                detail.ComboId       = 0;
                                detail.ComboQuantity = 0;
                                db.tStockOutputDetails.InsertOnSubmit(detail);

                                var ton = new tStockInventory();
                                ton.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                                ton.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                                ton.ProductId    = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                                ton.QuantityOut  = byte.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                                ton.CreateAt     = DateTime.Now;
                                ton.Status       = 3;//1//xuat ban//2//qua tang//3//xuat dieu chuyen
                                db.tStockInventories.InsertOnSubmit(ton);
                            }
                            else
                            {
                                //is combo, foreach product in combo
                                var pd = from x in db.tCombos
                                         from y in db.tComboDetails
                                         where x.Id == y.ComboId && x.ComboId == dtTemp.Rows[i]["ProductId"].ToString()
                                         select new { x.Id, y.ProductId, y.Quantity };
                                foreach (var item in pd.ToList())
                                {
                                    var detail = new tStockOutputDetail();
                                    detail.StockOutputId = p.Id;
                                    detail.ProductId     = item.ProductId.Value;
                                    detail.Quantity      = int.Parse(dtTemp.Rows[i]["Quantity"].ToString()) * item.Quantity.Value;
                                    detail.IsCombo       = true;
                                    detail.ComboId       = item.Id;
                                    detail.ComboQuantity = byte.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                                    db.tStockOutputDetails.InsertOnSubmit(detail);

                                    var ton = new tStockInventory();
                                    ton.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                                    ton.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                                    ton.ProductId    = item.ProductId.Value;
                                    ton.QuantityOut  = byte.Parse((int.Parse(dtTemp.Rows[i]["Quantity"].ToString()) * item.Quantity.Value).ToString());
                                    ton.CreateAt     = DateTime.Now;
                                    ton.Status       = 3;//1//xuat ban//2//qua tang//3//xuat dieu chuyen
                                    db.tStockInventories.InsertOnSubmit(ton);
                                }
                            }
                        }
                        db.SubmitChanges();
                        dtTemp.Rows.Clear();
                        resetControl();
                        MessageBox.Show("Lưu thành công, đã gửi phiếu xuất tới chi nhánh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Không có sản phẩm nào trong đơn hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ax)
            {
                MessageBox.Show(ax.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtOutputCode.Text.Trim().Equals(""))
            {
                MessageBox.Show("Nhập mã phiếu xuất", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (dtTemp.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu nào để lưu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (MessageBox.Show("Bạn chắc chắc muốn lưu phiếu nhập này ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var    codeId      = db.sp_StockInput_GetCodeId().FirstOrDefault().CodeId.Value;
                    object total_price = dtTemp.Compute("SUM(Total)", "");

                    var p = new tStockInput();
                    p.StockInputCode  = "HBTL" + DateTime.Now.ToString("ddMMyy") + (codeId + 1).ToString("D3");
                    p.BranchTypeId    = WindowsFormsApplication3.Form1.branch_type_id;
                    p.BranchId        = WindowsFormsApplication3.Form1.branch_id;
                    p.StockOutputCode = txtOutputCode.Text.Trim().ToUpper();
                    p.InputType       = 0;//nhap tra lai
                    p.TotalPrice      = double.Parse(total_price.ToString());
                    p.Note            = txtNote.Text.Trim();
                    p.Status          = 1;
                    p.CreateAt        = DateTime.Now;
                    p.CreateBy        = WindowsFormsApplication3.Form1.user_id;

                    db.tStockInputs.InsertOnSubmit(p);
                    db.SubmitChanges();

                    for (int i = 0; i < dtTemp.Rows.Count; i++)
                    {
                        if (int.Parse(dtTemp.Rows[i]["IsCombo"].ToString()) == 0)
                        {
                            var detail = new tStockInputDetail();
                            detail.StockInputId  = p.Id;
                            detail.ProductId     = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                            detail.Quantity      = int.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                            detail.Price         = double.Parse(dtTemp.Rows[i]["Price"].ToString());
                            detail.IsCombo       = false;
                            detail.ComboId       = 0;
                            detail.ComboQuantity = 0;
                            db.tStockInputDetails.InsertOnSubmit(detail);


                            var ton = new tStockInventory();
                            ton.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                            ton.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                            ton.ProductId    = int.Parse(dtTemp.Rows[i]["ProductId"].ToString());
                            ton.QuantityIn   = byte.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                            ton.CreateAt     = DateTime.Now;
                            db.tStockInventories.InsertOnSubmit(ton);
                        }
                        else
                        {
                            //is combo, foreach product in combo
                            var pd = from x in db.tCombos
                                     from y in db.tComboDetails
                                     where x.Id == y.ComboId && x.Id == Int64.Parse(dtTemp.Rows[i]["IsCombo"].ToString())
                                     select new { x.Id, y.ProductId, y.Quantity };
                            var si = 0;
                            foreach (var item in pd.ToList())
                            {
                                var detail = new tStockInputDetail();
                                detail.StockInputId = p.Id;
                                detail.ProductId    = item.ProductId.Value;
                                detail.Quantity     = int.Parse(dtTemp.Rows[i]["Quantity"].ToString()) * item.Quantity.Value;
                                if (si == 0)
                                {
                                    detail.Price = double.Parse(dtTemp.Rows[i]["Price"].ToString());
                                }
                                else
                                {
                                    detail.Price = 0;
                                }
                                detail.IsCombo       = true;
                                detail.ComboId       = item.Id;
                                detail.ComboQuantity = byte.Parse(dtTemp.Rows[i]["Quantity"].ToString());
                                db.tStockInputDetails.InsertOnSubmit(detail);
                                si++;

                                var ton = new tStockInventory();
                                ton.BranchTypeId = WindowsFormsApplication3.Form1.branch_type_id;
                                ton.BranchId     = WindowsFormsApplication3.Form1.branch_id;
                                ton.ProductId    = item.ProductId.Value;
                                ton.QuantityIn   = byte.Parse((int.Parse(dtTemp.Rows[i]["Quantity"].ToString()) * item.Quantity.Value).ToString());
                                ton.CreateAt     = DateTime.Now;
                                db.tStockInventories.InsertOnSubmit(ton);
                            }
                        }
                    }
                    db.SubmitChanges();
                    dtTemp.Rows.Clear();
                    txtNote.Text        = "";
                    txtOutputCode.Text  = "";
                    txtProductCode.Text = "";
                    MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }