Example #1
0
        //sửa phiếu nhập hàng
        private bool suaphieunhap()
        {
            PHIEUNHAPHANG entity = new PHIEUNHAPHANG();

            if (txtsuamanv.Text.Trim().Length == 0 || txtsuamanvhientai.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa chọn phiếu nhập hàng để sửa!", "Thông báo");
                return(false);
            }
            else
            {
                if (maphieunhaplbl.Text == madonnhap.ToString())
                {
                    entity.MANHAPHANG = madonnhap;
                }
                else
                {
                    entity.MANHAPHANG = Convert.ToInt32(maphieunhaplbl.Text);
                }
                entity.MANV         = txtsuamanvhientai.Text;
                entity.NGAYNHAPHANG = dateTimePicker4.Value.Date;
                entity.MANHACUNGCAP = cbmancc.SelectedItem.ToString();
                phieunhaphangbus bus     = new phieunhaphangbus();
                bool             success = bus.update(entity);
                common.successorerror(success);
                return(success);
            }
        }
Example #2
0
 public nhaphangdto(PHIEUNHAPHANG entity)
 {
     manhaphang   = entity.MANHAPHANG;
     ngaynhaphang = entity.NGAYNHAPHANG;
     nhacungcap   = entity.NHACUNGCAP.TENNHACUNGCAP;
     tennhanvien  = entity.NHANVIEN.TENNV;
 }
Example #3
0
        private void btn_Them_Click(object sender, EventArgs e)
        {
            //kiểm tra rỗng
            if (txt_manhaphang.Text == "" || txt_manv.Text == "" || ed_ngaynhap.Text == "")
            {
                MessageBox.Show("Không được để trống");
                return;
            }
            //kiểm tra trùng
            PHIEUNHAPHANG nh = new PHIEUNHAPHANG();
            var           kt = from s in ql.PHIEUNHAPHANGs where s.MANH == txt_manhaphang.Text select s;

            if (kt.Count() > 0)
            {
                MessageBox.Show("Trùng khóa chính");
                return;
            }
            nh.MANH            = txt_manhaphang.Text;
            nh.MANV            = txt_manv.Text;
            nh.MADH            = cbo_madh.Text;
            nh.NGAYNHAPHANG    = Convert.ToDateTime(ed_ngaynhap.Text);
            nh.TONGSOLUONGNHAP = 0;
            nh.TONGTIENNHAP    = 0;
            ql.PHIEUNHAPHANGs.InsertOnSubmit(nh);
            ql.SubmitChanges();
            //frm_phieunhaphang_Load(sender, e);
            //this.cT_PHIEUNHAPHANG1TableAdapter.Fill(this.fPT_SHOPDataSet.CT_PHIEUNHAPHANG1, phieuNhapDataGridView.CurrentRow.Cells[0].Value.ToString());
            frm_NhapHang_Load(sender, e);
            MessageBox.Show("Thành công");
            //txt_manhaphang.Text = "" || txt_manv.Text = "" || txt_madathang.Text = "" || txt_mancc.Text = "" || ed_ngaynhap.Text = "" || txt_soluong.Text = "" || txt_tongtien.Text = "";
        }
        public JsonResult CreatePhieuNhap(PHIEUNHAPHANG entity)
        {
            var dao = new NhapHangDAO();
            var pn  = dao.InsertPhieuNhapHang(entity);

            return(Json(new { msg = pn }, JsonRequestBehavior.AllowGet));
        }
 public bool delete(PHIEUNHAPHANG entity)
 {
     if (admin.phanquyen)
     {
         return(phieunhaphangrepository.Delete(entity));
     }
     return(false);
 }
 public bool update(PHIEUNHAPHANG entity)
 {
     if (validate(entity))
     {
         return(phieunhaphangrepository.Attach(entity));
     }
     return(false);
 }
