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 ArtManagement_Load(object sender, EventArgs e) { if (DBAccess.IsServerConnected()) { PopulateData(currentPageNumber, rowPerPage, currentOrderByItem); } }
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 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 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!"); } }
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 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 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 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); } }
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 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 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 "); } }
void CheckUserPassword(string username, string password) { try { if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { string query = "SELECT * FROM Staff Join Roles on Staff.RoleID = Roles.RoleID WHERE Tendangnhap ='" + username + "' and Matkhau='" + password + "';"; if (DBAccess.IsServerConnected()) { using (SqlCeConnection connection = new SqlCeConnection(conn)) { using (SqlCeCommand command = new SqlCeCommand(query, connection)) { SqlCeDataAdapter sda = new SqlCeDataAdapter(command); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count >= 1) { string currentUser = dt.Rows[0].Field <string>("Tendangnhap").ToString(); string currentRole = dt.Rows[0].Field <string>("RoleID").ToString(); LoginForm childForm = (LoginForm)this.ParentForm; Form1 parentForm = (Form1)childForm.ParentForm; Panel pnMenu = parentForm.Controls["pnMenu"] as Panel; pnMenu.Visible = true; Panel pnLeft = parentForm.Controls["pnLeft"] as Panel; pnLeft.Visible = true; pnLeft.Width = 238; Panel pnStuff = pnLeft.Controls["pnStuff"] as Panel; Panel pnSystem = pnLeft.Controls["pnSystem"] as Panel; Panel pnInOutStock = pnLeft.Controls["pnInOutStock"] as Panel; if (currentRole == "0000001") { pnStuff.Visible = true; pnSystem.Visible = true; Button btnStaff = pnSystem.Controls["btnStaff"] as Button; btnStaff.Visible = true; pnInOutStock.Visible = false; } else if (currentRole == "0000003") { pnStuff.Visible = false; pnSystem.Visible = false; pnInOutStock.Visible = true; } Button btnMini = pnLeft.Controls["btnMini"] as Button; btnMini.Visible = true; Label lblCurrentUser = pnMenu.Controls["lblCurrentUser"] as Label; lblCurrentUser.Text = username; lblCurrentUser.Visible = true; Button btnMinimize = pnMenu.Controls["btnMinimize"] as Button; btnMinimize.Visible = true; Button btnMaximize = pnMenu.Controls["btnMaximize"] as Button; btnMaximize.Visible = true; Panel SidePanelLeft = pnLeft.Controls["SidePanelLeft"] as Panel; SidePanelLeft.Visible = true; Button btnSignout = pnMenu.Controls["btnSignout"] as Button; btnSignout.Visible = true; this.Visible = false; ClearField(); } else { CommonHelper.showDialog("Sai tên đăng nhập hoặc mật khẩu.", Color.FromArgb(255, 53, 71)); } } } } } else { CommonHelper.showDialog("Mời tên đăng nhập và mật khẩu.", Color.FromArgb(255, 187, 51)); } } catch (SqlCeException Ceex) { MessageBox.Show(Ceex.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }