// start add private void BtnSave_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { Product pro = new Product(); pro.ProductID = txtProductID.Text.Trim(); pro.ProductName = txtProductName.Text; pro.Description = txtDescription.Text; pro.Package = txtPackage.Text; pro.NumberPackage = 0; pro.Subpackage = txtSubpacakge.Text; pro.NumberSub = 0; pro.PricePackage = 0; pro.PriceToExportPackage = 0; pro.PriceToExportSub = 0; pro.CountSubExport = 0; bool check = ProDAO.insertProduct(pro); if (check) { MessageBox.Show("Create product successful", "Notification"); this.Hide(); frmImport ip = new frmImport(userID, importFrom, listImport); ip.ShowDialog(); this.Close(); } else { MessageBox.Show("Create product fail", "Warning"); this.Hide(); frmImport ip = new frmImport(userID, importFrom, listImport); ip.ShowDialog(); this.Close(); } } }
private void BtnRemove_Click(object sender, EventArgs e) { if (index == -1) { MessageBox.Show("please choose a product by click to it to update", "Warning"); } else { bool delete = ProDAO.SetStatusByID(listPro.ElementAt(index).ProductID, false); if (delete) { listPro.RemoveAt(index); MessageBox.Show("Delete successfull", "Notification"); loadData(listPro); index = -1; txtPricePack.Text = ""; txtPriceSub.Text = ""; } else { MessageBox.Show("Delete fail", "Notification"); index = -1; txtPricePack.Text = ""; txtPriceSub.Text = ""; } } }
private void TxtNumberSub_Validating(object sender, CancelEventArgs e) { if (!string.IsNullOrEmpty(txtSubPackage.Text)) { if (string.IsNullOrEmpty(txtNumberSub.Text)) { e.Cancel = true; errorProvider.SetError(txtNumberSub, "Please input number of sub package"); } else if (!ProDAO.checkInt(txtNumberSub.Text) || int.Parse(txtNumberSub.Text) <= 0) { e.Cancel = true; errorProvider.SetError(txtNumberSub, "Number sub package must be number and greater than 0"); } else { e.Cancel = false; errorProvider.SetError(txtNumberSub, null); } } else { e.Cancel = false; errorProvider.SetError(txtNumberSub, null); } }
private void BtnUpdate_Click(object sender, EventArgs e) { if (index == -1) { MessageBox.Show("please choose a product by click to it to update", "Warning"); } else { if (string.IsNullOrEmpty(txtProductName.Text)) { MessageBox.Show("please input name of product", "Warning"); } else if (string.IsNullOrEmpty(txtPricePack.Text)) { MessageBox.Show("please input price export a package to udpate", "Warning"); } else if (!ProDAO.checkFloat(txtPricePack.Text) || float.Parse(txtPricePack.Text) <= 0) { MessageBox.Show("Price must be a possible number and greater than 0", "Warning"); } else if (string.IsNullOrEmpty(txtPriceSub.Text)) { MessageBox.Show("please input price export a package to udpate", "Warning"); } else if (!ProDAO.checkFloat(txtPriceSub.Text) || float.Parse(txtPriceSub.Text) < 0) { MessageBox.Show("Price must be a possible number and greater than 0", "Warning"); } else { bool check = ProDAO.updatePriceExportByID(listPro.ElementAt(index).ProductID, float.Parse(txtPricePack.Text), float.Parse(txtPriceSub.Text), txtProductName.Text, txtDescription.Text); if (check) { MessageBox.Show("Update successfull", "Notification"); listPro = ProDAO.getListProduct(); loadData(listPro); index = -1; txtPricePack.Text = ""; txtPriceSub.Text = ""; txtProductName.Text = ""; txtDescription.Text = ""; } else { MessageBox.Show("Update fail", "Notification"); index = -1; txtPricePack.Text = ""; txtPriceSub.Text = ""; txtProductName.Text = ""; txtDescription.Text = ""; } } } }
private void BtnImport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtProductID.Text)) { MessageBox.Show("Please choose a product to import!"); } else if (ValidateChildren(ValidationConstraints.Enabled)) { string id = txtProductID.Text; string dateImport = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); int numberPackage = int.Parse(txtNumberPacakge.Text); int numSub = int.Parse(txtNumberSub.Text); float price = float.Parse(txtPrice.Text); int numpackeLast = ProDAO.getNumberPackageByID(id); int numSubLast = ProDAO.getNumSub(id); //create iumportDTO Import ip = new Import(); ip.ImportID = userID; ip.ProductID = id; ip.DateImport = dateImport; ip.ImportFrom = importFrom; ip.NumberPackageImport = numberPackage; ip.PriceImport = price * numberPackage; ip.PriceOneImport = price; ip.ProductName = txtProductName.Text; ip.lastPrice = lastPrice; ip.numSub = int.Parse(txtNumberSub.Text); bool checkUpdateProduct = ProDAO.updateProduct(numberPackage + numpackeLast, numSub + numSubLast, price, id); bool checkInsertIntoImport = importDAO.insertImport(ip); if (checkUpdateProduct && checkInsertIntoImport) { MessageBox.Show("Import successfull"); listProduct = ProDAO.getListProduct(); listImport.Add(ip); txtProductID.Text = ""; txtProductName.Text = ""; txtDescription.Text = ""; txtPackage.Text = ""; txtNumberPacakge.Text = ""; txtSubPackage.Text = ""; txtNumberSub.Text = ""; txtPrice.Text = ""; } else { MessageBox.Show("Import fail"); } } }
private void BtnSearch_Click(object sender, EventArgs e) { string name = txtSearch.Text; listProduct = ProDAO.searchLikeName(name); loadData(listProduct); txtProductID.Text = ""; txtProductName.Text = ""; txtPackage.Text = ""; txtNumberPacakge.Text = ""; txtSubPackage.Text = ""; txtNumberSub.Text = ""; txtPrice.Text = ""; }
private void BtnSearch_Click(object sender, EventArgs e) { string name = txtSearch.Text; listProduct = ProDAO.searchLikeName(name); loadData(listProduct); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; }
private void TxtProductID_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(txtProductID.Text)) { e.Cancel = true; errorProvider.SetError(txtProductID, "Please input productID"); } else if (ProDAO.checkProductID(txtProductID.Text.Trim())) { e.Cancel = true; errorProvider.SetError(txtProductID, "ProductID is existed"); } else { e.Cancel = false; errorProvider.SetError(txtProductID, null); } }
public void loadData(DataTable t) { DataTable view = new DataTable(); view.Columns.Add("ProductID", typeof(string)); view.Columns.Add("ProductName", typeof(string)); view.Columns.Add("DateImport", typeof(string)); view.Columns.Add("ImportFrom", typeof(string)); view.Columns.Add("NumberPackImport", typeof(string)); view.Columns.Add("Price", typeof(string)); for (int i = 0; i < t.Rows.Count; i++) { view.Rows.Add(t.Rows[i]["ProductID"].ToString(), ProDAO.getNameByID(t.Rows[i]["ProductID"].ToString().Trim()), t.Rows[i]["DateImport"].ToString(), t.Rows[i]["ImportFrom"].ToString(), t.Rows[i]["NumberPackageImport"].ToString(), t.Rows[i]["PriceImport"].ToString()); } dgvHistory.DataSource = view; }
private void TxtPrice_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(txtPrice.Text)) { e.Cancel = true; errorProvider.SetError(txtPrice, "Please input price of one package"); } else if (!ProDAO.checkFloat(txtPrice.Text) || int.Parse(txtPrice.Text) <= 0) { e.Cancel = true; errorProvider.SetError(txtPrice, "Price must be number and greater than 0"); } else { e.Cancel = false; errorProvider.SetError(txtPrice, null); } }
//validate public bool validate() { bool valid = true; if (string.IsNullOrEmpty(txtNumberPackage.Text)) { errorProvider.SetError(txtNumberPackage, "Please input number of one package"); valid = false; } else if (!ProDAO.checkInt(txtNumberPackage.Text) || int.Parse(txtNumberPackage.Text) < 0) { errorProvider.SetError(txtNumberPackage, "Number package must be possible number"); valid = false; } else if (!string.IsNullOrEmpty(lbSub.Text)) { errorProvider.SetError(txtNumberPackage, null); if (string.IsNullOrEmpty(txtNumberSub.Text)) { valid = false; errorProvider.SetError(txtNumberSub, "Please input number of sub package"); } else if (!ProDAO.checkInt(txtNumberSub.Text) || int.Parse(txtNumberSub.Text) < 0) { valid = false; errorProvider.SetError(txtNumberSub, "Number sub package must be number and greater than 0"); } else { valid = true; errorProvider.SetError(txtNumberSub, null); } } else { valid = true; errorProvider.SetError(txtNumberPackage, null); errorProvider.SetError(txtNumberSub, null); } return(valid); }
public void loadData(DataTable t) { DataTable view = new DataTable(); view.Columns.Add("ProductID", typeof(string)); view.Columns.Add("ProductName", typeof(string)); view.Columns.Add("DateImport", typeof(string)); view.Columns.Add("ImportFrom", typeof(string)); view.Columns.Add("NumberPackImport", typeof(string)); view.Columns.Add("Price", typeof(string)); float sum = 0; for (int i = 0; i < t.Rows.Count; i++) { sum += float.Parse(t.Rows[i]["PriceImport"].ToString()); view.Rows.Add(t.Rows[i]["ProductID"].ToString(), ProDAO.getNameByID(t.Rows[i]["ProductID"].ToString().Trim()), t.Rows[i]["DateImport"].ToString(), t.Rows[i]["ImportFrom"].ToString(), t.Rows[i]["NumberPackageImport"].ToString(), float.Parse(t.Rows[i]["PriceImport"].ToString()).ToString("N", CultureInfo.CreateSpecificCulture("es-ES"))); } view.Rows.Add("Total: ", "", "", "", "", sum.ToString("N", CultureInfo.CreateSpecificCulture("es-ES")) + "VND"); dgvHistory.DataSource = view; }
private void BtnRemove_Click(object sender, EventArgs e) { if ((dgvSubmit.RowCount - 1) == 0) { MessageBox.Show("List import is empty"); } else { flag = dgvSubmit.CurrentCell.RowIndex; if (flag != -1) { string id = listImport.ElementAt(flag).ProductID; float lastPrice = listImport.ElementAt(flag).lastPrice; string date = listImport.ElementAt(flag).DateImport; int currentNumberPackage = ProDAO.getNumberPackageByID(id); int currentNumSub = ProDAO.getNumSub(id); int numberImport = listImport.ElementAt(flag).NumberPackageImport; int numSubImport = listImport.ElementAt(flag).numSub; listImport.RemoveAt(flag); bool check = importDAO.removeImportByDateTime(date); bool checkReset = ProDAO.updateProduct(currentNumberPackage - numberImport, currentNumSub - numSubImport, lastPrice, id); if (check && checkReset) { MessageBox.Show("Remove successful"); loadData(listImport); flag = -1; } else { MessageBox.Show("Remove fail"); flag = -1; } } else { MessageBox.Show("Please choose product to Remove"); } } }
private void FrmExport_Load(object sender, EventArgs e) { listProduct = ProDAO.getListProduct(); loadData(listProduct); }
private void BtnRemove_Click(object sender, EventArgs e) { if ((dgvSubmitExport.RowCount - 1) == 0) { MessageBox.Show("List export is empty"); } else { flag = dgvSubmitExport.CurrentCell.RowIndex; if (flag != -1) { string productID = listExport.ElementAt(flag).ProductID; string dateExport = listExport.ElementAt(flag).DateExport; int oldNumPack = listExport.ElementAt(flag).NumberPackageExport; int oldNumSub = listExport.ElementAt(flag).NumberSubExport; int oldCount = listExport.ElementAt(flag).CountExport; int currentPackage = ProDAO.getNumberPackageByID(productID); int currentSub = ProDAO.getNumSub(productID); listExport.RemoveAt(flag); if (oldNumSub != 0) { if (oldCount + oldNumSub >= currentSub) { bool checkUpdatePro = ProDAO.updateProductAtCountExport(oldCount, currentPackage + 1 + oldNumPack, productID); bool checkDelete = exportDAO.removeExportByDateTime(dateExport); if (checkUpdatePro) { MessageBox.Show("Remove successful", "Notification"); loadData(listExport); flag = -1; } else { MessageBox.Show("Remove fail", "Warning"); flag = -1; } } else { bool checkUpdatePro = ProDAO.updateProductAtCountExport(oldCount, currentPackage + oldNumPack, productID); bool checkDelete = exportDAO.removeExportByDateTime(dateExport); if (checkUpdatePro) { MessageBox.Show("Remove successful", "Notification"); loadData(listExport); flag = -1; } else { MessageBox.Show("Remove fail", "Warning"); flag = -1; } } } else { bool checkUpdatePro = ProDAO.updateProductAtCountExport(oldCount, currentPackage + oldNumPack, productID); bool checkDelete = exportDAO.removeExportByDateTime(dateExport); if (checkUpdatePro) { MessageBox.Show("Remove successful", "Notification"); loadData(listExport); flag = -1; } else { MessageBox.Show("Remove fail", "Warning"); flag = -1; } } } else { MessageBox.Show("Please choose product to Remove", "Warning"); } } }
private void ManageProduct_Load(object sender, EventArgs e) { listPro = ProDAO.getListProduct(); loadData(listPro); }
private void BtnExport_Click(object sender, EventArgs e) { if (index == -1) { MessageBox.Show("Please choose a product to export"); } else { if (validate()) { string exportID = userID; string productID = txtProductID.Text.Trim(); string productName = txtProductName.Text; string dateExport = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); int numPack = int.Parse(txtNumberPackage.Text); int numSub = 0; if (!string.IsNullOrEmpty(txtNumberSub.Text)) { numSub = int.Parse(txtNumberSub.Text); } float pricePackageExport = listProduct.ElementAt(index).PriceToExportPackage; float priceSubExport = listProduct.ElementAt(index).PriceToExportSub; int currentNumberPackage = ProDAO.getNumberPackageByID(productID); int currentNumSub = ProDAO.getNumSub(productID); int currentCount = ProDAO.getCountExport(productID); if (numPack == 0 && numSub == 0) { MessageBox.Show("please input a number of package or dub package to export"); return; } if (pricePackageExport != 0) { if (numSub == 0) { if (numPack <= currentNumberPackage && numSub <= currentNumSub) { Export ep = new Export(); ep.ExportID = userID; ep.ProductID = productID; ep.ProductName = productName; ep.DateExport = dateExport; ep.NumberPackageExport = numPack; ep.NumberSubExport = numSub; ep.PricePackageExport = pricePackageExport; ep.PriceSubPackageExport = priceSubExport; ep.PriceExport = numPack * pricePackageExport; ep.CountExport = currentCount; bool checkUpdateProdutc = ProDAO.updateProductAtCountExport(0, currentNumberPackage - numPack, productID); bool checkInsertExport = exportDAO.insertExport(ep); if (checkUpdateProdutc && checkInsertExport) { MessageBox.Show("Add to export list successful"); listExport.Add(ep); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } else { MessageBox.Show("Add to export list fail"); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } } else { MessageBox.Show("Number export greater than number produts have been, please inmput again"); } } else { if (priceSubExport != 0) { if (numSub < currentNumSub && numPack <= currentNumberPackage) { Export ep = new Export(); ep.ExportID = userID; ep.ProductID = productID; ep.ProductName = productName; ep.DateExport = dateExport; ep.NumberPackageExport = numPack; ep.NumberSubExport = numSub; ep.PricePackageExport = pricePackageExport; ep.PriceSubPackageExport = priceSubExport; ep.PriceExport = numPack * pricePackageExport + numSub * priceSubExport; ep.CountExport = currentCount; if (numSub + currentCount > currentNumSub) { bool checkUpdateProdutc = ProDAO.updateProductAtCountExport((numSub + currentCount - currentNumSub), currentNumberPackage - 1 - numPack, productID); bool checkInsertExport = exportDAO.insertExport(ep); if (checkUpdateProdutc && checkInsertExport) { MessageBox.Show("Add to export list successful"); listExport.Add(ep); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } else { MessageBox.Show("Add to export list fail"); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } } else if (numSub + currentCount == currentNumSub) { bool checkUpdateProdutc = ProDAO.updateProductAtCountExport(0, currentNumberPackage - 1 - numPack, productID); bool checkInsertExport = exportDAO.insertExport(ep); if (checkUpdateProdutc && checkInsertExport) { MessageBox.Show("Add to export list successful"); listExport.Add(ep); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } else { MessageBox.Show("Add to export list fail"); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } } else { bool checkUpdateProdutc = ProDAO.updateProductAtCountExport((numSub + currentCount), currentNumberPackage - numPack, productID); bool checkInsertExport = exportDAO.insertExport(ep); if (checkUpdateProdutc && checkInsertExport) { MessageBox.Show("Add to export list successful"); listExport.Add(ep); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } else { MessageBox.Show("Add to export list fail"); index = -1; txtProductID.Text = ""; txtProductName.Text = ""; txtDesCription.Text = ""; txtNumberPackage.Text = ""; txtNumberSub.Text = ""; lbPackage.Text = ""; lbSub.Text = ""; } } } else { MessageBox.Show("Please input number sub package less than number sub of one package or yout can export a package"); } } else { MessageBox.Show("Price to export had not been input, please input at manage product function"); } } } else { MessageBox.Show("Price to export had not been input, please input at manage product function"); } } } }