Example #7
0
        //xóa phiếu nhập hàng
        private void xoaphieunhaphang(int manhaphang)
        {
            phieunhaphangbus bus    = new phieunhaphangbus();
            PHIEUNHAPHANG    entity = new PHIEUNHAPHANG();

            entity.MANHAPHANG = manhaphang;
            common.successorerror(bus.delete(entity));
        }
 public bool validate(PHIEUNHAPHANG entity)
 {
     if (entity.MANV.Trim().Length == 0 || Regex.IsMatch(entity.MANV, @"^[a-zA-Z]+$"))
     {
         validatedictionary.Add("MANV", "Không được để trống nhân viên");
     }
     if (validatedictionary.Count() <= 0)
     {
         return(true);
     }
     return(false);
 }
 public int Luu_phieunhaphang(PHIEUNHAPHANG _pHIEUNHAPHANG)
 {
     try
     {
         qa.PHIEUNHAPHANGs.InsertOnSubmit(_pHIEUNHAPHANG);
         qa.SubmitChanges();
         return(1);
     }
     catch
     {
         return(0);
     }
 }
Example #10
0
 public long InsertNhap(PHIEUNHAPHANG pn)
 {
     try
     {
         var kq = db.PHIEUNHAPHANGs.Add(pn);
         db.SaveChanges();
         return(pn.PHIEUNHAPHANG_ID);
     }
     catch
     {
         return(-1);
     }
 }
Example #11
0
        private void simpleButtonChiTiet_Click(object sender, EventArgs e)
        {
            // check the gridview is valid
            if (this.gridViewDanhSachPhieuNhapHang.SelectedRowsCount < 0 || this.gridViewDanhSachPhieuNhapHang.SelectedRowsCount > 1 || this.gridViewDanhSachPhieuNhapHang.DataRowCount == 0)
            {
                return;
            }
            PHIEUNHAPHANG selectedImportReceipt = (PHIEUNHAPHANG)this.gridViewDanhSachPhieuNhapHang.GetRow(this.gridViewDanhSachPhieuNhapHang.FocusedRowHandle);
            // start the form
            PhieuNhapHang_Form viewImportDetailForm = new PhieuNhapHang_Form(ActionType.ACTION_VIEW, selectedImportReceipt);

            // show form
            viewImportDetailForm.ShowDialog();
        }
