void BtnAddPOClick(object sender, EventArgs e) { if(btnAddPO.Text == "Add PO") { btnAddPO.Text = "Save PO"; btnEditPO.Enabled = false; Enabler(true); } else { PO thePO = new PO(); thePO.PONumber = tbxPO.Text; thePO.Amount = nudOmount.Value; thePO.ClientID = clientID; if(Model.AddPO(thePO)) { LoadPOs(); lbxPOs.SelectedIndex =0; } else { MessageBox.Show("Unable to add the PO"); } btnAddPO.Text = "Add PO"; Enabler(false); } }
public static List<PO> GetPOs(int clientID) { if(theConnection.ConnectionString == string.Empty) { theConnection.ConnectionString = connectionString; } List<PO> thePOs = new List<PO>(); PO thePO; List<POTransaction> transactions = new List<POTransaction>(); POTransaction theTransaction; try { commandString= "select * from PO_Transactions"; theConnection.Open(); theCommand.Connection = theConnection; theCommand.CommandText = commandString; reader = theCommand.ExecuteReader(); while(reader.Read()) { theTransaction = new POTransaction(); theTransaction.POID = int.Parse(reader["poID"].ToString()); theTransaction.Date = DateTime.Parse(reader["date"].ToString()); theTransaction.Amount = decimal.Parse(reader["amount"].ToString()); transactions.Add(theTransaction); } reader.Close(); commandString = "select * from POs where clientID = " + clientID; theCommand.CommandText = commandString; reader = theCommand.ExecuteReader(); while (reader.Read()) { thePO = new PO(); thePO.Amount = decimal.Parse(reader["amount"].ToString()); thePO.ClientID = int.Parse(reader["clientID"].ToString()); thePO.ID = int.Parse(reader["poID"].ToString()); thePO.PONumber = reader["poMTNumber"].ToString(); thePO.Transactions = new List<POTransaction>(); foreach(POTransaction tempTransaction in transactions) { if(tempTransaction.POID == thePO.ID) { thePO.Transactions.Add(tempTransaction); } } thePOs.Add(thePO); } return thePOs; } catch (MySqlException ex) { return new List<PO>(); } finally { theConnection.Close(); } }
public static bool AddPO(PO thePO) { if(theConnection.ConnectionString == string.Empty) { theConnection.ConnectionString = connectionString; } try { theConnection.Open(); theCommand.Connection = theConnection; commandString = "insert into POs (clientID,poMTNumber,amount)" + "Values(@clientID,@poMTNumber,@amount)"; theCommand.CommandText = commandString; theCommand.Prepare(); theCommand.Parameters.Clear(); theCommand.Parameters.AddWithValue("@clientID",thePO.ClientID); theCommand.Parameters.AddWithValue("@poMTNumber",thePO.PONumber); theCommand.Parameters.AddWithValue("@amount",thePO.Amount); theCommand.ExecuteNonQuery(); return true; } catch(MySqlException ex) { return false; } finally { theConnection.Close(); } }
public static bool UpdatePO(PO thePO) { if(theConnection.ConnectionString == string.Empty) { theConnection.ConnectionString = connectionString; } try { theConnection.Open(); theCommand.Connection = theConnection; commandString = "update POs set poMTNumber = @poMTNumber,amount = @amount where poID = " + thePO.ID; theCommand.CommandText = commandString; theCommand.Prepare(); theCommand.Parameters.Clear(); theCommand.Parameters.AddWithValue("@poMTNumber",thePO.PONumber); theCommand.Parameters.AddWithValue("@amount",thePO.Amount); theCommand.ExecuteNonQuery(); return true; } catch(MySqlException ex) { return false; } finally { theConnection.Close(); } }
void BtnEditPOClick(object sender, EventArgs e) { if(btnEditPO.Text == "Edit PO") { btnEditPO.Text = "Save PO"; btnAddPO.Enabled = false; Enabler(true); } else { btnEditPO.Text = "Edit PO"; btnAddPO.Enabled = true; PO thePO = new PO(); thePO.Amount = nudOmount.Value; thePO.PONumber = tbxPO.Text; thePO.ID = pos[lbxPOs.SelectedIndex].ID; if(Model.UpdatePO(thePO)) { LoadPOs(); } else { MessageBox.Show("Unable to update PO"); } Enabler(false); } }