Example #1
0
 public bool Update(Kho entity)
 {
     try
     {
         var model = db.Khoes.Find(entity.ID);
         if (model != null)
         {
             //model.DonHangID = entity.DonHangID;
             model.Ten       = entity.Ten;
             model.DiaChi    = entity.DiaChi;
             model.QuanLyKho = entity.QuanLyKho;
             model.SLToiDa   = entity.SLToiDa;
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #2
0
        public void Action_Kho(int action, int id, string sonhapkho, int soluong, string ngaynhapkho, int id_po, int id_po_chi_tiet, int id_phongban)
        {
            Kho        kho = new Kho();
            List <Kho> tb  = kho.LayDanhSachKho(action, id, sonhapkho, soluong, ngaynhapkho, id_po, id_po_chi_tiet, id_phongban);

            Context.Response.Write(JsonConvert.SerializeObject(tb));
        }
Example #3
0
 void add()
 {
     if (tb_makho.Text == "" || tb_tenkho.Text == "")
     {
         MessageBox.Show("Mã kho và tên kho không đc để trống", "Cảnh báo");
     }
     else
     {
         try
         {
             Kho kho = new Kho()
             {
                 Ma_kho = tb_makho.Text, Ten_kho = tb_tenkho.Text
             };
             db.Khoes.Add(kho);
             db.SaveChanges();
             MessageBox.Show("Thêm mới thành công", "Message");
             tb_makho.Text  = "";
             tb_tenkho.Text = "";
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.ToString(), "ERROR");
         }
     }
 }
Example #4
0
 public long Insert(Kho entity)
 {
     entity.Status = true;
     db.Khoes.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (txtTenKho.Text == "")
     {
         MessageBox.Show("Chưa nhập tên kho!");
         txtTenKho.Focus();
     }
     else if (txtViTri.Text == "")
     {
         MessageBox.Show("Chưa nhập vị trí!");
         txtViTri.Focus();
     }
     else
     {
         Kho _kho = new Kho {
             Tenkho = txtTenKho.Text, Vitri = txtViTri.Text
         };
         if (KhoBUL.Instance.InsertKho(_kho))
         {
             MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadKhoSach();
         }
         else
         {
             MessageBox.Show("Thêm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        public void InsertK(Kho k)
        {

            db.Khoes.Add(k);
            db.SaveChanges();

        }
Example #7
0
 public int Update(Kho kho)
 {
     if (Load_DAL("select * from Kho where MaKho='" + kho.MaKho + "'").Rows.Count == 0)
     {
         return(2);
     }
     else if (Load_DAL("select * from Kho where TenKho='" + kho.TenKho + "' and MaKho <> '" + kho.MaKho + "'").Rows.Count > 0)
     {
         return(3);
     }
     else
     {
         SqlCommand cmd = new SqlCommand("Update_Kho", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add(new SqlParameter("@ten", kho.TenKho));
         cmd.Parameters.Add(new SqlParameter("@dc", kho.DiaChi));
         cmd.Parameters.Add(new SqlParameter("@nvql", kho.NVQL));
         cmd.Parameters.Add(new SqlParameter("@dt", kho.DT));
         cmd.Parameters.Add(new SqlParameter("@ma", kho.MaKho));
         try { if (con.State != ConnectionState.Open)
               {
                   con.Open();
               }
         } catch { return(-2); }
         try { cmd.ExecuteNonQuery(); return(1); } catch { return(0); } finally { if (con.State == ConnectionState.Open)
                                                                                  {
                                                                                      con.Close();
                                                                                  }
         }
     }
 }
Example #8
0
 public int Delete(Kho kho)
 {
     if (Load_DAL("select * from Kho where MaKho='" + kho.MaKho + "'").Rows.Count == 0)
     {
         return(2);
     }
     else if (Load_DAL("select * from PhieuNhap where MaKho='" + kho.MaKho + "'").Rows.Count > 0)
     {
         return(3);
     }
     else if (Load_DAL("select * from PhieuXuat where MaKho='" + kho.MaKho + "'").Rows.Count > 0)
     {
         return(4);
     }
     else if (Load_DAL("select * from CTMH where MaKho='" + kho.MaKho + "'").Rows.Count > 0)
     {
         return(5);
     }
     else
     {
         SqlCommand cmd = new SqlCommand("Delete_Kho", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add(new SqlParameter("@ma", kho.MaKho));
         try { if (con.State != ConnectionState.Open)
               {
                   con.Open();
               }
         } catch { return(-2); }
         try { cmd.ExecuteNonQuery(); return(1); } catch { return(0); } finally { if (con.State == ConnectionState.Open)
                                                                                  {
                                                                                      con.Close();
                                                                                  }
         }
     }
 }
Example #9
0
        public bool addSach(Phieunhap phieunhap,CTPN[] ctpn)
        {
            try
            {//phieunhap.NgayNhap = DateTime.Today;
                NoNXB no = new NoNXB();
                Kho kho = new Kho();
                //tao dl ao
                no.NgayNhap = phieunhap.NgayNhap;
                no.IdNXB = phieunhap.IdNXB;
                kho.NgayGhi = phieunhap.NgayNhap;

                foreach (var i in ctpn) //code ctpn in here
                {
                    Sach sach = db.Saches.Find(i.IdSach);
                    kho.IdSach = sach.IdSach;
                    kho.SL = i.SoLuong;
                    no.TienNo = i.SoLuong * sach.GiaNhap;
                    UpdateNo(no);
                    UpdateKho(kho);
                    phieunhap.CTPNs.Add(i);
                    db.SaveChanges();

                }
                db.Phieunhaps.Add(phieunhap);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Example #10
0
        public ActionResult Create(Kho entity)
        {
            var dao = new KhoDao();

            dao.Insert(entity);
            return(RedirectToAction("Index"));
        }
Example #11
0
 public bool CreateDetailCoupon(ChiTietPhieu DetailCouponToCreate)
 {
     //            if (!ValidateDetailCoupon(DetailCouponToCreate))
     //   return false;
     try
     {
         _detailCouponrepository.createDetailCoupon(DetailCouponToCreate);
         SanPham       product = _productrepository.GetProduct(DetailCouponToCreate.MaSP);
         Kho           target  = getWareHouse(DetailCouponToCreate.MaSP);
         PhieuNhapXuat Phieu   = getCoupon(DetailCouponToCreate.MaPhieu);
         if (Phieu.TrangThai.Equals("Nhập"))
         {
             target.SoLuong = target.SoLuong + DetailCouponToCreate.SoLuong;
             target.NgayLap = Phieu.NgayLap;
         }
         else
         {
             target.SoLuong  = target.SoLuong - DetailCouponToCreate.SoLuong;
             product.SoLuong = product.SoLuong + DetailCouponToCreate.SoLuong;
             target.NgayXuat = Phieu.NgayLap;
             _productrepository.EditProduct(product);
         }
         _warehouserepository.UpdateWareHouse(target);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Example #12
0
 public bool UpdateDetailCoupon(ChiTietPhieu DetailCouponToEdit)
 {
     try
     {
         SanPham       product = _productrepository.GetProduct(DetailCouponToEdit.MaSP);
         Kho           target  = getWareHouse(DetailCouponToEdit.MaSP);
         PhieuNhapXuat Phieu   = getCoupon(DetailCouponToEdit.MaPhieu);
         ChiTietPhieu  chitiet = getDetailCoupon(DetailCouponToEdit.MaPhieu, DetailCouponToEdit.MaSP);
         if (Phieu.TrangThai.Equals("Nhập"))
         {
             target.SoLuong = target.SoLuong - chitiet.SoLuong + DetailCouponToEdit.SoLuong;
             target.NgayLap = Phieu.NgayLap;
         }
         else
         {
             target.SoLuong  = target.SoLuong + chitiet.SoLuong - DetailCouponToEdit.SoLuong;
             product.SoLuong = product.SoLuong - chitiet.SoLuong + DetailCouponToEdit.SoLuong;
             target.NgayXuat = Phieu.NgayLap;
             _productrepository.EditProduct(product);
         }
         _warehouserepository.UpdateWareHouse(target);
     }
     catch { return(false); }
     _detailCouponrepository.editDetailCoupon(DetailCouponToEdit);
     return(true);
 }
Example #13
0
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_makho.Text))
            {
                Form1.Default.ShowMessageWarning("Bạn phải nhập vào mã kho.");
                txt_makho.Focus(); return;
            }
            if (string.IsNullOrEmpty(txt_tenkho.Text))
            {
                Form1.Default.ShowMessageWarning("Bạn phải nhập vào tên kho.");
                txt_tenkho.Focus(); return;
            }

            if (Convert.ToInt32(ExecSQL.ExecQuerySacalar($"SELECT COUNT(*) FROM dbo.tbl_kho WHERE makho='{txt_makho.Text}'")) > 0)
            {
                Form1.Default.ShowMessageError("Mã kho này đã tồn tại.");
                txt_makho.Focus(); return;
            }
            var kho = new Kho {
                makho = txt_makho.Text, tenkho = txt_tenkho.Text, nguoitd = ComicPro.StrTenDangNhap.ToUpper()
            };

            ExecSQL.Insert(kho);
            XoaText();
            //Gửi dữ liệu
            var message = new MessageBroker
            {
                data = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                task = "kho"
            };

            message.Publish();
        }
Example #14
0
        //Bán hàng

        public static DataTable LayChungTuBH()
        {
            try
            {
                Kho       dao          = new Kho();
                DataTable dataTableCT  = dao.ChitietChungTuBH();
                DonViTinh dv           = new DonViTinh();
                DataTable dataTableDV  = dv.LoadDVTDonGian();
                DataTable dataTableKho = dao.LoadKhoHang();
                DataTable dataTableBH  = dao.LayChungTuBH();

                var results = from table1 in dataTableCT.AsEnumerable()
                              join table2 in dataTableDV.AsEnumerable() on(string) table1["Unit"] equals(string) table2["UNIT_ID"]
                              join table3 in dataTableKho.AsEnumerable() on(string) table1["Stock_ID"] equals(string) table3["Stock_ID"]
                              join table4 in dataTableBH.AsEnumerable() on(string) table1["Outward_ID"] equals(string) table4["ID"]
                              select new
                {
                    Outward_ID   = table1["Outward_ID"].ToString(),
                    RefDate      = DateTime.Parse(table4["RefDate"].ToString()),
                    Description  = table1["Description"].ToString(),
                    Product_ID   = table1["Product_ID"].ToString(),
                    ProductName  = table1["ProductName"].ToString(),
                    Stock_ID     = table3["Stock_Name"].ToString(),
                    Unit         = table2["Unit_Name"].ToString(),
                    Quantity     = float.Parse(table1["Quantity"].ToString()),
                    UnitPrice    = float.Parse(table1["UnitPrice"].ToString()),
                    Charge       = float.Parse(table1["Charge"].ToString()),
                    DiscountRate = float.Parse(table1["DiscountRate"].ToString()),
                    Discount     = float.Parse(table1["Discount"].ToString()),
                    Amount       = float.Parse(table1["Amount"].ToString())
                };

                DataTable rs = new DataTable();
                rs.Columns.Add("Outward_ID");
                rs.Columns.Add("RefDate");
                rs.Columns.Add("Description");
                rs.Columns.Add("Product_ID");
                rs.Columns.Add("ProductName");
                rs.Columns.Add("Stock_ID");
                rs.Columns.Add("Unit");
                rs.Columns.Add("Quantity", typeof(float));
                rs.Columns.Add("UnitPrice", typeof(float));
                rs.Columns.Add("Charge", typeof(float));
                rs.Columns.Add("DiscountRate", typeof(float));
                rs.Columns.Add("Discount", typeof(float));
                rs.Columns.Add("Amount", typeof(float));

                foreach (var item in results)
                {
                    rs.Rows.Add(item.Outward_ID, item.RefDate, item.Description, item.Product_ID, item.ProductName, item.Stock_ID, item.Unit,
                                item.Quantity, item.UnitPrice, item.Charge, item.DiscountRate, item.Discount, item.Amount);
                }
                return(rs);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
Example #15
0
        public SuaKho(Kho kho2)
        {
            InitializeComponent();

            kho        = kho2;
            tbMa.Text  = kho.MaKho;
            tbTen.Text = kho.TenKho;
        }
        public void xoa1kho(string makho)
        {
            Kho kh = new Kho();

            kh = data.Khos.Where(t => t.IDKho == makho).FirstOrDefault();
            data.Khos.DeleteOnSubmit(kh);
            data.SubmitChanges();
        }
Example #17
0
        public ActionResult DeleteConfirmed(int id)
        {
            Kho kho = db.Khoes.Find(id);

            db.Khoes.Remove(kho);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #18
0
 public bool checkAmount(Kho warehouse, int target)
 {
     if (warehouse.SoLuong < target)
     {
         return(false);
     }
     return(true);
 }
        public Kho UpdateWareHouse(Kho warehouseToUpdate)
        {
            var target = getWareHouse(warehouseToUpdate.MaSP);

            _entities.Entry(target).CurrentValues.SetValues(warehouseToUpdate);
            _entities.SaveChanges();
            return(warehouseToUpdate);
        }
Example #20
0
        public async Task <ResponseData> LayTatCaPhieuNhapKho()
        {
            try
            {
                string url     = string.Format("{0}/api/import/get-all", Config.HOST);
                var    client  = new RestSharp.RestClient(url);
                var    request = new RestSharp.RestRequest(Method.GET);
                request.AddHeader("content-type", "application/json; charset=utf-8");
                request.AddHeader("x-access-token", UserResponse.AccessToken);

                var response = await client.ExecuteTaskAsync(request);

                var responseParse = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(response.Content);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var            data = responseParse["data"];
                    var            listPhieuNhapJson = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(data.ToString());
                    List <NhapKho> listNhapKho       = new List <NhapKho>();
                    foreach (var item in listPhieuNhapJson)
                    {
                        NhapKho nhapKho = Newtonsoft.Json.JsonConvert.DeserializeObject <NhapKho>(item.ToString());
                        Kho     kho     = new Kho()
                        {
                            Id  = item["IdKho"],
                            Ten = item["TenKho"]
                        };
                        NhanVien nhanVien = new NhanVien()
                        {
                            Id  = item["IdNhanVien"],
                            Ten = item["TenNhanVien"]
                        };
                        NhaCungCap nhaCungCap = new NhaCungCap()
                        {
                            Id  = item["IdNhaCungCap"],
                            Ten = item["TenNhaCungCap"]
                        };
                        nhapKho.NhanVien   = nhanVien;
                        nhapKho.Kho        = kho;
                        nhapKho.NhaCungCap = nhaCungCap;
                        listNhapKho.Add(nhapKho);
                    }
                    return(new ResponseData()
                    {
                        Status = Config.CODE_OK,
                        Data = listNhapKho,
                        Message = ""
                    });
                }
                else
                {
                    return(Util.GenerateErrorResponse(response, responseParse));
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #21
0
 public bool ValidatetoWarehouse(Kho warehoustToValidate)
 {
     _validationDictionary.Clear();
     if (warehoustToValidate.SoLuong < 0)
     {
         _validationDictionary.AddError("Soluong", "Vui lòng nhập số lượng hợp lệ");
     }
     return(_validationDictionary.IsValid);
 }
        public void UpdateDS(Kho k)
        {
            Kho capnhat = this.db.Khoes.Single(s => s.MaKho == k.MaKho);
            capnhat.MaKho = k.MaKho;
            capnhat.TenKho = k.TenKho;
            capnhat.ThuKho = k.ThuKho;
            db.SaveChanges();

        }
Example #23
0
 private void UpdateKhoKhacNgay(Kho ct)
 {
     if (db.Khoes.Any(c => c.IdSach == ct.IdSach))
     {
         Kho kho = db.Khoes.OrderByDescending(c => c.IdSach == ct.IdSach).FirstOrDefault();
         ct.SL = kho.SL + ct.SL;
     }
     db.Khoes.Add(ct);
 }
Example #24
0
        private void btnLoadGrid_Click(object sender, EventArgs e)
        {
            int ID_kho         = Convert.ToInt32(ledKhoVT.EditValue);
            int ID_loai_vat_tu = Convert.ToInt32(ledLoaiVT.EditValue);

            gridView1.Columns.Clear();
            gridTonKho.DataSource      = Kho.TonKho(ID_kho, ID_loai_vat_tu);
            gridView1.Columns[0].Width = 120;
        }
Example #25
0
        public void ghiFile(ArrayList arrayList)
        {
            StreamWriter streamWriter = new StreamWriter(path);

            foreach (Kho Kho in arrayList)
            {
                streamWriter.WriteLine(Kho.ToString());
            }
            streamWriter.Close();
        }
Example #26
0
 public ActionResult Edit([Bind(Include = "Id,TenKho")] Kho kho)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kho).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(kho));
 }
Example #27
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     txtMaKho.Text  = UtilitiesService.AutoGenarateCode(Config.P_KHO);
     txtTenKho.Text = "";
     txtDiaChi.Text = "";
     txtGhiChu.Text = "";
     txtSDT.Text    = "";
     cboQuanLy.Text = "";
     txtIdKho.Text  = "";
     currentKho     = new Kho();
 }
Example #28
0
 public ActionResult Edit([Bind(Include = "NgayGhi,IdSach,SL")] Kho kho)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kho).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdSach = new SelectList(db.Saches, "IdSach", "TenSach", kho.IdSach);
     return(View(kho));
 }
Example #29
0
 public async Task <ActionResult <KhoDTO> > Add(Kho kho)
 {
     try
     {
         return(await repo.AddKho(kho));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #30
0
 private void UpdateKho(Kho ct)
 {
     if (db.Khoes.Any(c => c.NgayGhi == ct.NgayGhi))
     {
         UpdateKhoCungNgay(ct);
     }
     else
     {
         UpdateKhoKhacNgay(ct);
     }
 }
Example #31
0
        public ActionResult Create([Bind(Include = "Id,TenKho")] Kho kho)
        {
            if (ModelState.IsValid)
            {
                db.Khoes.Add(kho);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kho));
        }
Example #32
0
 // Xóa một kho khỏi database
 public static void XoaKho(Kho kho)
 {
     using (MyDatabaseDataContext db = new MyDatabaseDataContext())
     {
         KHO khoDB = (from n in db.KHOs
                      where n.MAKHO == kho.MaKho
                      select n).FirstOrDefault();
         db.KHOs.DeleteOnSubmit(khoDB);
         db.SubmitChanges();
     }
 }
 public void InsertDS(Kho ds)
 {
     this.ms.InsertK(ds);
 }
 public void UpdateDS(Kho ds)
 {
     this.ms.UpdateDS(ds);
 }
        public bool NhapMoi(int MaSP, int Mau, int MaSize, int Soluong, decimal GiaNhap)
        {
            Kho kho = new Kho();
            kho.MaSP = MaSP;
            kho.MaMau = Mau;
            kho.MaSize = MaSize;
            kho.SL = Soluong;
            kho.GiaNhap = GiaNhap;
            kho.GiaBan = 0;
            try
            {
                using (DBGiayDepEntities db = new DBGiayDepEntities())
                {
                    db.Khoes.Add(kho);
                    db.SaveChanges();
                    return true;
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return false;
            }
        }