Example #12
0
        public JsonResult InsertBill(string list)
        {
            var jsonCart = new JavaScriptSerializer().Deserialize <List <ProductViewModel> >(list);

            sortby(ref jsonCart);
            int i, k = 0;
            var tmp = jsonCart[0];

            for (i = 0; i < countncc(jsonCart); i++)
            {
                var l = new List <ProductViewModel>();
                for (int j = k; j < jsonCart.Count; j++)
                {
                    if (tmp.IdNCC == jsonCart[j].IdNCC)
                    {
                        l.Add(jsonCart[j]);
                    }
                    else
                    {
                        k   = j;
                        tmp = jsonCart[j];
                        break;
                    }
                }

                var pn = new PHIEUNHAPHANG();
                pn.TRANGTHAINHAPHANG = 0;
                var id = new NhapHangDAO().InsertNhap(pn);

                if (id > 0)
                {
                    foreach (var item in l)
                    {
                        var model = new DetailNhapModel();
                        model.idNCC     = item.IdNCC;
                        model.idNhap    = id;
                        model.idProduct = item.Id;
                        model.SoLuong   = item.SoLuong;
                        model.Price     = item.Price;
                        var kq = new NhapHangDAO().InsertDetailNhap(model);
                    }
                    Export(id);
                }
            }
            return(Json(new
            {
                status = true,
            }, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        public ActionResult EditPhieuNhapHang(PHIEUNHAPHANG pn)
        {
            if (ModelState.IsValid)
            {
                var dao = new NhapHangDAO();

                //var id = dao.UpdatePhieuNhapHang(pn);
                //if (id)
                //{
                //    SetAlert("Sửa thành công", "success");
                //    return RedirectToAction("QLPhieuNhapHang", "NhapHang");
                //}
                //else
                //{
                //    SetAlert("Sửa không thành công", "warning");
                //    ModelState.AddModelError("", "Cập nhật không thành Công!");
                //}
            }
            return(View("QLPhieuNhapHang"));
        }
        //nhập phiếu nhập hàng
        private void button1_Click(object sender, EventArgs e)
        {
            PHIEUNHAPHANG entity = new PHIEUNHAPHANG();

            entity.MANHACUNGCAP = manhacungcapcb.SelectedItem.ToString();
            entity.NGAYNHAPHANG = dateTimePicker1.Value.Date;
            entity.MANV         = manvtxt.Text;

            phieunhaphangbus bus     = new phieunhaphangbus();
            bool             success = bus.add(entity);

            common.successorerror(success);
            //hiện panel để nhập chi tiết đơn hàng của phiếu nhập hàng
            if (success)
            {
                madonnhap              = bus.getcurrentid();
                madonnhaplbl.Text      = madonnhap.ToString();
                nhapchitietdon.Visible = true;
                panel1.Visible         = false;
            }
        }
Example #15
0
 public decimal InsertPhieuNhapHang(PHIEUNHAPHANG pn)
 {
     db.PHIEUNHAPHANGs.Add(pn);
     db.SaveChanges();
     return(pn.PHIEUNHAPHANG_ID);
 }
Example #16
0
        private void groupControl1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 1)
            {
                PHIEUNHAPHANG pn = new PHIEUNHAPHANG();

                pn.MAPN         = txtmaphieunhap.Text;
                pn.MADH         = txtmaphieudat.Text;
                pn.MANV         = _message;
                pn.NGAYGIAOHANG = DateTime.Parse(cmbngaylap.Text);
                pn.TONGTIEN     = decimal.Parse(txtthanhtien.Text);
                pn.TINHTRANG    = false;
                BH.PHIEUNHAPHANGs.InsertOnSubmit(pn);
                BH.SubmitChanges();

                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    CHITIET_PHIEUNHAP ctpn = new CHITIET_PHIEUNHAP();
                    SANPHAM           sp   = new SANPHAM();
                    DONDATHANG        dh   = new DONDATHANG();
                    ctpn.MAPN      = txtmaphieunhap.Text;
                    ctpn.MA_CT_DH  = dataGridView1.Rows[j].Cells[5].Value.ToString();
                    ctpn.SOLUONG   = decimal.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    ctpn.DONGIA    = decimal.Parse(dataGridView1.Rows[j].Cells[3].Value.ToString());
                    ctpn.THANHTIEN = decimal.Parse(dataGridView1.Rows[j].Cells[4].Value.ToString());
                    //cập nhật sản phẩm
                    int sl = (from slhanghoa in BH.SANPHAMs

                              where slhanghoa.MASP == dataGridView1.Rows[j].Cells[6].Value.ToString()
                              select
                              slhanghoa.SOLUONG).FirstOrDefault();
                    int soln      = int.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    int slcapnhat = sl + soln;
                    sp         = BH.SANPHAMs.Where(s => s.MASP == dataGridView1.Rows[j].Cells[6].Value.ToString()).Single();
                    sp.SOLUONG = slcapnhat;

                    //kiểm tra số lượng nhập
                    // dem dong
                    int sum;
                    int count = (from nhaphang in BH.CHITIET_PHIEUNHAPs
                                 where nhaphang.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                                 select
                                 nhaphang.SOLUONG
                                 ).Count();
                    if (count == 0)
                    {
                        sum = 0;
                    }
                    else
                    {
                        //tổng số lượng các lần nhập hàng
                        sum = (int)(from nhaphang in BH.CHITIET_PHIEUNHAPs
                                    where nhaphang.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                                    select
                                    nhaphang.SOLUONG
                                    ).Sum();
                    }

                    // tổng nhập
                    int tongnhap = sum + int.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    //số lượng chi tiết đơn đặt hàng
                    var sl1 = (from slhanghoa1 in BH.CT_DONDHs

                               where slhanghoa1.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                               select
                               slhanghoa1.SOLUONG).FirstOrDefault();
                    if (tongnhap > int.Parse(sl1.ToString()))
                    {
                        XtraMessageBox.Show("Số lượng nhập quá lớn", "Thông báo");
                    }
                    else
                    {
                        if (tongnhap == int.Parse(sl1.ToString()))
                        {
                            // cap nhat tinh trang
                            dh           = BH.DONDATHANGs.Where(s => s.MADH == txtmaphieudat.Text).Single();
                            dh.TINHTRANG = true;
                        }
                        else
                        {
                            dh.TINHTRANG = false;
                        }

                        BH.CHITIET_PHIEUNHAPs.InsertOnSubmit(ctpn);
                        BH.SubmitChanges();
                        XtraMessageBox.Show("Lưu thành công");
                    }
                }
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 2)
            {
                dataGridView1.DataSource = null;

                // Bind with the new data.
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.ColumnCount         = 7;

                dataGridView1.Columns[0].Name = "Mã phiếu nhập";
                dataGridView1.Columns[1].Name = "Sản phẩm";
                dataGridView1.Columns[2].Name = "Số lượng";
                dataGridView1.Columns[3].Name = "Đơn giá";
                dataGridView1.Columns[4].Name = "Thành tiền";
                dataGridView1.Columns[5].Name = "Mã CT";
                dataGridView1.Columns[6].Name = "Mã sản phẩm";
                bool   kt      = true;
                var    v3Value = cmbsanpham.Properties.GetDataSourceValue("MASP", cmbsanpham.ItemIndex);
                string value   = (from tennv in BH.CT_DONDHs
                                  join sp in BH.SANPHAMs on tennv.MASP equals sp.MASP
                                  join ddh in BH.DONDATHANGs on tennv.MADH equals ddh.MADH
                                  where tennv.MASP == v3Value.ToString() && tennv.MADH == txtmaphieudat.Text
                                  select
                                  tennv.MA_CT_DH).FirstOrDefault();
                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    if (value == dataGridView1.Rows[j].Cells[5].Value.ToString())
                    {
                        int slcong = Int32.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                        slcong = slcong + int.Parse(txtsoluong.Text);
                        dataGridView1.Rows[j].Cells[2].Value = slcong;
                        double thanhtien = 0;
                        thanhtien = (slcong * double.Parse(dataGridView1.Rows[j].Cells[3].Value.ToString()));
                        dataGridView1.Rows[j].Cells[4].Value = thanhtien;
                        kt = false;
                        break;
                    }
                }
                if (kt)
                {
                    int row = 0;
                    dataGridView1.Rows.Add();
                    row = dataGridView1.Rows.Count - 1;

                    dataGridView1.Rows[row].Cells[0].Value = txtmaphieunhap.Text;

                    dataGridView1.Rows[row].Cells[1].Value = cmbsanpham.Text;

                    dataGridView1.Rows[row].Cells[2].Value = txtsoluong.Text;

                    dataGridView1.Rows[row].Cells[3].Value = txtdongia.Text;

                    double tt = int.Parse(dataGridView1.Rows[row].Cells[2].Value.ToString()) * double.Parse(dataGridView1.Rows[row].Cells[3].Value.ToString());

                    dataGridView1.Rows[row].Cells[4].Value = tt.ToString();
                    dataGridView1.Rows[row].Cells[5].Value = value;
                    dataGridView1.Rows[row].Cells[6].Value = v3Value;
                }
                double i = tinhtongtien();
                txtthanhtien.Text = string.Format("{0:n0}", Double.Parse(i.ToString()));
            }
        }