コード例 #1
0
 public static CommandResult Create(WAREHOUSE_TRANSACTION c)
 {
     using (var context = new GST_MockProjectEntities())
     {
         c.CreateDate = DateTime.Now;
         c.CreateBy   = UserService.GetUserInfo().ID;
         context.WAREHOUSE_TRANSACTION.Add(c);
         context.SaveChanges();
         //TODO
         //context.Log(c, LogType.BankBranch_Create, userId, "", HttpContext.Current.Request.Form);
         return(new CommandResult());
     }
 }
コード例 #2
0
        //hàm tạo mới 1 hóa đơn sẽ tự tạo các chi tiết trong nhập xuất kho
        public static CommandResult Create1(WAREHOUSE_TRANSACTION c, int userId, string[] listSanphamID, string[] listSoluong, string[] listGia)

        {
            using (var context = new GST_MockProjectEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())
                {
                    decimal?Tongtien = 0;
                    c.CreateBy   = userId;
                    c.CreateDate = DateTime.Now;
                    context.WAREHOUSE_TRANSACTION.Add(c);
                    context.SaveChanges();



                    //luu chi tiet san pham
                    var listwtd = new List <WAREHOUSETRANSACTION_DETAIL>();
                    for (var i = 0; i < listSanphamID.Length; i++)
                    {
                        var     SanphamID = int.Parse(listSanphamID[i]);
                        var     Soluong   = decimal.Parse(listSoluong[i]);
                        decimal?price     = null;
                        if (listGia[i] != "")
                        {
                            price    = decimal.Parse(listGia[i]);
                            Tongtien = Tongtien + price;
                        }
                        if (listSoluong[i] != "")
                        {
                            UpdateSoLuongSanPham(c.Warehouse_ID, SanphamID, Soluong);
                        }
                        var wtd = new WAREHOUSETRANSACTION_DETAIL()
                        {
                            WarehouseTransaction_ID = c.ID,
                            Product_ID = SanphamID,
                            Quantity   = Soluong,
                            Amount     = price
                        };
                        listwtd.Add(wtd);
                    }

                    context.WAREHOUSETRANSACTION_DETAIL.AddRange(listwtd);

                    context.SaveChanges();
                    dbTran.Commit();
                    return(new CommandResult());
                }
            }
        }
コード例 #3
0
        public static CommandResult Edit(WAREHOUSE_TRANSACTION c)
        {
            using (var context = new GST_MockProjectEntities())
            {
                var NhapXuatKho = context.WAREHOUSE_TRANSACTION.First(x => x.ID == c.ID);

                NhapXuatKho.UpdateDate   = DateTime.Now;
                NhapXuatKho.UpdateBy     = UserService.GetUserInfo().ID;
                NhapXuatKho.Warehouse_ID = c.Warehouse_ID;
                NhapXuatKho.Type         = c.Type.Value;
                context.SaveChanges();
                //TODO
                // context.Log(c, LogType.Customer_Edit, userId, "", HttpContext.Current.Request.Form);
                return(new CommandResult());
            }
        }
コード例 #4
0
        //chỉnh sửa hóa đơn + ch tiết hóa đơn
        public static CommandResult Edit1(WAREHOUSE_TRANSACTION c, int userId, string[] listSanphamID, string[] listSoluong, string[] listGia)
        {
            using (var context = new GST_MockProjectEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())

                {
                    var Nhapxuatkho =
                        context.WAREHOUSE_TRANSACTION.Include(x => x.WAREHOUSETRANSACTION_DETAIL).First(x => x.ID == c.ID);
                    //xóa số lượng sản phẩm đang được chỉnh sửa ở trong chi tiết kho

                    for (int i = 0; i < listSanphamID.Length; i++)
                    {
                        var SanphamID = int.Parse(listSanphamID[i]);
                        var Soluong   =
                            context.WAREHOUSETRANSACTION_DETAIL.Where(y => y.WarehouseTransaction_ID == c.ID && y.Product_ID == SanphamID).First().Quantity;

                        //var Soluong2 = int.Parse(Soluong);
                        UpdateSoLuongSanPham2(c.Warehouse_ID, SanphamID, Soluong.Value);
                    }
                    //xóa danh sách sản phẩm cũ
                    var listwtdOld = Nhapxuatkho.WAREHOUSETRANSACTION_DETAIL;
                    context.WAREHOUSETRANSACTION_DETAIL.RemoveRange(listwtdOld);
                    var listSoluongOld =
                        context.WAREHOUSETRANSACTION_DETAIL.Where(x => x.WarehouseTransaction_ID == c.ID).ToList();

                    //thêm danh sách sản phẩm mới
                    var listwtd = new List <WAREHOUSETRANSACTION_DETAIL>();
                    for (int i = 0; i < listSanphamID.Length; i++)
                    {
                        var     SanphamID = int.Parse(listSanphamID[i]);
                        var     Soluong   = int.Parse(listSoluong[i]);
                        decimal?Giaban    = null;

                        if (listGia[i] != "")
                        {
                            Giaban = decimal.Parse(listGia[i]);
                        }
                        var cthd = new WAREHOUSETRANSACTION_DETAIL()
                        {
                            Product_ID = SanphamID,
                            Quantity   = Soluong,
                            WarehouseTransaction_ID = c.ID,
                            Amount = Giaban
                        };
                        listwtd.Add(cthd);
                    }



                    context.WAREHOUSETRANSACTION_DETAIL.AddRange(listwtd);
                    //Chỉnh sửa lại thông tin hóa đơn khi sửa
                    Nhapxuatkho.UpdateBy   = userId;
                    Nhapxuatkho.UpdateDate = DateTime.Now;
                    Nhapxuatkho.Type       = c.Type;
                    context.SaveChanges();
                    dbTran.Commit();

                    return(new CommandResult(ResultCode.Success, "Sửa thành công"));
                }
            }
        }