Exemplo n.º 1
0
 private void btnApply_Click(object sender, EventArgs e)
 {
     SqlConnector.Connect();
     try
     {
         if (FieldValidator.CheckFilledTextBoxes(this) && FieldValidator.AreFieldsValid(this))
         {
             if (checkModifications == 0)
             {
                 List <string> AllNewUserData     = AddToList(tbFirstname.Text, tbLastname.Text, tbEmail.Text, tbPhone.Text, tbStreetnumber.Text, tbPostalcode.Text, tbCity.Text, tbProvince.Text, tbCompanyEmail.Text, tbCompanyPhone.Text, tbCompany.Text, tbInsurance.Text, tbFaxnumber.Text);
                 string        columsInRightOrder = " firstname, lastname, email, phonenumber, homenumber, postalCode1, city1, province, email_company, phonenumber_company, companyName, insurance_id, faxnumber";
                 SqlConnector.InsertDataIntoDatabase(AllNewUserData, columsInRightOrder, "Tbl_Customers");
                 isCustomerAdded = true;
             }
             else if (checkModifications == 4)
             {
                 List <string> AllNewUserData     = AddToList(tbFirstname.Text, tbLastname.Text, tbCompany.Text, tbCompanyEmail.Text, tbCompanyPhone.Text, tbEmail.Text, tbPostalcode.Text, tbCity.Text, tbStreetnumber.Text, tbProvince.Text, tbPhone.Text, tbFaxnumber.Text, tbInsurance.Text);
                 string        columsInRightOrder = " firstname, lastname, companyName, email_company, phonenumber_company, email, postalCode1, city1, homenumber, province, phonenumber, faxnumber, insurance_id";
                 SqlConnector.modifyDatabase(AllNewUserData, ((ViewPanel)lastPanel).GetSelectedId(0), columsInRightOrder, "Tbl_Customers", "project");
                 isCustomerAdded = true;
             }
         }
         else
         {
             isCustomerAdded = false;
             MessageBox.Show("Please insert the right values.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
     finally
     {
         if (isCustomerAdded)
         {
             if (checkModifications == 0)
             {
                 MessageBox.Show("You have succesfully modified a customer, this form will close now.");
                 this.Close();
             }
             else
             {
                 MessageBox.Show("You have succesfully added a customer, this form will close now.");
                 this.Close();
             }
         }
     }
 }
Exemplo n.º 2
0
        private void SaveProject(object sender, EventArgs e)
        {
            SqlConnector.Connect();
            if ((!cbCustomer.Enabled || cbCustomer.SelectedIndex != 0 && cbCustomer.SelectedItem != null) && isInt(tbPrice.Text) && FieldValidator.CheckFilledTextBoxes(this))
            {
                SqlConnector.Connect();
                List <string> dataList;
                if (checkModifications == 1)
                {
                    int currentCustomerId = ((ViewPanel)lastPanel).GetSelectedId(1);
                    dataList = AddToList(((ViewPanel)lastPanel).GetSelectedId(0).ToString(), currentCustomerId.ToString(), tbProjectName.Text, tbDescription.Text, tbPrice.Text);
                }
                else
                {
                    dataList = AddToList(cbCustomer.GetSelectedId().ToString(), tbProjectName.Text, tbDescription.Text, tbPrice.Text);
                }

                string colums = " Customer_id, name, description, price";

                if (cbDeadLine.Checked)
                {
                    dataList.Add(datePicker.Text);
                    colums += ", deadline";
                }

                if (checkModifications == 1 && SqlConnector.modifyDatabase(dataList, ((ViewPanel)lastPanel).GetSelectedId(1), colums, "Tbl_Projects", "invoice"))
                {
                    MessageBox.Show("The project has been succesfully submitted to the server.",
                                    "Successfully saved the project.");
                    SqlConnector.Connect();
                    Close();
                }
                else if (SqlConnector.InsertDataIntoDatabase(dataList, colums, "Tbl_Projects"))
                {
                    MessageBox.Show("The project has been succesfully submitted to the server.",
                                    "Successfully saved the project.");
                    SqlConnector.Connect();
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Unable to save project. Are you sure all fields are filled in correctly and are you sure you selected a customer?",
                                "Error saving Project");
            }
        }