Пример #1
0
        private void btnLưu_Click(object sender, EventArgs e)
        {
            if (txtMaPX.Text == "" || txtTenNguoiNhan.Text == "" || txtCMND.Text == "")
            {
                MessageBox.Show("Vui lòng điền đủ thông tin phiên xuất kho", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                //luu thong tin phien vao stockout, cap nhat trang thai barcode thanh false(da xuat kho), luu thong tin bang stockoutdetail
                //luu thong tin phien vao stockout
                StockOut so = new StockOut();
                so.StockOutCode  = txtMaPX.Text;
                so.UserID        = txtUser.Text;
                so.DateOut       = DateTime.Parse(dateNgayPX.EditValue.ToString());
                so.RecipientName = txtTenNguoiNhan.Text;
                so.IDCard        = txtCMND.Text;
                so.Company       = txtCongTy.Text;
                so.TotalWeight   = double.Parse(txtTongTrongLuong.Text);
                so.Quantity      = Int32.Parse(txtSoLuong.Text);
                so.Note          = txtGhiChu.Text;
                //Kiem tra trung stockoutcode
                StockOut var = (from s in dc.StockOuts
                                where s.StockOutCode == so.StockOutCode
                                select s).FirstOrDefault();
                if (var == null)
                {
                    dc.StockOuts.InsertOnSubmit(so);
                    dc.SubmitChanges();
                }
                else
                {
                    MessageBox.Show("Mã phiên xuất kho bị trùng lặp", "Thông báo", MessageBoxButtons.OK);
                }

                //cập nhật trang thai barcode thanh false (da xuat kho)
                for (int i = 0; i < gridViewBarcode.RowCount; i++)
                {
                    BarcodeDetail bd = (from c in dc.BarcodeDetails
                                        where c.Barcode == gridViewBarcode.GetRowCellValue(i, "Barcode").ToString()
                                        select c).FirstOrDefault();
                    if (bd != null)
                    {
                        bd.Status = false;
                        dc.SubmitChanges();
                    }
                }
                //luu thong tin stockout detail
                for (int i = 0; i < gridViewBarcode.RowCount; i++)
                {
                    StockOutDetail sod = new StockOutDetail();
                    sod.StockOutCode = txtMaPX.Text;
                    sod.Barcode      = gridViewBarcode.GetRowCellValue(i, "Barcode").ToString();
                    dc.StockOutDetails.InsertOnSubmit(sod);
                    dc.SubmitChanges();
                }
                MessageBox.Show("Lưu phiên xuất kho thành công", "Thông báo", MessageBoxButtons.OK);
            }
        }
Пример #2
0
        private void btnLưu_Click(object sender, EventArgs e)
        {
            // luu thong tin phien, trang thai barcode chuyen sang chua nhap kho
            if (txtMaPN.Text == "" || txtMaNV.Text == "")
            {
                MessageBox.Show("Vui lòng điền đủ thông tin phiên nhập kho", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                //luu thong tin phien vao stockin va tao barcode trang thai chua nhap kho va luu thong tin bang stockindetail
                //luu thong tin phien vao stockin
                StockIn si = new StockIn();
                si.StockInCode  = txtMaPN.Text;
                si.UserID       = txtUser.Text;
                si.EmployeeCode = txtMaNV.Text;
                si.DateIn       = DateTime.Parse(datePN.EditValue.ToString());
                si.Note         = txtGhiChuPhien.Text;
                si.TotalWeight  = double.Parse(txtTongTrongLuong.Text);
                si.Quantity     = Int32.Parse(txtSoLuong.Text);
                //Kiem tra trung stockincode
                StockIn var = (from s in dc.StockIns
                               where s.StockInCode == si.StockInCode
                               select s).FirstOrDefault();
                if (var == null)
                {
                    dc.StockIns.InsertOnSubmit(si);
                    dc.SubmitChanges();
                }
                else
                {
                    MessageBox.Show("Mã phiên nhập kho bị trùng lặp", "Thông báo", MessageBoxButtons.OK);
                }
                //luu thong tin barcode

                for (int i = 0; i < gridViewBarcode.RowCount; i++)
                {
                    BarcodeDetail bar = new BarcodeDetail();
                    bar.Barcode     = gridViewBarcode.GetRowCellValue(i, "Barcode").ToString();
                    bar.WasteCode   = gridViewBarcode.GetRowCellValue(i, "TenRac").ToString();
                    bar.FactoryCode = gridViewBarcode.GetRowCellValue(i, "Xuong").ToString();
                    bar.StorageCode = gridViewBarcode.GetRowCellValue(i, "Kho").ToString();
                    bar.Weigh       = double.Parse(gridViewBarcode.GetRowCellValue(i, "TrongLuong").ToString());
                    bar.Status      = true;
                    bar.Note        = gridViewBarcode.GetRowCellValue(i, "GhiChu").ToString();

                    //kiem tra trung barcode
                    BarcodeDetail barcode = (from s in dc.BarcodeDetails
                                             where s.Barcode == bar.Barcode
                                             select s).FirstOrDefault();
                    if (var == null)
                    {
                        dc.BarcodeDetails.InsertOnSubmit(bar);
                        dc.SubmitChanges();
                    }
                    else
                    {
                        MessageBox.Show("Mã barcode bị trùng lặp", "Thông báo", MessageBoxButtons.OK);
                    }
                }

                //Luu thong tin stockindetail

                for (int i = 0; i < gridViewBarcode.RowCount; i++)
                {
                    StockInDetail sid = new StockInDetail();
                    sid.StockInCode = txtMaPN.Text;
                    sid.Barcode     = gridViewBarcode.GetRowCellValue(i, "Barcode").ToString();
                    sid.Note        = txtGhiChuPhien.Text;
                    dc.StockInDetails.InsertOnSubmit(sid);
                    dc.SubmitChanges();
                }
                MessageBox.Show("Lưu phien nhập thành công", "Thông báo", MessageBoxButtons.OK);
            }
        }
Пример #3
0
 private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e)
 {
     //neu nut an la enter
     if (e.KeyChar == (char)13)
     {
         lblMessageBarcode.Text = "";
         //neu dang o trang thai scan
         if (rbtnScan.Checked == true && rbtnHuy.Checked == false)
         {
             //kiem tra luoi rong
             if (gridViewBarcode.RowCount == 0)
             {
                 //kiem tra xem barcode da co trong bang barcode detail chua va trang thai la true(da nhap kho)
                 BarcodeDetail item1 = (from c in dc.BarcodeDetails where c.Barcode == txtBarcode.Text && c.Status == true select c).SingleOrDefault();
                 if (item1 == null)
                 {
                     //neu co thong bao la barcode chua ton tai va o scan hien do(that bai)
                     lblMessageBarcode.Text = "Barcode " + txtBarcode.Text + " không tồn tại";
                     txtBarcode.Text        = "";
                     txtBarcode.Focus();
                     txtBarcode.BackColor = Color.Red;
                 }
                 else
                 {
                     //neu luoi rong
                     ScanBarcode();
                 }
             }
             else
             {
                 //kiem tra xem barcode da co trong bang barcode detail chua va trang thai la true(da nhap kho)
                 BarcodeDetail item = (from c in dc.BarcodeDetails where c.Barcode == txtBarcode.Text && c.Status == true select c).SingleOrDefault();
                 if (item == null)
                 {
                     //neu co thong bao la barcode chua ton tai va o scan hien do(that bai)
                     lblMessageBarcode.Text = "Barcode " + txtBarcode.Text + " không tồn tại";
                     txtBarcode.Text        = "";
                     txtBarcode.Focus();
                     txtBarcode.BackColor = Color.Red;
                 }
                 else
                 {
                     //neu barcode da co trong bang barcode detail va trang thai la true(da nhap kho)
                     //kiem tra xem barcode vua scan da xuat hien trong luoi chua
                     int count = 0;
                     for (int i = 0; i < gridViewBarcode.RowCount; i++)
                     {
                         if (gridViewBarcode.GetRowCellValue(i, "Barcode").ToString() == txtBarcode.Text)
                         {
                             count = count + 1; break;
                         }
                     }
                     if (count > 0)
                     {
                         //neu co thong bao la barcode da duoc xuat hien trong luoi va o scan hien vang(canh bao)
                         lblMessageBarcode.Text = "Barcode " + txtBarcode.Text + " đã được scan";
                         txtBarcode.Text        = "";
                         txtBarcode.Focus();
                         txtBarcode.BackColor = Color.Yellow;
                     }
                     else
                     {
                         //add barcode xuong luoi
                         ScanBarcode();
                     }
                 }
             }
         }
         //new dang o trang thai scan huy
         else if (rbtnScan.Checked == false && rbtnHuy.Checked == true)
         {
             //kiem tra so dong trong luoi
             if (gridViewBarcode.RowCount == 0)
             {
                 MessageBox.Show("Không còn dòng để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 txtBarcode.Text = "";
                 txtBarcode.Focus();
             }
             else
             {
                 //kiem tra xem barcode da ton tai trong luoi chua
                 int dem = 0;
                 for (int i = 0; i < gridViewBarcode.RowCount; i++)
                 {
                     if (txtBarcode.Text == gridViewBarcode.GetRowCellValue(i, "Barcode").ToString())
                     {
                         dem = 0;
                     }
                     else
                     {
                         dem = dem + 1;
                     }
                 }
                 if (dem == gridViewBarcode.RowCount)
                 {
                     lblMessageBarcode.Text = "Barcode " + txtBarcode.Text + " không tồn tại trong lưới";
                     txtBarcode.Text        = "";
                     txtBarcode.Focus();
                     txtBarcode.BackColor = Color.Red;
                 }
                 else
                 {
                     CancelScan(txtBarcode.Text);
                 }
             }
         }
     }
     else
     {
         txtBarcode.Focus();
     }
 }