Esempio n. 1
0
        // Save the data entered in the form as a Job in the database.
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (_homeMenuForm.IsOnline() && DataFilled())
            {
                try
                {
                    this.getClientsTableAdapter.Fill(this.agileDevelopmentDataSet.GetClients);
                }
                catch
                {
                    MessageBox.Show("Error: A problem has occured while trying to access the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }


                try
                {
                    int ClientID = Convert.ToInt32(((ComboboxItem)comboBox_clientID.SelectedItem).Value);
                    queriesTableAdapter1.CreateJob(ClientID, txt_shortDescription.Text, txt_location.Text, (byte)numUD_priority.Value, date_startTime.Value, null, 0, false);
                    queriesTableAdapter1.Dispose();
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Error: A problem has occured while trying to access the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Esempio n. 2
0
        // Save the Client information to the database.
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (_homeMenuForm.IsOnline() && DataFilled())
            {
                try
                {
                    queriesTableAdapter1.CreateClient(txt_name.Text, txt_address.Text, txt_landLine.Text, txt_mobilePhone.Text, txt_email.Text, txt_businessName.Text);

                    //Make the query safe.
                    queriesTableAdapter1.Dispose();
                    this.Close();
                }
                catch { Console.Out.WriteLine("oops"); }
            }
        }
Esempio n. 3
0
 // Create the employee in the database.
 private void btn_submit_Click(object sender, EventArgs e)
 {
     if (_homeMenuForm.IsOnline() && DataFilled())
     {
         try
         {
             queriesTableAdapter1.CreateEmployee(txt_name.Text, txt_address.Text, txt_landLine.Text, txt_mobilePhone.Text, txt_email.Text);
             queriesTableAdapter1.Dispose();
             this.Close();
         }
         catch
         {
             MessageBox.Show("Error: A problem has occured while trying to access the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Esempio n. 4
0
        // Create a new Shift in the database.
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (_homeMenuForm.IsOnline() && DataFilled())
            {
                try
                {
                    int EmployeeID = Convert.ToInt32(((ComboboxItem)comboBox_employeeID.SelectedItem).Value);
                    int JobID      = Convert.ToInt32(((ComboboxItem)comboBox_job.SelectedItem).Value);
                    queriesTableAdapter1.CreateShift(EmployeeID, JobID, date_startTime.Value, date_endTime.Value);

                    //Make the query safe.
                    queriesTableAdapter1.Dispose();
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Error: A problem has occured while trying to access the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Esempio n. 5
0
        // Export data from the database into a file that is readable by the offline version of the program.
        private void btn_export_Click(object sender, EventArgs e)
        {
            if (_homeMenuForm.IsOnline())
            {
                Package  p     = new Package();
                DateTime Start = date_startTime.Value;
                DateTime End   = date_endTime.Value;

                //fetches data from sql server
                DataTable table = getShiftForEmployeeTableAdapter1.GetData(Convert.ToInt32(((ComboboxItem)comboBox_employeeID.SelectedItem).Value), Start, End);
                //counting rows
                Console.WriteLine(table.Rows.Count);
                //for each row
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    Console.WriteLine("Writing Shift");
                    //New Shift
                    ContractShift newShift = new ContractShift();
                    newShift.StartTime = DateTime.Parse(table.Rows[i][1].ToString());
                    newShift.EndTime   = DateTime.Parse(table.Rows[i][2].ToString());
                    newShift.JobID     = int.Parse(table.Rows[i][3].ToString());
                    Console.WriteLine(newShift.ToString());

                    //New Job if Job doesn't already exist
                    int JobID = int.Parse(table.Rows[i][3].ToString());
                    if (p.UniqueJobID(JobID))
                    {
                        Job newJob = new Job();
                        newJob.ID = JobID;
                        newJob.ShortDescription = (String)table.Rows[i][4].ToString();
                        newJob.Ordered          = DateTime.Parse(table.Rows[i][5].ToString());
                        newJob.Location         = (String)table.Rows[i][6].ToString();
                        newJob.priority         = int.Parse(table.Rows[i][7].ToString());
                        newJob.StartTime        = DateTime.Parse(table.Rows[i][8].ToString());
                        try
                        {
                            newJob.CompletionTime = DateTime.Parse(table.Rows[i][9].ToString());
                        }
                        catch { }//oops
                        newJob.Charged = decimal.Parse(table.Rows[i][10].ToString());
                        newJob.Paid    = Boolean.Parse(table.Rows[i][11].ToString());

                        //Client info
                        Client client = new Client();
                        client.id           = int.Parse(table.Rows[i][13].ToString());
                        client.name         = (String)table.Rows[i][14].ToString();
                        client.BusinessName = (String)table.Rows[i][12].ToString();
                        client.address      = (String)table.Rows[i][15].ToString();
                        try
                        {
                            client.SetLandLine(int.Parse(table.Rows[i][16].ToString()));
                        }
                        catch { client.SetLandLine(0); } // Default value.
                        try
                        {
                            client.SetMobile(int.Parse(table.Rows[i][17].ToString()));
                        }
                        catch { client.SetMobile(0); }
                        client.email = (String)table.Rows[i][18].ToString();


                        p.AddClient(client);


                        //add client to Job
                        newJob.client = p.getClient(client.id);

                        //setting values of the new Job
                        p.AddJob(newJob);
                    }

                    p.AddShift(newShift);
                }

                //get contractor info here
                DataTable employeeTable = getEmployeesTableAdapter.GetData();
                DataRow   employeeRow   = null;
                for (int i = 0; i < employeeTable.Rows.Count; i++)
                {
                    if (employeeTable.Rows[i][0].ToString() == ((ComboboxItem)comboBox_employeeID.SelectedItem).Value.ToString())
                    {
                        employeeRow = employeeTable.Rows[i];
                        i           = employeeTable.Rows.Count;
                    }
                }

                //attempt to fix issue
                p.Contractor.EmployeeID = int.Parse(table.Rows[0][0].ToString());
                p.Contractor.name       = employeeRow[2].ToString();

                //save file
                p.Serialise();
            }
        }