コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 private void ButtonReset_Click(object sender, EventArgs e)
 {
     TextBoxVoucherNo.Text = "";
     TextBoxPaidTo.Text    = "";
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT  Name, Id, DateIssued, value FROM Expences");
             dt = DatabaseConnectObj.ExecuteQuery();
             dataGridView1.DataSource = dt;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #4
0
        private DataTable getCustomerItemData()
        {
            DataTable result = new DataTable();

            try
            {
                ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
                try
                {
                    DatabaseConnectObj.SqlQuery("SELECT ItemId, ItemName, ItemDesc, ItemPrice, VehicleId FROM Items");
                    result = DatabaseConnectObj.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DatabaseConnectObj.DatabaseConnectionClose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
コード例 #5
0
        private DataTable getCustomerVehicleData()
        {
            DataTable result = new DataTable();

            try
            {
                ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
                try
                {
                    DatabaseConnectObj.SqlQuery("SELECT Id,VehicleName,VehicleType FROM Vehicle");
                    result = DatabaseConnectObj.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DatabaseConnectObj.DatabaseConnectionClose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
コード例 #6
0
 private void ButtonReset_Click(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT Customer.CustomerName, Customer.VehicleNo, Invoice.InvoiceNo, Invoice.Date, Invoice.total, Invoice.due, Invoice.invoiceid FROM Invoice INNER JOIN Customer ON Invoice.CustomerId = Customer.CustomerId");
             dt = DatabaseConnectObj.ExecuteQuery();
             dataGridView1.DataSource = dt;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     TextBoxCusName.Text    = "";
     TextBoxCusContact.Text = "";
     TextBoxVehicleNo.Text  = "";
     TextBoxInvoiceNo.Text  = "";
 }
コード例 #7
0
 private void ButtonReset_Click(object sender, EventArgs e)
 {
     ComboBoxServiceName.Text = "";
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT ItemName, ItemDesc, ItemPrice FROM Items");
             dt = DatabaseConnectObj.ExecuteQuery();
             dataGridView1.DataSource = dt;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #8
0
 private void NewVoucher_Load(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT MAX(Id) AS voucherno FROM Expences");
             dt = DatabaseConnectObj.ExecuteQuery();
             foreach (DataRow row in dt.Rows)
             {
                 TextBoxVoucherNo.Text = (Convert.ToInt32(row["voucherno"].ToString()) + 1).ToString();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             TextBoxVoucherNo.Text = "1";
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #9
0
 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;
     }
 }
コード例 #10
0
        private void ReportingInvoice_Load(object sender, EventArgs e)
        {
            try
            {
                ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
                try //load datagrid
                {
                    DataTable dt = new DataTable();
                    DatabaseConnectObj.SqlQuery("SELECT Customer.CustomerName, Customer.VehicleNo, Invoice.InvoiceNo, Invoice.Date, Invoice.total, Invoice.due, Invoice.invoiceid FROM Invoice INNER JOIN Customer ON Invoice.CustomerId = Customer.CustomerId");
                    dt = DatabaseConnectObj.ExecuteQuery();
                    dataGridView1.DataSource = dt;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DatabaseConnectObj.DatabaseConnectionClose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Decimal temp = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows) //calculate total
            {
                temp += Convert.ToDecimal(row.Cells["total"].Value);
            }
            TextBoxTotal.Text = temp.ToString(); //update total
        }
コード例 #11
0
 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;
 }
コード例 #12
0
 private void SchedulerSmsReport_Load(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT VehicleNo, Date FROM Schedule");
             dt = DatabaseConnectObj.ExecuteQuery();
             dataGridView1.DataSource = dt;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #13
0
        private void MountlyReport_Load(object sender, EventArgs e)
        {
            try
            {
                ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
                try
                {
                    DataTable dt = new DataTable();
                    DatabaseConnectObj.SqlQuery("SELECT  Name, Id, DateIssued, value FROM Expences");
                    dt = DatabaseConnectObj.ExecuteQuery();
                    dataGridView1.DataSource = dt;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DatabaseConnectObj.DatabaseConnectionClose();
                }
            }
            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();
        }
コード例 #14
0
 private void SelectCustomer_Load(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT CustomerName, CustomerNo, VehicleNo FROM Customer");
             dt = DatabaseConnectObj.ExecuteQuery();
             foreach (DataRow row in dt.Rows)
             {
                 CheckBoxListCusList.Items.Add(row["CustomerName"].ToString().Trim() + "     (" + row["VehicleNo"].ToString() + ")");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #15
0
 private void ReportingService_Load(object sender, EventArgs e)
 {
     ComboBoxServiceName.Items.Clear();
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         try
         {
             DataTable dt = new DataTable();
             DatabaseConnectObj.SqlQuery("SELECT ItemName, ItemDesc, ItemPrice FROM Items");
             dt = DatabaseConnectObj.ExecuteQuery();
             foreach (DataRow row in dt.Rows)
             {
                 ComboBoxServiceName.Items.Add(row["ItemName"].ToString());
             }
             dataGridView1.DataSource = dt;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             DatabaseConnectObj.DatabaseConnectionClose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #16
0
        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);
                }
            }
        }
コード例 #17
0
 private void ButtonSearch_Click(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         if (ComboBoxServiceName.Text != "")
         {
             try
             {
                 DataTable dt = new DataTable();
                 DatabaseConnectObj.SqlQuery("SELECT ItemName, ItemDesc, ItemPrice FROM Items WHERE (ItemName = '" + ComboBoxServiceName.Text + "')");
                 dt = DatabaseConnectObj.ExecuteQuery();
                 dataGridView1.DataSource = dt;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
             finally
             {
                 DatabaseConnectObj.DatabaseConnectionClose();
             }
         }
         else
         {
             MessageBox.Show("Enter a product name");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #18
0
 private void ButtonSearch_Click(object sender, EventArgs e)
 {
     try
     {
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         string query = "";
         if (TextBoxCusName.Text != "")
         {
             query = "CustomerName LIKE '%" + TextBoxCusName.Text.Trim() + "%' AND ";
         }
         if (TextBoxCusContact.Text != "")
         {
             query = query + "CustomerNo LIKE '%" + TextBoxCusContact.Text.Trim() + "%' AND ";
         }
         if (ComboBoxVehicleSelection.Text != "")
         {
             if (ComboBoxVehicleOption.Text == "Vehicle Type")
             {
                 query = query + "VehicleType = '" + ComboBoxVehicleSelection.Text.Trim() + "' AND ";
             }
             else
             {
                 query = query + "VehicleName = '" + ComboBoxVehicleSelection.Text.Trim() + "' AND ";
             }
         }
         if (TextBoxVehicleNo.Text != "")
         {
             query = query + "VehicleNo LIKE '%" + TextBoxVehicleNo.Text.Trim() + "%'";
         }
         if (query.EndsWith("AND "))
         {
             query = query.Remove(query.Length - 4);
         }
         DataRow[] result = dataCustomerAndVehicle.Select(query);
         if (result.Length > 0)
         {
             DataTable source = result.CopyToDataTable();
             dataGridClient.DataSource = source;
         }
         else
         {
             //expty source created nstead of null because null removes the column properties defined.
             DataTable emptySource = new DataTable();
             emptySource.Columns.Add("CustomerName");
             emptySource.Columns.Add("CustomerNo");
             emptySource.Columns.Add("VehicleNo");
             emptySource.Columns.Add("VehicleName");
             emptySource.Columns.Add("VehicleType");
             dataGridClient.DataSource = emptySource;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
 private void ButtonSearch_Click(object sender, EventArgs e)
 {
     try
     {
         String DateTo   = "";
         String DateFrom = "";
         DateTo   = DateTimePickerTo.Value.Month.ToString() + "/" + DateTimePickerTo.Value.Day.ToString() + "/" + DateTimePickerTo.Value.Year.ToString();
         DateFrom = DateTimePickerFrom.Value.Month.ToString() + "/" + DateTimePickerFrom.Value.Day.ToString() + "/" + DateTimePickerFrom.Value.Year.ToString();
         ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
         if (TextBoxVehicleNo.Text != "")
         {
             try
             {
                 DataTable dt = new DataTable();
                 DatabaseConnectObj.SqlQuery("SELECT VehicleNo, Date FROM Schedule WHERE (VehicleNo = '" + TextBoxVehicleNo.Text + "') AND (Date BETWEEN '" + DateFrom + "' AND '" + DateTo + "')");
                 dt = DatabaseConnectObj.ExecuteQuery();
                 dataGridView1.DataSource = dt;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
             finally
             {
                 DatabaseConnectObj.DatabaseConnectionClose();
             }
         }
         else
         {
             try
             {
                 DataTable dt = new DataTable();
                 DatabaseConnectObj.SqlQuery("SELECT VehicleNo, Date FROM Schedule WHERE (Date BETWEEN '" + DateFrom + "' AND '" + DateTo + "')");
                 dt = DatabaseConnectObj.ExecuteQuery();
                 dataGridView1.DataSource = dt;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
             finally
             {
                 DatabaseConnectObj.DatabaseConnectionClose();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #21
0
 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 = "";
         }
     }
 }
コード例 #22
0
 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");
         }
     }
 }
コード例 #23
0
        private void getCustomerData()
        {
            ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();

            try
            {
                DatabaseConnectObj.SqlQuery("SELECT CustomerId, CustomerName, CustomerNo, VehicleNo, VehicleId FROM dbo.Customer");
                customerData = DatabaseConnectObj.ExecuteQuery();
            }
            catch (Exception ex)
            {
                string output = ex.Message + " getCustomerData"; MessageBox.Show(output);
            }
            finally
            {
                DatabaseConnectObj.DatabaseConnectionClose();
            }
        }
コード例 #24
0
        private void getVehicleData()
        {
            ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();

            try
            {
                DatabaseConnectObj.SqlQuery("SELECT Id, VehicleType, VehicleName FROM dbo.Vehicle");
                vehicledata = DatabaseConnectObj.ExecuteQuery();
            }
            catch (Exception ex)
            {
                string output = ex.Message + " getVehicleData"; MessageBox.Show(output);
            }
            finally
            {
                DatabaseConnectObj.DatabaseConnectionClose();
            }
        }
コード例 #25
0
        private void getLaboursData()
        {
            ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();

            try
            {
                DatabaseConnectObj.SqlQuery("SELECT LabourId, LabourName, LabourDesc, LabourPrice FROM Labour");
                laboursdata = DatabaseConnectObj.ExecuteQuery();
            }
            catch (Exception ex)
            {
                string output = ex.Message + " getLaboursData"; MessageBox.Show(output);
            }
            finally
            {
                DatabaseConnectObj.DatabaseConnectionClose();
            }
        }
コード例 #26
0
        private void getItemsData()
        {
            ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();

            try
            {
                DatabaseConnectObj.SqlQuery("SELECT ItemId, ItemName, ItemDesc, ItemPrice, VehicleId FROM dbo.Items");
                itemsData = DatabaseConnectObj.ExecuteQuery();
            }
            catch (Exception ex)
            {
                string output = ex.Message + " getItemsData"; MessageBox.Show(output);
            }
            finally
            {
                DatabaseConnectObj.DatabaseConnectionClose();
            }
        }
コード例 #27
0
 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");
     }
 }
コード例 #28
0
        private void loadCustomerAndVehicleData()
        {
            ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();

            try
            {
                DataTable dt = new DataTable();
                DatabaseConnectObj.SqlQuery("SELECT Customer.CustomerName, Customer.CustomerNo, Customer.VehicleNo, Vehicle.VehicleType, Vehicle.VehicleName FROM Customer INNER JOIN Vehicle ON Customer.VehicleId = Vehicle.Id");
                dt = DatabaseConnectObj.ExecuteQuery();
                dataCustomerAndVehicle = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DatabaseConnectObj.DatabaseConnectionClose();
            }
        }
コード例 #29
0
 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();
         }
     }
 }
コード例 #30
0
        private void ButtonSelect_Click(object sender, EventArgs e)
        {
            String temp = "";

            for (int i = 0; i < CheckBoxListCusList.Items.Count; i++)
            {
                if (CheckBoxListCusList.GetItemChecked(i))
                {
                    String[] sub   = CheckBoxListCusList.Items[i].ToString().Split('(');
                    String[] temp2 = sub[1].Split(')');
                    try
                    {
                        ClassDatabaseConnection DatabaseConnectObj = new ClassDatabaseConnection();
                        try
                        {
                            DataTable dt = new DataTable();
                            DatabaseConnectObj.SqlQuery("SELECT CustomerNo FROM Customer where VehicleNo = '" + temp2[0].Trim() + "'");
                            dt = DatabaseConnectObj.ExecuteQuery();
                            DataRow row = dt.Rows[0];
                            temp = temp + " " + row["CustomerNo"].ToString() + ",";
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        finally
                        {
                            DatabaseConnectObj.DatabaseConnectionClose();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            this.Close();
        }