private void btnCreateUnit_Click(object sender, EventArgs e) { OleDbTransaction transactionObj = null; try { if (!unitInEditMode) { transactionObj = DatabaseConnectionObject.connectionObj_Global.BeginTransaction(); if (tbxUnitName.Text == "") { tbxUnitName.BackColor = Color.Red; tbxUnitName.Focus(); throw new Exception("Please Provide a Unit Name"); } if (tbxUnitPrice.Text == "") { tbxUnitPrice.BackColor = Color.Red; tbxUnitPrice.Focus(); throw new Exception("Please Provide a Price for the new Unit"); } if (tbxUnitPrice.BackColor == Color.Red) { tbxUnitPrice.Focus(); throw new Exception("Only Digits are Accepted in Unit Price. Try Again"); } string prefix = DatabaseConnectionObject.datasetObject_Global.Tables["TableIDNumbers"].Rows.Find("TabUnits")["Table Prefix"].ToString(); string num = DatabaseConnectionObject.datasetObject_Global.Tables["TableIDNumbers"].Rows.Find("TabUnits")["Next ID Number"].ToString(); DataTableManager DTM_Units = new DataTableManager("Units", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID); // DataObjectsInitializer UnitTableObj = new DataObjectsInitializer("Units", DatabaseConnectionObject.datasetObject_Global, transactionObj); Dictionary <String, Object> Dic2Use = new Dictionary <string, object> { }; //DataRow NewDTRow = DatabaseConnectionObject.datasetObject_Global.Tables["Units"].NewRow(); Dic2Use.Add("Unit ID", prefix + num); Dic2Use.Add("Unit Name", tbxUnitName.Text); Dic2Use.Add("Item ID", DeleteDictionary[cbxItemID.SelectedItem.ToString()]); Dic2Use.Add("Unit Price", tbxUnitPrice.Text); DTM_Units.CreateRow(Dic2Use, Dic2Use["Unit ID"].ToString()); Dic2Use.Clear(); DataTableManager DTM_TABID = new DataTableManager("TableIDNumbers", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID); String CurrentNextID_Nmber = DTM_TABID.Search("Next ID Number", "TabUnits", true, false).ToString(); Dic2Use.Add("Next ID Number", (long.Parse(CurrentNextID_Nmber) + 1).ToString()); DTM_TABID.EditRow("TabUnits", Dic2Use); transactionObj.Commit(); MessageBox.Show("Unit " + tbxUnitName.Text + " Successfully Created!", "Success"); btnCreateUnit.Enabled = false; tbxUnitName.Text = ""; tbxUnitPrice.Text = ""; cbxItemID.SelectedIndex = 0; cbxItemID.DataSource = DeleteList; cbxItemID.SelectedIndex = 0; cbxUnitID.Enabled = false; btnEdit.Enabled = false; } else { transactionObj = DatabaseConnectionObject.connectionObj_Global.BeginTransaction(); if (tbxUnitName.Text == "") { tbxUnitName.BackColor = Color.Red; tbxUnitName.Focus(); throw new Exception("Please Provide a Unit Name"); } if (tbxUnitPrice.Text == "") { tbxUnitPrice.BackColor = Color.Red; tbxUnitPrice.Focus(); throw new Exception("Please Provide a Price for the new Unit"); } if (tbxUnitPrice.BackColor == Color.Red) { tbxUnitPrice.Focus(); throw new Exception("Only Digits are Accepted in Unit Price. Try Again"); } //DataObjectsInitializer UnitTableObj = new DataObjectsInitializer("Units", DatabaseConnectionObject.datasetObject_Global, transactionObj); //NewDTRow["Unit ID"] = (long.Parse(DatabaseConnectionObject.datasetObject_Global.Tables["TableIDNumbers"].Rows.Find("TabUnits")["Next ID Number"].ToString()) + 1).ToString(); DataTableManager DTM_UnitsEdit = new DataTableManager("Units", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID); DataRow NewDTRow = DatabaseConnectionObject.datasetObject_Global.Tables["Units"].Rows.Find(UnitIDDictionary[cbxUnitID.SelectedItem.ToString()]); Dictionary <String, Object> Dic2Use = new Dictionary <string, object> { }; Dic2Use.Add("Unit Name", tbxUnitName.Text); Dic2Use.Add("Unit Price", tbxUnitPrice.Text); DTM_UnitsEdit.EditRow(UnitIDDictionary[cbxUnitID.SelectedItem.ToString()], Dic2Use); transactionObj.Commit(); MessageBox.Show("Unit " + tbxUnitName.Text + " Successfully Editted succfully", "Success"); //btnCreateUnit.Enabled = false; // tbxUnitName.Text = ""; // tbxUnitPrice.Text = ""; tbxUnitPrice.Enabled = false; tbxUnitName.Enabled = false; btnCreateUnit.Enabled = false; btnEdit.Enabled = true; } } catch (Exception ex) { if (transactionObj != null) { transactionObj.Rollback(); } MessageBox.Show("Error Modifying Units: " + ex.Message.ToString(), "Error Modifying Units"); } }
private void Login_Load(object sender, EventArgs e) { String DatabasePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\ShabaLite.mdb"; OleDbTransaction transactionObj = null; try { DatabaseConnectionObject.connectionObj_Global = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Jet OLEDB:Database Password=aryampa;Data Source=" + DatabasePath); DatabaseConnectionObject.datasetObject_Global = new DataSet(); DatabaseConnectionObject.connectionObj_Global.Open(); DatabaseConnectionObject databaseConnObj = new DatabaseConnectionObject(); Boolean populationResults = databaseConnObj.populate_DataSet(); if (populationResults) { transactionObj = DatabaseConnectionObject.connectionObj_Global.BeginTransaction(); //DataObjectsInitializer SettingsDataObj = new DataObjectsInitializer("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj,""); GlobalVariables.CurrentSessionID = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "CurrentSessionID", true, false).ToString(); GlobalVariables.FirstBackupPerformed = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "FirstBackupPerformed", true, false).ToString(); GlobalVariables.LastBackupDate = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupDate", true, false).ToString(); GlobalVariables.LastBackupID = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupID", true, false).ToString(); GlobalVariables.LastBackupSuccess = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupSuccess", true, false).ToString(); if (GlobalVariables.FirstBackupPerformed == "NO") { DialogResult backupNowQestion = MessageBox.Show("Initial Backup of Data has never been performed. Click YES to Perform the Backp Now or NO to Exit the application", "Backup Not Done", MessageBoxButtons.YesNo); if (backupNowQestion == DialogResult.Yes)// Perform Inital Backup { DateTime CurrentDate = DateTime.Now; DataTableManager DTM_Settings = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, ""); DataTableManager DTM_SessionData = new DataTableManager("SessionData", DatabaseConnectionObject.datasetObject_Global, transactionObj, ""); Dictionary <String, Object> dicSessionData = new Dictionary <string, object> { }; dicSessionData.Add("Session ID", new DateTimeUtility().ToEpochFormat(CurrentDate)); dicSessionData.Add("Date Created", new DateTimeUtility().ToEpochFormat(CurrentDate)); dicSessionData.Add("Date Backedup", new DateTimeUtility().ToEpochFormat(CurrentDate)); DTM_SessionData.CreateRow(dicSessionData, dicSessionData["Session ID"].ToString()); Dictionary <String, Object> EditDic = new Dictionary <string, object> { }; EditDic.Add("Setting Value", "YES"); DTM_Settings.EditRow("FirstBackupPerformed", EditDic); EditDic.Clear(); EditDic.Add("Setting Value", new DateTimeUtility().ToEpochFormat(CurrentDate)); DTM_Settings.EditRow("LastBackupDate", EditDic); EditDic.Clear(); EditDic.Add("Setting Value", new DateTimeUtility().ToEpochFormat(CurrentDate)); DTM_Settings.EditRow("CurrentSessionID", EditDic); EditDic.Clear(); EditDic.Add("Setting Value", new DateTimeUtility().ToEpochFormat(CurrentDate)); DTM_Settings.EditRow("LastBackupID", EditDic); EditDic.Clear(); EditDic.Add("Setting Value", "YES"); DTM_Settings.EditRow("LastBackupSuccess", EditDic); transactionObj.Commit(); MessageBox.Show("Success! Intial Backup Performed", "Sucess!"); GlobalVariables.CurrentSessionID = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "CurrentSessionID", true, false).ToString(); GlobalVariables.FirstBackupPerformed = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "FirstBackupPerformed", true, false).ToString(); GlobalVariables.LastBackupDate = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupDate", true, false).ToString(); GlobalVariables.LastBackupID = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupID", true, false).ToString(); GlobalVariables.LastBackupSuccess = new DataTableManager("Settings", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID).Search("Setting Value", "LastBackupSuccess", true, false).ToString(); } else { throw new Exception("Application Will Exit Because Intial Backup Was not Performed."); } } // MessageBox.Show("Success!!!!!"); } } catch (Exception ex) { if (transactionObj != null) { transactionObj.Rollback(); } MessageBox.Show("Startup Error: [**" + ex.Message.ToString() + "**]", "Startup Error!"); Application.Exit(); } }
private void btnCreateNew_Click_1(object sender, EventArgs e) { OleDbTransaction transactionObj = null; try { if (tbxNewItmName.Text == "") { tbxNewItmName.BackColor = Color.Red; tbxNewItmName.Focus(); throw new Exception("Please Provide a Name"); } if (tbxNewItmDescrip.Text == "") { tbxNewItmDescrip.BackColor = Color.Red; tbxNewItmDescrip.Focus(); throw new Exception("Please Provide a description for the new Item"); } if (DatabaseConnectionObject.connectionObj_Global.State == ConnectionState.Closed) { DatabaseConnectionObject.connectionObj_Global.Open(); DatabaseConnectionObject conObj = new DatabaseConnectionObject(); if (!conObj.populate_DataSet()) { throw new Exception("Error Populating Dataset"); } } transactionObj = DatabaseConnectionObject.connectionObj_Global.BeginTransaction(); //DataObjectsInitializer NewItemDataObj = new DataObjectsInitializer("Items", DatabaseConnectionObject.datasetObject_Global, transactionObj); //DataObjectsInitializer IDtableObj = new DataObjectsInitializer("TableIDNumbers", DatabaseConnectionObject.datasetObject_Global, transactionObj); DataTableManager dbNewItems = new DataTableManager("Items", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID); DataTableManager dbIDTableNmbers = new DataTableManager("TableIDNumbers", DatabaseConnectionObject.datasetObject_Global, transactionObj, GlobalVariables.CurrentSessionID); String CurrentNextID_Nmber = dbIDTableNmbers.Search("Next ID Number", "TabItems", true, false).ToString(); Dictionary <String, Object> Dic2Use = new Dictionary <string, object> { }; Dic2Use.Add("Next ID Number", (long.Parse(CurrentNextID_Nmber) + 1).ToString()); dbIDTableNmbers.EditRow("TabItems", Dic2Use); Dic2Use.Clear(); Dic2Use.Add("Item ID", tbxItmID.Text); Dic2Use.Add("Item Name", tbxNewItmName.Text); Dic2Use.Add("Description", tbxNewItmDescrip.Text); dbNewItems.CreateRow(Dic2Use, tbxItmID.Text); transactionObj.Commit(); MessageBox.Show("Item " + tbxNewItmName.Text + " Successfully Created", "Success"); btnCreateNew.Enabled = false; btnNewItem.Enabled = true; } catch (Exception ex) { if (transactionObj != null) { transactionObj.Rollback(); } MessageBox.Show("Error Creating New Item" + Environment.NewLine + " Message: " + ex.Message.ToString(), "Error"); } }