private void dvgArt_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 5) { string ARTID = Convert.ToString(dvgArt.Rows[e.RowIndex].Cells["ARTID"].Value); string Ten = Convert.ToString(dvgArt.Rows[e.RowIndex].Cells["Ten"].Value); string Mieuta = Convert.ToString(dvgArt.Rows[e.RowIndex].Cells["Mota"].Value); string now = System.DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"); if (!string.IsNullOrEmpty(ARTID)) { string query = "UPDATE ART SET Ten = '" + Ten + "',Mota = '" + Mieuta + "',Ngaytao = '" + now + "',Ngaysua = '" + now + "' WHERE SonID= " + ARTID; bool isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { PopulateData(currentPageNumber, rowPerPage, currentOrderByItem); lblMess.Text = " Ban da sua thanh cong ARTID: " + ARTID; } } } if (e.ColumnIndex == 6) { string ARTID = Convert.ToString(dvgArt.Rows[e.RowIndex].Cells["ARTID"].Value); if (!string.IsNullOrEmpty(ARTID)) { string query = "DELETE FROM ART WHERE ARTID= " + ARTID; bool isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { PopulateData(currentPageNumber, pageSize, currentOrderByItem); lblMess.Text = " Ban da xoa thanh cong ARTID: " + ARTID; } } } }
private void SaveOrderToTransactionDB(string barcode, string LoaiID, string Mota, string soluong, string Nhap, string Xong) { DBModel modelWhere = new DBModel(); bool isSuccess = false; string InsertItemQry; string TransID = CommonHelper.RandomString(8); string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); if (!string.IsNullOrEmpty(barcode)) { InsertItemQry = "INSERT INTO [Transaction]([TransID],[Barcode],[LoaiID],[Mota],[Soluong],[Nhap],[Xong],[Ngaytao],[Ngaysua])VALUES('" + TransID + "','" + barcode + "','" + LoaiID + "','" + Mota + "','" + soluong + "','" + Nhap + "','" + Xong + "','" + createDate + "','" + modifyDate + "')"; //if (DBAccess.IsServerConnected()) //{ if (InsertItemQry.Length > 5) { bool isExisted = DBHelper.CheckItemExist("[Product]", "Barcode", barcode); if (isExisted) { isSuccess = DBAccess.ExecuteQuery(InsertItemQry); } else { CommonHelper.showDialog("Barcode chưa tồn tại!", Color.FromArgb(255, 53, 71)); } } // } } }
private void btnDelete_Click(object sender, EventArgs e) { bool isSuccess = false; if (dvgProduct.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dvgProduct.SelectedRows) { string barcode = row.Cells[0].Value.ToString(); string orderID = row.Cells[0].Value.ToString(); string query = "DELETE FROM Product WHERE Barcode ='" + barcode + "';"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } dvgProduct.Rows.Remove(row); } GetTotalRow(); GetAllDataProduct(1, 50); ClearText(); } else { MessageBox.Show("Mời chọn đơn hàng muốn xóa!"); } }
private void CreateNew() { string query = ""; bool isSuccess = false; string Barcode, Kyhieu, Dai, Rong, ARTID, SonID, DVT, MaSP, Mieuta; Barcode = Kyhieu = Dai = Rong = ARTID = SonID = DVT = MaSP = Mieuta = string.Empty; // Set value for number field if (string.IsNullOrEmpty(txtDai.Text)) { txtDai.Text = "0"; } if (string.IsNullOrEmpty(txtRong.Text)) { txtRong.Text = "0"; } // Barcode if (string.IsNullOrEmpty(txtBarcode.Text)) { Barcode = CommonHelper.RandomString(14); } else { Barcode = txtBarcode.Text; } //Kyhieu Kyhieu = txtKyhieu.Text; Dai = txtDai.Text; Rong = txtRong.Text; ARTID = cbArt.SelectedValue.ToString(); SonID = cbSon.SelectedValue.ToString(); DVT = txtDVT.Text; MaSP = txtMaSP.Text; Mieuta = txtMieuta.Text; // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); query = "Insert into Product([Barcode],[Kyhieu],[Dai],[Rong],[ArtID],[SonID],[DVT],[Mieuta],[Ngaytao],[Ngaysua],[MaSP]) Values ('" + Barcode + "','" + Kyhieu + "','" + Dai + "','" + Rong + "','" + ARTID + "','" + SonID + "','" + DVT + "','" + Mieuta + "','" + createDate + "','" + createDate + "','" + MaSP + "')"; if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { cbSon.SelectedIndex = 0; cbArt.SelectedIndex = 0; currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(); GetAllDataProduct(currentPageNumber, rowPerPage); MessageBox.Show("Đã thêm thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void btnSave_Click(object sender, EventArgs e) { try { string query = ""; bool isSuccess = false; string Barcode, Kyhieu, Dai, Rong, ARTID, SonID, DVT, MaSP, Mieuta; Barcode = Kyhieu = Dai = Rong = ARTID = SonID = DVT = MaSP = Mieuta = string.Empty; // Set value for number field if (string.IsNullOrEmpty(txtDai.Text)) { txtDai.Text = "0"; } if (string.IsNullOrEmpty(txtRong.Text)) { txtRong.Text = "0"; } // Barcode Barcode = txtBarcode.Text; //Kyhieu Kyhieu = txtKyhieu.Text; Dai = txtDai.Text; Rong = txtRong.Text; ARTID = cbArt.SelectedValue.ToString(); SonID = cbSon.SelectedValue.ToString(); DVT = txtDVT.Text; MaSP = txtMaSP.Text; Mieuta = txtMieuta.Text; string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); query = "UPDATE [Product] SET[Kyhieu] ='" + Kyhieu + "',[Dai]= '" + Dai + "',[Rong]= '" + Rong + "',[ARTID]= '" + ARTID + "',[SonID]= '" + SonID + "',[DVT]= '" + DVT + "',[Mieuta]= '" + Mieuta + "',[Ngaysua]= '" + modifyDate + "' WHERE Barcode ='" + Barcode + "';"; if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); } if (isSuccess) { cbSon.SelectedIndex = 0; cbArt.SelectedIndex = 0; currentPageNumber = 1; ClearText(); // Update datalist GetAllDataProduct(currentPageNumber, rowPerPage); MessageBox.Show("Đã cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Đang Hoàn Thiện Hệ Thống!"); } }
private void btnDelete_Click(object sender, EventArgs e) { bool isSuccess = false; try { if (dgvStaff.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dgvStaff.SelectedRows) { Form1 form1 = new Form1(); bool isExisted = DBHelper.CheckItemExist("[Staff]", "Tendangnhap", form1.lblCurrentUser.Text); bool isAmdin = DBHelper.CheckItemExist("[Staff]", "RoleID", "0000001"); if (!isAmdin) { if (!isExisted) { string NhanvienID = row.Cells[0].Value.ToString(); string query = "DELETE FROM[Staff] WHERE NhanvienID = '" + NhanvienID + "'"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } dgvStaff.Rows.Remove(row); } else { MessageBox.Show("Không thể xóa, tên truy cập đang sử dụng!"); } } else { MessageBox.Show("Không thể xóa admin!"); } } GetTotalRow(); GetAllData(1, rowPerPage); ClearText(); } else { MessageBox.Show("Mời chọn dòng muốn xóa!"); } if (isSuccess) { MessageBox.Show("Đã xóa thành công!"); } } catch (Exception ex) { MessageBox.Show("Mời chọn dòng muốn xóa!"); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (dvgArt.DataSource != null) { //DataTable dtItem = (DataTable)(dvgArt.DataSource); string id, name, desc, createDate, modifyDate; string InsertItemQry = ""; int count = 0; var csv = new StringBuilder(); //foreach (DataRow dr in dtItem.Rows) //{ id = txtArtID.Text; name = txtTen.Text; desc = txtMieuta.Text; createDate = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"); modifyDate = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"); if (id != "") { InsertItemQry += "INSERT INTO [ART] (ARTID,Ten,Mota,Anh, Ngaytao,Ngaysua)VALUES('" + id + "','" + name + "','" + desc + "','" + null + "','" + createDate + "','" + modifyDate + "');"; //var newLine = $"{id},{name},{desc},{createDate},{modifyDate}"; //csv.AppendLine(newLine); //count++; } // if (DBAccess.IsServerConnected()) { if (InsertItemQry.Length > 5) { bool isSuccess = DBAccess.ExecuteQuery(InsertItemQry); if (isSuccess) { MessageBox.Show("Thành công, Số sản phẩm đã nhập : " + count + "", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } //else //{ // File.AppendAllText(pathCSV, csv.ToString()); // MessageBox.Show("Thành công, Số sản phẩm đã nhập : " + count + "", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //} // Update datalist PopulateData(currentPageNumber, rowPerPage, currentOrderByItem); } } catch (Exception ex) { MessageBox.Show("Exception " + ex); } }
private void btnDelete_Click(object sender, EventArgs e) { bool isSuccess = false; try { if (dgvSupplier.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dgvSupplier.SelectedRows) { string NhaccID = row.Cells[0].Value.ToString(); bool isExisted = DBHelper.CheckItemExist("[Order]", "NhaccID", NhaccID); if (!isExisted) { string query = "DELETE FROM[Supplier] WHERE NhaccID = '" + NhaccID + "'"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } dgvSupplier.Rows.Remove(row); } else { CommonHelper.showDialog("Nhà cung ứng đang giao dịch!", Color.FromArgb(255, 53, 71)); } } GetTotalRow(); GetAllData(1, rowPerPage); ClearText(); } else { CommonHelper.showDialog("Mời chọn dòng muốn xóa!", Color.FromArgb(255, 187, 51)); } if (isSuccess) { CommonHelper.showDialog("Đã xóa thành công!", Color.FromArgb(4, 132, 75)); } } catch (Exception ex) { CommonHelper.showDialog("Mời chọn dòng muốn xóa!", Color.FromArgb(255, 187, 51)); } }
private void btnXoa_Click(object sender, EventArgs e) { bool isSuccess = false; int count = 0; if (dgvOrder.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dgvOrder.SelectedRows) { if (isEdit) { string orderID = row.Cells[0].Value.ToString(); string query = "DELETE FROM[OrderDetail] WHERE DonhangID = '" + orderID + "'"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } query = "DELETE FROM[Stock] WHERE DonhangID = '" + orderID + "'"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } query = "DELETE FROM [Order] WHERE DonhangID ='" + orderID + "';"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } dgvOrder.Rows.Remove(row); count++; } } GetTotalRow(); GetAllDataOrder(1, 10); ClearText(); CommonHelper.showDialog("Đã xoá thành công " + count + " dòng!", Color.FromArgb(4, 132, 75)); } else { CommonHelper.showDialog("Mời chọn đơn hàng muốn xóa!", Color.FromArgb(255, 187, 51)); } }
public static bool AddIntoStock(string barcode, string donhangID, string createDate, string BTPChuaInID, string BTPDaInID, string TPID, string SPLoiID, string BTPChuaInSL, string BTPDaInSL, string TPSL, string SPLoiSL) { List <string> InsertItemQryList = new List <string>(); string InsertItemQry = ""; bool isSuccess = false; string TonkhoID1 = CommonHelper.RandomString(7) + 1; string TonkhoID2 = CommonHelper.RandomString(7) + 2; string TonkhoID3 = CommonHelper.RandomString(7) + 3; string TonkhoID4 = CommonHelper.RandomString(7) + 4; InsertItemQry = "INSERT INTO [Stock] ([TonkhoID], [DonhangID], [Barcode],[LoaiID],[Soluongcon],[Ngaytao])VALUES('" + TonkhoID1 + "','" + donhangID + "','" + barcode + "','" + BTPChuaInID + "','" + BTPChuaInSL + "','" + createDate + "')"; InsertItemQryList.Add(InsertItemQry); InsertItemQry = "INSERT INTO [Stock] ([TonkhoID],[DonhangID], [Barcode],[LoaiID],[Soluongcon],[Ngaytao])VALUES('" + TonkhoID2 + "','" + donhangID + "','" + barcode + "','" + BTPDaInID + "','" + BTPDaInSL + "','" + createDate + "')"; InsertItemQryList.Add(InsertItemQry); InsertItemQry = "INSERT INTO [Stock] ([TonkhoID],[DonhangID], [Barcode],[LoaiID],[Soluongcon],[Ngaytao])VALUES('" + TonkhoID3 + "','" + donhangID + "','" + barcode + "','" + TPID + "','" + TPSL + "','" + createDate + "')"; InsertItemQryList.Add(InsertItemQry); InsertItemQry = "INSERT INTO [Stock] ([TonkhoID],[DonhangID], [Barcode],[LoaiID],[Soluongcon],[Ngaytao])VALUES('" + TonkhoID4 + "','" + donhangID + "','" + barcode + "','" + SPLoiID + "','" + SPLoiSL + "','" + createDate + "')"; InsertItemQryList.Add(InsertItemQry); //if (DBAccess.IsServerConnected()) //{ if (InsertItemQry.Length > 5) { bool isExisted = DBHelper.CheckItemExist("[Product]", "Barcode", barcode); if (isExisted) { foreach (var item in InsertItemQryList) { isSuccess = DBAccess.ExecuteQuery(item); } } else { CommonHelper.showDialog("Barcode chưa tồn tại!", Color.FromArgb(255, 53, 71)); //MessageBox.Show("Barcode chưa tồn tại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } // } } return(isSuccess); }
private void btnNew_Click(object sender, EventArgs e) { try { string query = ""; bool isSuccess = false; string Ngay, DonhangID, Barcode, Soluong, Ghichu; DonhangID = Barcode = Soluong = Ghichu = string.Empty; DonhangID = CommonHelper.RandomString(8); KHID = cbCustomer.SelectedValue.ToString(); Barcode = cbKyHieu.SelectedValue.ToString(); Soluong = txtSoluong.Text; Ghichu = txtghichu.Text; Ngay = dtpNgay.Value.ToString("MM/dd/yyyy hh:mm:ss tt"); // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); query = "INSERT INTO [CustomerOrder] ([DonhangID],[KHID],[Barcode],[Soluong],[Ghichu],[NgayGD], [Ngaytao],[Ngaysua])VALUES('" + DonhangID + "','" + KHID + "','" + Barcode + "','" + Soluong + "','" + Ghichu + "','" + Ngay + "','" + createDate + "','" + createDate + "')"; if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(KHID); GetAllData(currentPageNumber, rowPerPage, KHID); MessageBox.Show("Cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show("Đang Hoàn Thiện Hệ Thống!"); } }
public static bool UpdateStock(string barcode, string donhangID, string createDate, string BTPChuaInID, string BTPDaInID, string TPID, string SPLoiID, string BTPChuaInSL, string BTPDaInSL, string TPSL, string SPLoiSL) { List <string> UpdateItemQryList = new List <string>(); string UpdateItemQry = ""; bool isSuccess = false; string TonkhoID1 = CommonHelper.RandomString(7) + 1; string TonkhoID2 = CommonHelper.RandomString(7) + 2; string TonkhoID3 = CommonHelper.RandomString(7) + 3; string TonkhoID4 = CommonHelper.RandomString(7) + 4; UpdateItemQry = "UPDATE[Stock] SET [Barcode] = '" + barcode + "',[Soluongcon]= '" + BTPChuaInSL + "',[Ngaytao]= '" + createDate + "' WHERE DonhangID ='" + donhangID + "' AND LoaiID='" + BTPChuaInID + "';"; UpdateItemQryList.Add(UpdateItemQry); UpdateItemQry = "UPDATE[Stock] SET [Barcode] = '" + barcode + "',[Soluongcon]= '" + BTPDaInSL + "',[Ngaytao]= '" + createDate + "' WHERE DonhangID ='" + donhangID + "' AND LoaiID='" + BTPDaInID + "';"; UpdateItemQryList.Add(UpdateItemQry); UpdateItemQry = "UPDATE[Stock] SET [Barcode] = '" + barcode + "',[Soluongcon]= '" + TPSL + "',[Ngaytao]= '" + createDate + "' WHERE DonhangID ='" + donhangID + "' AND LoaiID='" + TPID + "';"; UpdateItemQryList.Add(UpdateItemQry); UpdateItemQry = "UPDATE[Stock] SET [Barcode] = '" + barcode + "',[Soluongcon]= '" + SPLoiSL + "',[Ngaytao]= '" + createDate + "' WHERE DonhangID ='" + donhangID + "' AND LoaiID='" + SPLoiID + "';"; UpdateItemQryList.Add(UpdateItemQry); //if (DBAccess.IsServerConnected()) //{ if (UpdateItemQry.Length > 5) { bool isExisted = DBHelper.CheckItemExist("[Product]", "Barcode", barcode); if (isExisted) { foreach (var item in UpdateItemQryList) { isSuccess = DBAccess.ExecuteQuery(item); } } else { CommonHelper.showDialog("Barcode chưa tồn tại!", Color.FromArgb(255, 53, 71)); //MessageBox.Show("Barcode chưa tồn tại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } // } } return(isSuccess); }
private void btnDelete_Click(object sender, EventArgs e) { string id = txtArtID.Text; if (!string.IsNullOrEmpty(id)) { string query = "DELETE FROM Art WHERE ARTID ='" + id + "';"; if (DBAccess.IsServerConnected()) { if (query.Length > 5) { bool isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { MessageBox.Show("Số sản phẩm đã nhập Thành công: ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } // Update datalist PopulateData(currentPageNumber, rowPerPage, currentOrderByItem); } } } }
private void btnDelete_Click(object sender, EventArgs e) { bool isSuccess = false; try { if (dgvType.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dgvType.SelectedRows) { string loaiID = row.Cells[0].Value.ToString(); string query = "DELETE FROM[Type] WHERE LoaiID = '" + loaiID + "'"; isSuccess = DBAccess.ExecuteQuery(query); if (!isSuccess) { return; } dgvType.Rows.Remove(row); } GetTotalRow(); GetAllData(1, rowPerPage); ClearText(); } else { MessageBox.Show("Mời chọn dòng muốn xóa!"); } if (isSuccess) { MessageBox.Show("Đã xóa thành công!"); } } catch (Exception ex) { MessageBox.Show("Mời chọn dòng muốn xóa!"); } }
private void CreateNew() { List <string> ItemQryList = new List <string>(); bool isSuccess = false; string isNhap = "false"; string itemInStock = string.Empty; string Ngay, Ngayxong, DonhangID, barcode, kihieu, KHID, BTPChuaInID, BTPDaInID, TPID, SPLoiID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, GhiChu; kihieu = Ngay = Ngayxong = DonhangID = barcode = KHID = BTPChuaInID = BTPDaInID = TPID = SPLoiID = BTPChuaInSL = BTPDaInSL = TPSL = SPLoiSL = GhiChu = string.Empty; // Set value for number field if (string.IsNullOrEmpty(txtBTPChuaIn.Text)) { txtBTPChuaIn.Text = "0"; } if (string.IsNullOrEmpty(txtBTPDaIn.Text)) { txtBTPDaIn.Text = "0"; } if (string.IsNullOrEmpty(txtTP.Text)) { txtTP.Text = "0"; } if (string.IsNullOrEmpty(txtSPLoi.Text)) { txtSPLoi.Text = "0"; } if (DBHelper.checkValidField(txtBTPChuaIn.Text) && DBHelper.checkValidField(txtBTPDaIn.Text) && DBHelper.checkValidField(txtTP.Text) && DBHelper.checkValidField(txtSPLoi.Text)) { CommonHelper.showDialog("Mời nhập số lượng sản phẩm!", Color.FromArgb(255, 187, 51)); } else { // DonhangID DonhangID = CommonHelper.RandomString(8); // Customer KHID = cbCustomer.SelectedValue.ToString(); // Ngay nhap kho Ngayxong = dtpNgayXuat.Value.ToString("MM/dd/yyyy hh:mm:ss tt"); // Ngay xong // Barcode barcode = cbKyHieu.SelectedValue.ToString(); GhiChu = txtghichu.Text; kihieu = DBHelper.Lookup("Product", "Kyhieu", "barcode", barcode); // BTPChuaIn BTPChuaInID = DBHelper.Lookup("Type", "LoaiID", "Ten", "BTP Chưa in"); BTPChuaInSL = txtBTPChuaIn.Text; // BTPDaIn BTPDaInID = DBHelper.Lookup("Type", "LoaiID", "Ten", "BTP Đã in"); BTPDaInSL = txtBTPDaIn.Text; // TP TPID = DBHelper.Lookup("Type", "LoaiID", "Ten", "Thành Phẩm"); TPSL = txtTP.Text; // SPLoi SPLoiID = DBHelper.Lookup("Type", "LoaiID", "Ten", "Sản phẩm lỗi"); SPLoiSL = txtSPLoi.Text; // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); itemInStock = DBHelper.getStock(kihieu, DonhangID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, dtpNgayXuat.Value.ToString("dd/MM/yyyy")); if (string.IsNullOrEmpty(itemInStock)) { ItemQryList = AddNewOrder(Ngay, Ngayxong, DonhangID, KHID, barcode, "true", createDate, BTPChuaInID, BTPDaInID, TPID, SPLoiID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, GhiChu); if (DBAccess.IsServerConnected()) { if (ItemQryList.Count > 0) { foreach (var item in ItemQryList) { isSuccess = DBAccess.ExecuteQuery(item); } if (isSuccess) { SaveOrderToTransactionDB(barcode, BTPChuaInID, "", BTPChuaInSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, BTPDaInID, "", BTPDaInSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, TPID, "", TPSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, SPLoiID, "", SPLoiSL, isNhap, "true"); bool isAddedStock = DBHelper.AddIntoStock(barcode, DonhangID, Ngayxong, BTPChuaInID, BTPDaInID, TPID, SPLoiID, "-" + BTPChuaInSL, "-" + BTPDaInSL, "-" + TPSL, "-" + SPLoiSL); if (isAddedStock) { cbCustomer.SelectedIndex = 0; currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(); GetAllDataOrder(currentPageNumber, rowPerPage); CommonHelper.showDialog("Đã thêm thành công!", Color.FromArgb(4, 132, 75)); } } } } } else { CommonHelper.showDialog(itemInStock, Color.FromArgb(255, 187, 51)); } } }
private void btnImport_Click(object sender, EventArgs e) { string Barcode, Kyhieu, MaSP, Dai, Rong, ARTID, SonID, DVT, Mieuta, ngaytao, ngaysua; Barcode = Kyhieu = MaSP = Dai = Rong = ARTID = SonID = DVT = Mieuta = ngaytao = ngaysua = string.Empty; try { using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xlsx|Excel Workbook 97-2003|*.xls", ValidateNames = true }) { if (ofd.ShowDialog() == DialogResult.OK) { using (var stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)) { IExcelDataReader reader; if (ofd.FilterIndex == 2) { reader = ExcelReaderFactory.CreateBinaryReader(stream); } else { reader = ExcelReaderFactory.CreateOpenXmlReader(stream); } DataSet ds = reader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true } }); string InsertItemQry = ""; int count = 0; System.Data.DataTable dt = ds.Tables[0]; string[] columnNames = dt.Columns.Cast <DataColumn>() .Select(x => x.ColumnName) .ToArray(); for (int i = 7; i < dt.Rows.Count; i++) { //BarcodeWriter writer = new BarcodeWriter() { Format = BarcodeFormat.CODE_128 }; //pictureBox1.Image = writer.Write(textBox1.Text); //Barcode = BarcodeFormat.CODE_128; string now = DateTime.Now.ToString("ddmmyyyhhmmssff"); GeneratedBarcode newbarcode = BarcodeWriter.CreateBarcode(now, BarcodeWriterEncoding.Code128); Barcode = newbarcode.ToString(); Kyhieu = Convert.ToString(dt.Rows[i][1]).Trim(); MaSP = Convert.ToString(dt.Rows[i][2]).Trim(); Dai = Convert.ToString(dt.Rows[i][3]).Trim(); Rong = Convert.ToString(dt.Rows[i][4]).Trim(); ARTID = DBHelper.Lookup("ART", "ARTID", "Ten", Convert.ToString(dt.Rows[i][5]).Trim('\'').Trim()); if (string.IsNullOrEmpty(ARTID)) { MessageBox.Show(Convert.ToString(dt.Rows[i][5]).Trim('\'')); } SonID = DBHelper.Lookup("Color", "SonID", "Ten", Convert.ToString(dt.Rows[i][6]).Trim('\'').Trim()); if (string.IsNullOrEmpty(SonID)) { MessageBox.Show(Convert.ToString(dt.Rows[i][6]).Trim('\'')); } DVT = Convert.ToString(dt.Rows[i][8]).Trim(); Mieuta = string.Empty; ngaytao = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); ngaysua = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); if (Kyhieu != string.Empty) { InsertItemQry = "Insert into Product([Barcode],[Kyhieu],[Dai],[Rong],[ArtID],[SonID],[DVT],[Mieuta],[Ngaytao],[Ngaysua],[MaSP]) Values ('" + Barcode + "','" + Kyhieu + "','" + Dai + "','" + Rong + "','" + ARTID + "','" + SonID + "','" + DVT + "','" + "" + "','" + ngaysua + "','" + ngaytao + "','" + MaSP + "')"; if (DBAccess.IsServerConnected()) { if (InsertItemQry.Length > 5) { isSuccess = DBAccess.ExecuteQuery(InsertItemQry); } } if (isSuccess) { count++; } else { MessageBox.Show(InsertItemQry); } } else { GetTotalRow(); GetAllDataProduct(1, 50); MessageBox.Show("Import " + count + " dòng thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (isSuccess) { MessageBox.Show("Import " + count + " dòng thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Import dòng " + count + " không thành công!Kyhieu = " + Kyhieu, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } catch (Exception ex) { MessageBox.Show("File không đúng format! Format Đúng: Dữ liệu bắt đầu từ dòng 7, cột 1: Ký Hiệu, cột 2: Mã SP, cột 3: Dài, cột 4: Rộng, cột 5: ART, cột 6: SON, cột 8:DVT "); } }
private void btnSave_Click(object sender, EventArgs e) { try { List <string> ItemQryList = new List <string>(); string ngayxong = string.Empty; bool isSuccess = false; string isNhap = "false"; string itemInStock = string.Empty; string Ngay, kihieu, DonhangID, barcode, KHID, BTPChuaInID, BTPDaInID, TPID, SPLoiID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, GhiChu; Ngay = DonhangID = barcode = KHID = BTPChuaInID = BTPDaInID = TPID = SPLoiID = BTPChuaInSL = BTPDaInSL = TPSL = SPLoiSL = GhiChu = string.Empty; // Set value for number field if (string.IsNullOrEmpty(txtBTPChuaIn.Text)) { txtBTPChuaIn.Text = "0"; } if (string.IsNullOrEmpty(txtBTPDaIn.Text)) { txtBTPDaIn.Text = "0"; } if (string.IsNullOrEmpty(txtTP.Text)) { txtTP.Text = "0"; } if (string.IsNullOrEmpty(txtSPLoi.Text)) { txtSPLoi.Text = "0"; } if (!string.IsNullOrEmpty(txtOrder.Text)) { if (DBHelper.checkValidField(txtBTPChuaIn.Text) && DBHelper.checkValidField(txtBTPDaIn.Text) && DBHelper.checkValidField(txtTP.Text) && DBHelper.checkValidField(txtSPLoi.Text)) { CommonHelper.showDialog("Mời nhập số lượng sản phẩm!", Color.FromArgb(255, 187, 51)); } else { DonhangID = txtOrder.Text; string ngaysua = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); // NhaccID KHID = cbCustomer.SelectedValue.ToString(); // Ngay nhap ngaysua = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); // Ngay xong ngayxong = dtpNgayXuat.Value.ToString("MM/dd/yyyy hh:mm:ss tt"); // Barcode barcode = cbKyHieu.SelectedValue.ToString(); GhiChu = txtghichu.Text; kihieu = DBHelper.Lookup("Product", "Kyhieu", "barcode", barcode); // BTPChuaIn BTPChuaInID = DBHelper.Lookup("Type", "LoaiID", "Ten", "BTP Chưa in"); BTPChuaInSL = txtBTPChuaIn.Text; // BTPDaIn BTPDaInID = DBHelper.Lookup("Type", "LoaiID", "Ten", "BTP Đã in"); BTPDaInSL = txtBTPDaIn.Text; // TP TPID = DBHelper.Lookup("Type", "LoaiID", "Ten", "Thành Phẩm"); TPSL = txtTP.Text; // SPLoi SPLoiID = DBHelper.Lookup("Type", "LoaiID", "Ten", "Sản phẩm lỗi"); SPLoiSL = txtSPLoi.Text; itemInStock = DBHelper.getStock(kihieu, DonhangID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, dtpNgayXuat.Value.ToString("dd/MM/yyyy")); if (string.IsNullOrEmpty(itemInStock)) { ItemQryList = UpdateOrder(DonhangID, barcode, KHID, ngayxong, ngaysua, BTPChuaInID, BTPDaInID, TPID, SPLoiID, BTPChuaInSL, BTPDaInSL, TPSL, SPLoiSL, "true", GhiChu); if (DBAccess.IsServerConnected()) { if (ItemQryList.Count > 0) { foreach (var item in ItemQryList) { isSuccess = DBAccess.ExecuteQuery(item); } if (isSuccess) { SaveOrderToTransactionDB(barcode, BTPChuaInID, "", BTPChuaInSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, BTPDaInID, "", BTPDaInSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, TPID, "", TPSL, isNhap, "true"); SaveOrderToTransactionDB(barcode, SPLoiID, "", SPLoiSL, isNhap, "true"); bool isUpdatededStock = DBHelper.UpdateStock(barcode, DonhangID, ngayxong, BTPChuaInID, BTPDaInID, TPID, SPLoiID, "-" + BTPChuaInSL, "-" + BTPDaInSL, "-" + TPSL, "-" + SPLoiSL); if (isUpdatededStock) { cbCustomer.SelectedIndex = 0; currentPageNumber = 1; ClearText(); // Update datalist GetAllDataOrder(currentPageNumber, rowPerPage); CommonHelper.showDialog("Đã cập nhật thành công!", Color.FromArgb(4, 132, 75)); } } } } } else { CommonHelper.showDialog(itemInStock, Color.FromArgb(255, 187, 51)); } } } } catch (Exception ex) { CommonHelper.showDialog("Đang Hoàn Thiện Hệ Thống!", Color.FromArgb(255, 53, 71)); } }
private void btnSave_Click(object sender, EventArgs e) { try { string query = ""; bool isSuccess = false; string ngayxong = string.Empty; string TypeID, Ten, Mota; TypeID = Ten = Mota = string.Empty; if (string.IsNullOrEmpty(txtTypeID.Text)) { // TypeID TypeID = CommonHelper.RandomString(8); // Ten Ten = txtName.Text; // Mota Mota = txtMota.Text; // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); query = "INSERT INTO [Type] ([LoaiID],[Ten],[Mieuta],[Ngaytao],[Ngaysua])VALUES('" + TypeID + "','" + Ten + "','" + Mota + "','" + createDate + "','" + createDate + "')"; } else { TypeID = txtTypeID.Text; string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); // Ten Ten = txtName.Text; // Mota Mota = txtMota.Text; query = "UPDATE [Type] SET[Ten] ='" + Ten + "',[Mieuta]= '" + Mota + "',[Ngaysua]= '" + modifyDate + "' WHERE LoaiID ='" + TypeID + "';"; } if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { if (string.IsNullOrEmpty(txtTypeID.Text)) { currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(); GetAllData(currentPageNumber, rowPerPage); } else { currentPageNumber = 1; ClearText(); // Update datalist GetAllData(currentPageNumber, rowPerPage); } MessageBox.Show("Cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show("Đang Hoàn Thiện Hệ Thống!"); } }
private void btnSave_Click(object sender, EventArgs e) { try { string query = ""; bool isSuccess = false; string NhaccID, Name, Mota, Address, Sodt, Email; NhaccID = Name = Mota = Address = Sodt = Email = string.Empty; if (string.IsNullOrEmpty(txtNhaccID.Text)) { // NhaccID NhaccID = CommonHelper.RandomString(8); // Nha cung ung Name = txtName.Text; // Mota Mota = txtMota.Text; // Address Address = txtAddress.Text; // Sodt Sodt = txtSodt.Text; // Email Email = txtEmail.Text; // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); query = "INSERT INTO [Supplier] ([NhaccID],[Ten],[Mota],[Diachi],[Sodt],[Email],[Ngaytao],[Ngaysua])VALUES('" + NhaccID + "','" + Name + "','" + Mota + "','" + Address + "','" + Sodt + "','" + Email + "','" + createDate + "','" + createDate + "')"; } else { NhaccID = txtNhaccID.Text; string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); // Ten khach hang Name = txtName.Text; // Mota Mota = txtMota.Text; // Address Address = txtAddress.Text; // Sodt Sodt = txtSodt.Text; // Email Email = txtEmail.Text; query = "UPDATE [Supplier] SET[Ten] ='" + Name + "',[Mota]= '" + Mota + "',[Diachi]= '" + Address + "',[Sodt]= '" + Sodt + "',[Email]= '" + Email + "',[Ngaysua]= '" + modifyDate + "' WHERE NhaccID ='" + NhaccID + "';"; } if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { if (string.IsNullOrEmpty(txtNhaccID.Text)) { currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(); GetAllData(currentPageNumber, rowPerPage); } else { currentPageNumber = 1; ClearText(); // Update datalist GetAllData(currentPageNumber, rowPerPage); } CommonHelper.showDialog("Đã cập nhật thành công!", Color.FromArgb(4, 132, 75)); } } } catch (Exception ex) { CommonHelper.showDialog("Đang Hoàn Thiện Hệ Thống!", Color.FromArgb(255, 53, 71)); } }
private void btnSave_Click(object sender, EventArgs e) { try { string query = ""; bool isSuccess = false; string NhanvienID, Ho, Ten, Address, Sodt, Email, Username, Password, Role; NhanvienID = Ho = Ten = Address = Sodt = Email = Username = Password = Role = string.Empty; if (string.IsNullOrEmpty(txtNhanvienID.Text)) { // NhanvienID NhanvienID = CommonHelper.RandomString(8); // Ho Ho = txtHo.Text; // Ten Ten = txtTen.Text; // Address Address = txtAddress.Text; // Sodt Sodt = txtSodt.Text; // Email Email = txtEmail.Text; // Username Username = txtUsername.Text; // Password Password = txtPassword.Text; // Role Role = cbRole.SelectedValue.ToString(); // Created Date string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); query = "INSERT INTO [Staff] ([NhanvienID],[Ho],[Ten],[Diachi],[Sodt],[Email],[Tendangnhap],[Matkhau],[RoleID],[Ngaytao],[Ngaysua])VALUES('" + NhanvienID + "','" + Ho + "','" + Ten + "','" + Address + "','" + Sodt + "','" + Email + "','" + Username + "','" + Password + "','" + Role + "','" + createDate + "','" + createDate + "')"; } else { NhanvienID = txtNhanvienID.Text; string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"); // Ho Ho = txtHo.Text; // Ten Ten = txtTen.Text; // Address Address = txtAddress.Text; // Sodt Sodt = txtSodt.Text; // Email Email = txtEmail.Text; // Username Username = txtUsername.Text; // Password Password = txtPassword.Text; // Role Role = cbRole.SelectedValue.ToString(); query = "UPDATE [Staff] SET[Ho] ='" + Ho + "',[Ten]= '" + Ten + "',[Diachi]= '" + Address + "',[Sodt]= '" + Sodt + "',[Email]= '" + Email + "',[Tendangnhap]= '" + Username + "',[Matkhau]= '" + Password + "',[RoleID]= '" + Role + "',[Ngaysua]= '" + modifyDate + "' WHERE NhanvienID ='" + NhanvienID + "';"; } if (DBAccess.IsServerConnected()) { isSuccess = DBAccess.ExecuteQuery(query); if (isSuccess) { if (string.IsNullOrEmpty(txtNhanvienID.Text)) { currentPageNumber = 1; ClearText(); // Update datalist GetTotalRow(); GetAllData(currentPageNumber, rowPerPage); } else { currentPageNumber = 1; ClearText(); // Update datalist GetAllData(currentPageNumber, rowPerPage); } MessageBox.Show("Cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show("Đang Hoàn Thiện Hệ Thống!"); } }
private void btnImport_Click(object sender, EventArgs e) { txtArtID.Enabled = false; txtTen.Enabled = false; txtMieuta.Enabled = false; btnSave.Enabled = false; try { using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xlsx|Excel Workbook 97-2003|*.xls", ValidateNames = true }) { if (ofd.ShowDialog() == DialogResult.OK) { using (var stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)) { IExcelDataReader reader; if (ofd.FilterIndex == 2) { reader = ExcelReaderFactory.CreateBinaryReader(stream); } else { reader = ExcelReaderFactory.CreateOpenXmlReader(stream); } DataSet ds = reader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true } }); foreach (System.Data.DataTable dt in ds.Tables) { if (Convert.ToString(dt.Columns[0]).ToLower() != "ART") { MessageBox.Show("File bị lỗi!"); btnSave.Enabled = false; return; } else { string id, name, desc, createDate, modifyDate; string InsertItemQry = ""; int count = 0; var csv = new StringBuilder(); //foreach (DataRow dr in dtItem.Rows) //{ id = txtArtID.Text; name = txtTen.Text; desc = txtMieuta.Text; createDate = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"); modifyDate = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"); if (id != "") { InsertItemQry += "INSERT INTO [ART] (ARTID,Ten,Mota,Anh, Ngaytao,Ngaysua)VALUES('" + id + "','" + name + "','" + desc + "','" + null + "','" + createDate + "','" + modifyDate + "');"; //var newLine = $"{id},{name},{desc},{createDate},{modifyDate}"; //csv.AppendLine(newLine); //count++; } // if (DBAccess.IsServerConnected()) { if (InsertItemQry.Length > 5) { bool isSuccess = DBAccess.ExecuteQuery(InsertItemQry); if (isSuccess) { MessageBox.Show("Thành công, Số sản phẩm đã nhập : " + count + "", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } reader.Close(); } } OpenFileDialog dialog = new OpenFileDialog(); dialog.ShowDialog(); int ImportedRecord = 0, inValidItem = 0; string SourceURl = ""; if (dialog.FileName != "") { if (dialog.FileName.EndsWith(".xlsx")) { //dtNew = CSVHelper.GetDataTabletFromCSVFile(dialog.FileName, ""); //if (Convert.ToString(dtNew.Columns[0]).ToLower() != "ART") //{ // MessageBox.Show("File bị lỗi!"); // btnSave.Enabled = false; // return; //} //txtFile.Text = dialog.SafeFileName; //SourceURl = dialog.FileName; //if (dtNew.Rows != null && dtNew.Rows.ToString() != String.Empty) //{ // dvgArt.DataSource = dtNew; //} foreach (DataGridViewRow row in dvgArt.Rows) { if (Convert.ToString(row.Cells["ART"].Value) == "") { row.DefaultCellStyle.BackColor = Color.Red; inValidItem += 1; } else { ImportedRecord += 1; } } if (dvgArt.Rows.Count == 0) { btnSave.Enabled = false; MessageBox.Show("Không đọc được dữ liệu trong file", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Vui lòng chọn file excel.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch (Exception ex) { MessageBox.Show("Exception " + ex); } }