private void btnGen_Click(object sender, EventArgs e) { cnn.Open(); int completedCount = 0, rowCount = 0; String status = "DNC"; foreach (DataGridViewRow row in dGVItem.Rows) { int qty = Convert.ToInt32(row.Cells["Quantity"].Value); int arrivedQty = Convert.ToInt32(row.Cells["Arrived"].Value); String itemID = Convert.ToString(row.Cells["ItemID"].Value); MySqlCommand updateDN = new MySqlCommand("Update DeliveryNote SET ArrivedQty = '" + arrivedQty + "' WHERE ItemID = '" + itemID + "' and DeliveryID = '" + DNId + "';", cnn); updateDN.ExecuteNonQuery(); if (qty <= arrivedQty) { completedCount++; } rowCount++; } if (completedCount == rowCount) { status = "COM"; } MySqlCommand updateStatus = new MySqlCommand("Update DeliveryNote SET Status = '" + status + "' WHERE DeliveryID = '" + DNId + "';", cnn); updateStatus.ExecuteNonQuery(); if (status.Equals("COM")) { MessageBox.Show("Delivery Completed !", "Confirm Successfully !", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (status.Equals("DNC")) { MessageBox.Show("Delivery Completed with not correct amount", "Confirm Successfully !", MessageBoxButtons.OK, MessageBoxIcon.Information); } //Check DB for updating PR status MySqlCommand getCOMDN = new MySqlCommand("select count(RequestNo) from DeliveryNote where Status in ('COM','DNC','CAN') and RequestNo = '" + rno + "';", cnn); MySqlCommand getTotalDN = new MySqlCommand("select count(DeliveryID) from DeliveryNote where RequestNo = '" + rno + "';", cnn); MySqlCommand getFINDI = new MySqlCommand("select count(DesID) from DespatchInstruction where RequestNo = '" + rno + "' and Status = 'FIN'; ", cnn); MySqlCommand getTotalDI = new MySqlCommand("select count(DesID) from DespatchInstruction where RequestNo = '" + rno + "'; ", cnn); int COMDN = Convert.ToInt32(getCOMDN.ExecuteScalar()); int TotalDN = Convert.ToInt32(getTotalDN.ExecuteScalar()); int FINDI = Convert.ToInt32(getFINDI.ExecuteScalar()); int TotalDI = Convert.ToInt32(getTotalDI.ExecuteScalar()); if ((COMDN == TotalDN) && (FINDI == TotalDI)) { foreach (DataGridViewRow row in dGVItem.Rows) { String itemID = Convert.ToString(row.Cells["ItemID"].Value); MySqlCommand updatePRStatus = new MySqlCommand("Update PurchaseRequest SET Status = 'COM' WHERE RequestNo = '" + rno + "' and itemID = '" + itemID + "';", cnn); updatePRStatus.ExecuteNonQuery(); } } cnn.Close(); m.loadData(); this.Close(); }
private void btnGen_Click(object sender, EventArgs e) { cnn.Open(); foreach (DataGridViewRow row in dGVItem.Rows) { int quantity = Convert.ToInt32(row.Cells["quantity"].Value); int arrivedQty = Convert.ToInt32(row.Cells["arrived"].Value); String itemID = Convert.ToString(row.Cells["ItemID"].Value); MySqlCommand updateStock = new MySqlCommand("UPDATE DeliveryNote SET quantity = '" + quantity + "', ArrivedQty ='" + arrivedQty + "',Status = '" + lbStatus.Text + "' WHERE ItemID = '" + itemID + "' and DeliveryID = '" + DNId + "';", cnn); updateStock.ExecuteNonQuery(); } //Check DB for updating PR status MySqlCommand getCOMDN = new MySqlCommand("select count(RequestNo) from DeliveryNote where Status in ('COM','DNC','CAN') and RequestNo = '" + rno + "';", cnn); MySqlCommand getTotalDN = new MySqlCommand("select count(DeliveryID) from DeliveryNote where RequestNo = '" + rno + "';", cnn); MySqlCommand getFINDI = new MySqlCommand("select count(DesID) from DespatchInstruction where RequestNo = '" + rno + "' and Status = 'FIN'; ", cnn); MySqlCommand getTotalDI = new MySqlCommand("select count(DesID) from DespatchInstruction where RequestNo = '" + rno + "'; ", cnn); int COMDN = Convert.ToInt32(getCOMDN.ExecuteScalar()); int TotalDN = Convert.ToInt32(getTotalDN.ExecuteScalar()); int FINDI = Convert.ToInt32(getFINDI.ExecuteScalar()); int TotalDI = Convert.ToInt32(getTotalDI.ExecuteScalar()); if ((COMDN == TotalDN) && (FINDI == TotalDI)) { foreach (DataGridViewRow row in dGVItem.Rows) { String itemID = Convert.ToString(row.Cells["ItemID"].Value); MySqlCommand updatePRStatus = new MySqlCommand("Update PurchaseRequest SET Status = 'COM' WHERE RequestNo = '" + rno + "' and itemID = '" + itemID + "'; ", cnn); updatePRStatus.ExecuteNonQuery(); } } else { foreach (DataGridViewRow row in dGVItem.Rows) { String itemID = Convert.ToString(row.Cells["ItemID"].Value); MySqlCommand updatePRStatus = new MySqlCommand("Update PurchaseRequest SET Status = 'DLI' WHERE RequestNo = '" + rno + "' and itemID = '" + itemID + "';", cnn); updatePRStatus.ExecuteNonQuery(); } } cnn.Close(); MessageBox.Show("Update Success!", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); m.loadData(); this.Close(); }