private void frmReceiveOrder_Load(object sender, EventArgs e) { label1.Hide(); label2.Hide(); DataSet ds = new DataSet(); grdDataSuppliers.DataSource = Supplier.getSupplierSummary(ds).Tables["stk"]; grdDataSuppliers.Columns[0].Visible = false; }
private void frmPlaceOrder_Load(object sender, EventArgs e) { grpStockSelection.Hide(); grpAddCart.Hide(); btnRemove.Hide(); grpCart.Hide(); DataSet ds = new DataSet(); grdDataSupp.DataSource = Supplier.getSupplierSummary(ds).Tables["stk"]; grdDataCart.Columns.Add("OrderID", "OrderId"); grdDataCart.Columns.Add("StockID", "StockId"); grdDataCart.Columns.Add("StockName", "StockName"); grdDataCart.Columns.Add("Price", "Price"); grdDataCart.Columns.Add("Quantity", "Quantity"); grdDataCart.Columns.Add("Total for Product", "Total For Product"); }
private void btnReceiveOrder_Click(object sender, EventArgs e) { if (grdDataReceive.RowCount == 0) { MessageBox.Show("There is nothing received to update"); } else { int orderId = Convert.ToInt16(label2.Text); using (OracleConnection connection = new OracleConnection(DBConnect.oradb)) { connection.Open(); OracleCommand command = connection.CreateCommand(); OracleTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction(); // Must assign both transaction object and connection // to Command object for a pending local transaction command.Connection = connection; command.Transaction = transaction; try { //microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.begintransaction?view=netframework-4.7.2 int amount = Convert.ToInt16(grdDataReceive.Rows[grdDataReceive.CurrentCell.RowIndex].Cells[2].Value.ToString()); int id = Convert.ToInt16(grdDataReceive.Rows[grdDataReceive.CurrentCell.RowIndex].Cells[0].Value.ToString()); int receivedNow = Convert.ToInt16(txtReceived.Text); int orderid = Convert.ToInt16(grdDataOrder.Rows[grdDataOrder.CurrentCell.RowIndex].Cells[0].Value.ToString()); int alreadyReceived = Convert.ToInt16(grdDataReceive.Rows[grdDataReceive.CurrentCell.RowIndex].Cells[4].Value.ToString()); if ((receivedNow + alreadyReceived) <= amount) { if (amount == receivedNow + alreadyReceived) { command.CommandText = "UPDATE STOCK SET AMOUNT = (AMOUNT +" + amount + ") WHERE STOCKID = " + id; command.ExecuteNonQuery(); command.CommandText = "UPDATE OrderItems SET ReceivedStock = (ReceivedStock +" + receivedNow + "),STATUS = 'R' where StockId = " + id; command.ExecuteNonQuery(); grdDataReceive.Rows.RemoveAt(grdDataReceive.CurrentRow.Index); } else { command.CommandText = "UPDATE STOCK SET AMOUNT = (AMOUNT +" + amount + ") WHERE STOCKID = " + id; command.ExecuteNonQuery(); command.CommandText = "UPDATE OrderItems SET ReceivedStock = (ReceivedStock +" + receivedNow + ") where StockId = " + id; command.ExecuteNonQuery(); grdDataReceive.Rows.RemoveAt(grdDataReceive.CurrentRow.Index); } transaction.Commit(); Order.getOrderStatus(orderid); DataSet ds = new DataSet(); grdDataSuppliers.DataSource = Supplier.getSupplierSummary(ds).Tables["stk"]; } else { MessageBox.Show("you cant receive more stock than you ordered"); } } catch (Exception ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception ex2) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType()); Console.WriteLine(" Message: {0}", ex2.Message); } } } } }
private void btnCancel_Click(object sender, EventArgs e) { Boolean delete = true; int id = Convert.ToInt16(grdDataOrders.Rows[grdDataOrders.CurrentCell.RowIndex].Cells[3].Value.ToString()); float refund = float.Parse(grdDataOrders.Rows[grdDataOrders.CurrentCell.RowIndex].Cells[2].Value.ToString()); int suppid = Convert.ToInt16(grdData.Rows[grdData.CurrentCell.RowIndex].Cells[0].Value.ToString()); float balance = float.Parse(grdData.Rows[grdData.CurrentCell.RowIndex].Cells[2].Value.ToString()); float newBalance = balance - refund; for (int i = 0; i < grdDataItems.RowCount; i++) { if (!grdDataItems.Rows[i].Cells[3].Value.Equals("O")) { delete = false; break; } } if (delete) { using (OracleConnection connection = new OracleConnection(DBConnect.oradb)) { connection.Open(); OracleCommand command = connection.CreateCommand(); OracleTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction(); // Must assign both transaction object and connection // to Command object for a pending local transaction command.Connection = connection; command.Transaction = transaction; try { //microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.begintransaction?view=netframework-4.7.2 command.CommandText = "UPDATE SUPPLIER SET BALANCE =" + newBalance + " where SUPPLIERID = " + suppid; command.ExecuteNonQuery(); command.CommandText = "DELETE FROM ORDERITEMS WHERE ORDERID = " + id; command.ExecuteNonQuery(); command.CommandText = "DELETE FROM ORDERS WHERE ORDERID = " + id; command.ExecuteNonQuery(); MessageBox.Show("Commit next"); // Attempt to commit the transaction. transaction.Commit(); DataSet ds = new DataSet(); grdData.DataSource = Supplier.getSupplierSummary(ds).Tables["stk"]; } catch (Exception ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception ex2) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType()); Console.WriteLine(" Message: {0}", ex2.Message); } } } } else { MessageBox.Show("This cannot be deleted as order has been partially received"); } txtSupplierName.Clear(); grdData.DataSource = null; grdDataOrders.DataSource = null; grdDataItems.DataSource = null; }
private void btnCheckout_Click(object sender, EventArgs e) { if (grdDataCart.RowCount == 0) { MessageBox.Show("There is nothing in the shopping Cart"); } else { int OrderId = Order.getNextOrderId(); int SupplierId = Convert.ToInt16(label8.Text); string Status = "O"; float total = float.Parse(txtBalance.Text); //float OriginalBalance = float.Parse(grdDataSupp.Rows[grdDataStock.CurrentCell.RowIndex].Cells[2].Value); DateTime dt = DateTime.Now; string date = dt.ToString("dd-MMM-yyyy"); using (OracleConnection connection = new OracleConnection(DBConnect.oradb)) { connection.Open(); OracleCommand command = connection.CreateCommand(); OracleTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction(); // Must assign both transaction object and connection // to Command object for a pending local transaction command.Connection = connection; command.Transaction = transaction; try { //microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.begintransaction?view=netframework-4.7.2 command.CommandText = "Insert into Orders VALUES (" + OrderId + ",'" + date + "'," + SupplierId + "," + total + ",'" + Status + "')"; command.ExecuteNonQuery(); float currentBalance = float.Parse(grdDataSupp.Rows[grdDataSupp.CurrentCell.RowIndex].Cells[2].Value.ToString()); float newBalance = currentBalance + total; for (int i = 0; i < grdDataCart.RowCount; i++) { int StockId = Convert.ToInt16(grdDataCart.Rows[i].Cells[1].Value.ToString()); float price = float.Parse(grdDataCart.Rows[i].Cells[3].Value.ToString()); int quantity = Convert.ToInt16(grdDataCart.Rows[i].Cells[4].Value.ToString()); command.CommandText = "INSERT INTO OrderItems VALUES(" + OrderId + "," + StockId + "," + price + "," + quantity + ",'O',0)"; command.ExecuteNonQuery(); } command.CommandText = "UPDATE Supplier SET Balance = " + newBalance + "where SupplierId = " + SupplierId; command.ExecuteNonQuery(); // Attempt to commit the transaction. transaction.Commit(); txtAmountOrder.Value = 0; grdDataCart.Rows.Clear(); grdDataCart.Hide(); txtPrice.Clear(); txtBalance.Clear(); grpCart.Hide(); grpAddCart.Hide(); grpStockSelection.Hide(); DataSet ds = new DataSet(); grdDataSupp.DataSource = Supplier.getSupplierSummary(ds).Tables["stk"]; grpSupplier.Show(); } catch (Exception ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception ex2) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType()); Console.WriteLine(" Message: {0}", ex2.Message); } } } } }