private void ButtonSave_Click(object sender, EventArgs e) { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { if (ComboBoxLabourName.Items.Contains(ComboBoxLabourName.Text)) { DatabaseConnectObj.SqlQuery("UPDATE Labour SET LabourPrice = '" + TextBoxUnitPrice.Text.Trim() + "' WHERE (LabourName = '" + ComboBoxLabourName.Text.Trim() + "') "); DatabaseConnectObj.ExecutNonQuery(); } else { DatabaseConnectObj.SqlQuery("INSERT INTO Labour (LabourName, LabourDesc, LabourPrice) VALUES ('" + ComboBoxLabourName.Text.Trim() + "','','" + TextBoxUnitPrice.Text.Trim() + "')"); DatabaseConnectObj.ExecutNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { ComboBoxLabourName.Text = ""; TextBoxUnitPrice.Text = ""; DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception ex) { string output = ex.Message + " ButtonSave_Click"; MessageBox.Show(output); } }
private void ButtonSave_Click(object sender, EventArgs e) { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DataTable dt = new DataTable(); string date = DateTimePickerIssued.Value.Month.ToString() + "/" + DateTimePickerIssued.Value.Day.ToString() + "/" + DateTimePickerIssued.Value.Year.ToString(); DatabaseConnectObj.SqlQuery("INSERT INTO Expences (Name, [Desc], value, DateIssued) VALUES ('" + TextBoxPaidTo.Text + "','" + TextBoxDesc.Text + "','" + TextBoxAmount.Text + "','" + date + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } ButtonSave.Enabled = false; ButtonPrint.Enabled = true; }
private void LabelRestore_Click(object sender, EventArgs e) { //RESTORE DATABASE AdventureWorks FROM DISK = SaveFileDialog op = new SaveFileDialog(); if (op.ShowDialog() == DialogResult.OK) { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DatabaseConnectObj.SqlQuery(@"RESTORE DATABASE AdventureWorks FROM DISK = '" + op.FileName + "'"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception es) { MessageBox.Show(es.Message); } } }
private void LabelBackup_Click(object sender, EventArgs e) { FolderBrowserDialog op = new FolderBrowserDialog(); if (op.ShowDialog() == DialogResult.OK) { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DatabaseConnectObj.SqlQuery(@"BACKUP DATABASE [F:\DATA\BILLINGDATABASE.MDF] TO DISK = '" + op.SelectedPath.ToString() + @"\Backup_" + DateTime.Today.Date.ToShortDateString() + ".bak'"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception es) { MessageBox.Show(es.Message); } } }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (MessageBox.Show("are you sure you want to update the due of this invoice?", "Confirmation Box", MessageBoxButtons.OKCancel) == DialogResult.OK) { int temp = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Invoiceid"].Value.ToString()); try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DataTable dt = new DataTable(); DatabaseConnectObj.SqlQuery("UPDATE Invoice SET due = '" + dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() + "' WHERE (invoiceid = '" + dataGridView1.Rows[e.RowIndex].Cells["Invoiceid"].Value.ToString() + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = BeginEditVariable; } }
private void ButtonSave_Click(object sender, EventArgs e) { if (ComboBoxVehicleModel.Items.Contains(ComboBoxVehicleModel.Text) && ComboBoxVehicleName.Items.Contains(ComboBoxVehicleName.Text)) { try { DataRow[] vehicleRowData = customerVehicleData.Select("VehicleType='" + ComboBoxVehicleModel.Text.Trim() + "' AND VehicleName='" + ComboBoxVehicleName.Text.Trim() + "'"); string selectedVehicleId = vehicleRowData[0]["Id"].ToString().Trim(); ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { if (ComboBoxItemName.Items.Contains(ComboBoxItemName.Text)) { DatabaseConnectObj.SqlQuery("UPDATE Items SET ItemPrice = '" + TextBoxUnitPrice.Text + "' WHERE (VehicleId = '" + selectedVehicleId + "')"); DatabaseConnectObj.ExecutNonQuery(); } else { DatabaseConnectObj.SqlQuery("INSERT INTO Items (ItemName, ItemPrice,VehicleId) VALUES ('" + ComboBoxItemName.Text.Trim() + "','" + TextBoxUnitPrice.Text.Trim() + "','" + selectedVehicleId + "')"); DatabaseConnectObj.ExecutNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { ComboBoxVehicleModel.Text = ""; ComboBoxItemName.Text = ""; TextBoxUnitPrice.Text = ""; DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception es) { MessageBox.Show(es.Message); } } else { MessageBox.Show("Please select a model from the drop down list"); } }
private void ButtonSave_Click_1(object sender, EventArgs e) { Int64 n; string temp = TextBoxCusNo.Text.Trim(); bool flag = Int64.TryParse(temp, out n); if (TextBoxVehicleNo.Text.Trim() == "") { MessageBox.Show("please enter a vehicle number"); TextBoxVehicleNo.Focus(); } else if (flag) //check if the input is number or characters { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { if (ComboBoxVehicleName.Text.Trim() == "") { DatabaseConnectObj.SqlQuery("SELECT Id FROM Vehicle WHERE (VehicleType = '" + ComboBoxVehicleModel.Text.Trim() + "') AND (VehicleName is NULL)"); } else { DatabaseConnectObj.SqlQuery("SELECT Id FROM Vehicle WHERE (VehicleType = '" + ComboBoxVehicleModel.Text.Trim() + "') AND (VehicleName = '" + ComboBoxVehicleName.Text.Trim() + "')"); } DataTable result = DatabaseConnectObj.ExecuteQuery(); DatabaseConnectObj.SqlQuery("INSERT INTO Customer (CustomerName, CustomerNo, VehicleNo, VehicleId) VALUES ('" + TextBoxCusName.Text.Trim() + "','" + TextBoxCusNo.Text.Trim() + "','" + TextBoxVehicleNo.Text.Trim() + "','" + result.Rows[0]["Id"].ToString().Trim() + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { TextBoxCusName.Text = ""; TextBoxCusNo.Text = ""; TextBoxVehicleNo.Text = ""; ComboBoxVehicleModel.Text = ""; ComboBoxVehicleName.Text = ""; } } catch (Exception es) { MessageBox.Show(es.Message); } } else { MessageBox.Show("enter a valid customer contact number"); TextBoxVehicleNo.Focus(); } }
private void ComboBoxVehicleName_Leave(object sender, EventArgs e) { if (ComboBoxVehicleName.Text.Trim() == "") { MessageBox.Show("Vehicle name cannot be empty, please enter a name."); ComboBoxVehicleName.Focus(); } else if (!ComboBoxVehicleName.Items.Contains(ComboBoxVehicleName.Text.Trim().Trim())) { DialogResult result = MessageBox.Show("Selected Name does not exist for the cateegory of models " + ComboBoxVehicleModel.Text.Trim() + ", Do you want to add it?", "Delete Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string tempProduct = ComboBoxVehicleName.Text.Trim(); try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DatabaseConnectObj.SqlQuery("INSERT INTO Vehicle (VehicleType, VehicleName) VALUES ('" + ComboBoxVehicleModel.Text.Trim() + "','" + ComboBoxVehicleName.Text.Trim() + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataRow newData = customerVehicleData.NewRow(); newData["VehicleType"] = ComboBoxVehicleModel.Text.Trim(); newData["VehicleName"] = ComboBoxVehicleName.Text.Trim(); customerVehicleData.Rows.Add(newData); ComboBoxVehicleName.Items.Add(ComboBoxVehicleName.Text); } else { ComboBoxVehicleName.Text = ""; } } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete") { PasswordForm testDialog = new PasswordForm(); // Show testDialog as a modal dialog and determine if DialogResult = OK. if (testDialog.ShowDialog() == DialogResult.OK && testDialog.TextBoxPassword.Text == HiddenLabel.Text) { string invoiveid = dataGridView1.Rows[e.RowIndex].Cells["Invoiceid"].Value.ToString(); try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DataTable dt = new DataTable(); DatabaseConnectObj.SqlQuery("DELETE FROM Invoice WHERE (invoiceid = '" + invoiveid + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); dataGridView1.Rows.RemoveAt(e.RowIndex); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Decimal temp = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { temp += Convert.ToDecimal(row.Cells["total"].Value); } TextBoxTotal.Text = temp.ToString(); } else { MessageBox.Show("Enter a valid Password"); } } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete") { DialogResult result = MessageBox.Show("Are you sure?", "Delete Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string Id = dataGridView1.Rows[e.RowIndex].Cells["VoucherNo"].Value.ToString(); try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DataTable dt = new DataTable(); DatabaseConnectObj.SqlQuery("DELETE FROM Expences WHERE (Id = '" + Id + "')"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); dataGridView1.Rows.RemoveAt(e.RowIndex); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Decimal temp = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { temp += Convert.ToDecimal(row.Cells["total"].Value); } TextBoxTotal.Text = temp.ToString(); } } }
private void ButtonSave_Click(object sender, EventArgs e) { try { ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection(); try { DataTable dt = new DataTable(); DatabaseConnectObj.SqlQuery("DELETE FROM BillItemDetails" + typeEdit + " WHERE (" + typeEdit + "id = " + LableInvoiceId.Text + ")"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { DataTable dt = new DataTable(); DatabaseConnectObj.SqlQuery("DELETE FROM BillLabourDetail" + typeEdit + " WHERE (" + typeEdit + "id = " + LableInvoiceId.Text + ")"); DatabaseConnectObj.ExecutNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try // insert the bill details { for (int i = 0; i < dataGridItems.Rows.Count; i++) { DatabaseConnectObj.SqlQuery("INSERT INTO BillitemDetails" + typeEdit + " (ItemNo, Quantity, price, " + typeEdit + "No,Tax, " + typeEdit.ToLower() + "id) VALUES ('" + dataGridItems.Rows[i].Cells["Itemid"].Value + "','" + dataGridItems.Rows[i].Cells["Quantity"].Value + "','" + dataGridItems.Rows[i].Cells["UnitPrice"].Value + "','" + NumericInvoiceNo.Value + "','" + dataGridItems.Rows[i].Cells["Tax"].Value + "','" + LableInvoiceId.Text + "')"); DatabaseConnectObj.ExecutNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } try // insert the bill details { for (int i = 0; i < DataGridLabour.Rows.Count; i++) { DatabaseConnectObj.SqlQuery("INSERT INTO BillLabourDetail" + typeEdit + " (LabourNo, price, " + typeEdit + "No,Tax, " + typeEdit.ToLower() + "id) VALUES ('" + DataGridLabour.Rows[i].Cells["LabourId"].Value + "','" + DataGridLabour.Rows[i].Cells["LabourCharge"].Value + "','" + NumericInvoiceNo.Value + "','" + DataGridLabour.Rows[i].Cells["LabourTax"].Value + "','" + LableInvoiceId.Text + "')"); DatabaseConnectObj.ExecutNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } try // insert the bill details { for (int i = 0; i < dataGridItems.Rows.Count; i++) { DatabaseConnectObj.SqlQuery("UPDATE " + typeEdit + " SET total = '" + TextBoxTotal.Text + "', remark = '" + TextBoxRemark.Text + "' WHERE (" + typeEdit + "id = '" + LableInvoiceId.Text + "')"); DatabaseConnectObj.ExecutNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { DatabaseConnectObj.DatabaseConnectionClose(); } ButtonUpdate.Enabled = false; ButtonPreview.Enabled = true; ButtonMakeInvoice.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }