Exemplo n.º 1
0
        private void AssignEmployeeJobRegisterButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CheckForEmpty(this.AssignEmplyeeJobGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }

                // look for fields in the tables
                AllContainer = new Container();
                DB1 = new DBManager();
                AllContainer = DB1.GetWholeEntity();

                var result = from item in AllContainer._employeeslist
                             where item.employee_name.ToLower().Contains(this.AssignEmployeejobEmployeeNameTextbox.Text.ToLower())
                             select item;
                // get the id of the first value found
                employees emp = (employees)result.ToList().First();

                var rs = from item in AllContainer._job_typelist
                         where item.job_name.ToLower().Contains(this.AssignEmployeeJobJobNameTextBox.Text.ToLower())
                         select item;
                job_type job = (job_type)rs.ToList().First();

                // get the values from the two entities so as to merge them
                Container Entity1 = new Container();
                Entity1._job_description.employee_id = emp.employee_id;
                Entity1._job_description.job_type_id = job.job_type_id;
                if (DB1.InsertValue(Entity1, Constants.Job_Description))
                {
                    MessageBox.Show("the job description has been registered");
                    EmptyAllfields(this.AssignEmplyeeJobGrid);
                    RefreshContainer();
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        // function to get a whole table from the database
        public Container GetWholeEntity()
        {
            try
            {
                // switch based on the option
                string CmdText = "";
                Container c = new Container();
                if (Connect())
                {
                    // get all clients
                    {
                        CmdText = "SELECT * FROM clients ";
                        datareader = GetReader(CmdText);
                        c._clientlist = new List<clients>();
                        while (datareader.Read())
                        {
                            clients Client = new clients();
                            Client.client_id = Convert.ToInt32(datareader["client_id"]);
                            Client.client_name = datareader["client_name"].ToString();
                            Client.email = datareader["email"].ToString();
                            Client.contact = datareader["contact"].ToString();
                            c._clientlist.Add(Client);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    // get all employees
                    {
                        CmdText = "SELECT * FROM employees ";
                        datareader = GetReader(CmdText);
                        c._employeeslist = new List<employees>();
                        while (datareader.Read())
                        {

                            employees emp = new employees();
                            emp.employee_name = datareader["employee_name"].ToString();
                            emp.employee_contact_number = datareader["employee_contact_number"].ToString();
                            emp.employee_id = Convert.ToInt32(datareader["employee_id"].ToString());
                            c._employeeslist.Add(emp);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    //get all job types
                    {
                        CmdText = "SELECT * FROM job_type ";
                        datareader = GetReader(CmdText);
                        c._job_typelist = new List<job_type>();
                        while (datareader.Read())
                        {
                            job_type job = new job_type();
                            job.job_name = datareader["job_name"].ToString();
                            job.job_type_id = Convert.ToInt32(datareader["job_type_id"].ToString());
                            job.unit_pay = Convert.ToInt32(datareader["unit_pay"].ToString());
                            c._job_typelist.Add(job);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    // get all projects
                    {
                        CmdText = "SELECT * FROM Projects ";
                        datareader = GetReader(CmdText);
                        c._projectlist = new List<projects>();
                        while (datareader.Read())
                        {
                            projects proj = new projects();
                            proj.project_id = Convert.ToInt32(datareader["project_id"].ToString());
                            proj.project_name = datareader["project_name"].ToString();
                            proj.location = datareader["location"].ToString();
                            proj.description = datareader["description"].ToString();
                            proj.start_date = Convert.ToDateTime(datareader["start_date"].ToString());
                            proj.end_date = Convert.ToDateTime(datareader["end_Date"].ToString());
                            proj.status = datareader["status"].ToString();
                            proj.client_id = Convert.ToInt32(datareader["client_id"].ToString());
                            c._projectlist.Add(proj);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    // get all stock material names
                    {
                        CmdText = "SELECT * FROM stock_materials";
                        datareader = GetReader(CmdText);
                        c._stock_materialslist = new List<stock_materials>();
                        while (datareader.Read())
                        {
                            stock_materials stock = new stock_materials();
                            stock.stock_id = Convert.ToInt32(datareader["stock_id"]);
                            stock.material_id = Convert.ToInt32(datareader["material_id"]);
                            stock.quanitity = Convert.ToInt32(datareader["quantity"]);
                            c._stock_materialslist.Add(stock);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    // get all material names
                    {
                        CmdText = "SELECT * FROM materials";
                        datareader = GetReader(CmdText);
                        c._materialslist = new List<materials>();
                        while (datareader.Read())
                        {
                            materials mat = new materials();
                            mat.material_id = Convert.ToInt16(datareader["material_id"]);
                            mat.material_name = datareader["material_name"].ToString();
                            mat.measuring_unit = datareader["measuring_unit"].ToString();
                            c._materialslist.Add(mat);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    //get all tasks
                    {
                        CmdText = "SELECT * FROM tasks";
                        datareader = GetReader(CmdText);
                        c._tasklist = new List<task>();
                        while (datareader.Read())
                        {
                            task t = new task();
                            t.task_id = Convert.ToInt32(datareader["task_id"].ToString());
                            t.task_name = datareader["task_name"].ToString();
                            t.start_date = Convert.ToDateTime(datareader["start_date"].ToString());
                            t.end_date = Convert.ToDateTime(datareader["end_date"].ToString());
                            t.budget = Convert.ToInt32(datareader["budget"].ToString());
                            t.status = datareader["status"].ToString();
                            t.employee_id = Convert.ToInt32(datareader["employee_id"]);
                            t.project_id = Convert.ToInt32(datareader["project_id"].ToString());
                            c._tasklist.Add(t);
                        }
                        datareader.Close();
                        datareader = null;
                    }

                    return c;
                }
                else { return null; }

            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 3
0
        public MySqlCommand GenerateCommand(Container c, string entitytype)
        {
            string CmdText = null;
            //MySqlCommand cmd = new MySqlCommand();
            try
            {
                switch (entitytype)
                {
                    case Constants.Project:
                        CmdText = "INSERT INTO projects( project_id , project_name , location , description ,start_date , end_date  , client_id ) VALUES(@project_id , @project_name , @location, @description , @start_date , @end_date , @client_id )";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add nodes to the values
                        cmd.Parameters.AddWithValue("@project_id", null);
                        cmd.Parameters.AddWithValue("@project_name", c._project.project_name);
                        cmd.Parameters.AddWithValue("@location", c._project.location);
                        cmd.Parameters.AddWithValue("@description", c._project.description);
                        cmd.Parameters.AddWithValue("@start_date", c._project.start_date);
                        cmd.Parameters.AddWithValue("@end_date", c._project.end_date);
                        cmd.Parameters.AddWithValue("@client_id", c._project.client_id);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        string tmp = cmd.CommandText.ToString();
                        foreach (MySql.Data.MySqlClient.MySqlParameter p in cmd.Parameters)
                        {
                            try
                            {
                                tmp = tmp.Replace('@' + p.ParameterName.ToString(), "'" + p.Value.ToString() + "'");
                            }
                            catch { }

                        }
                        Debug.WriteLine(tmp);
                        break;
                    case Constants.Task:
                        CmdText = "INSERT INTO tasks( task_id , project_id , budget , start_date , end_date , employee_id , task_name  ) VALUES ( @task_id , @project_id , @budget , @start_date , @end_date , @employee_id ,@task_name )";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add nodes to the values
                        cmd.Parameters.AddWithValue("@task_id", null);
                        cmd.Parameters.AddWithValue("@project_id", c._task.project_id);
                        cmd.Parameters.AddWithValue("@budget", c._task.budget);
                        cmd.Parameters.AddWithValue("@start_date", c._task.start_date);
                        cmd.Parameters.AddWithValue("@end_date", c._task.end_date);
                        cmd.Parameters.AddWithValue("@employee_id", c._task.employee_id);
                        cmd.Parameters.AddWithValue("@task_name", c._task.task_name);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Client:
                        CmdText = "INSERT INTO clients(client_id , client_name , email , contact ) VALUES( @client_id , @client_name , @email , @contact)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the nodes
                        cmd.Parameters.AddWithValue("@client_id", null);
                        cmd.Parameters.AddWithValue("@client_name", c._client.client_name);
                        cmd.Parameters.AddWithValue("@email", c._client.email);
                        cmd.Parameters.AddWithValue("@contact", c._client.contact);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Materials:
                        CmdText = "INSERT INTO materials( material_id , material_name , measuring_unit ) VALUES( @material_id , @material_name , @measuring_unit )";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@material_id", null);
                        cmd.Parameters.AddWithValue("@material_name", c._materials.material_name);
                        cmd.Parameters.AddWithValue("@measuring_unit", c._materials.measuring_unit);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Stock_Materails:
                        CmdText = "INSERT INTO stock_materials(stock_id ,material_id, quantity) VALUES(@stock_id ,@material_id, @quantity)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@stock_id", null);
                        cmd.Parameters.AddWithValue("@material_id", c._stock_materials.material_id);
                        cmd.Parameters.AddWithValue("@quantity", c._stock_materials.quanitity);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Job_Description:
                        CmdText = "INSERT INTO job_description ( employee_id , job_type_id , job_description_id ) VALUES( @employee_id, @job_type_id, @job_description_id)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@employee_id", c._job_description.employee_id);
                        cmd.Parameters.AddWithValue("@job_type_id", c._job_description.job_type_id);
                        cmd.Parameters.AddWithValue("@job_description_id", null);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Job_Type:
                        CmdText = "INSERT INTO job_type(job_type_id, job_name, unit_pay) VALUES(@job_type_id, @job_name, @unit_pay)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@job_type_id", null);
                        cmd.Parameters.AddWithValue("@job_name", c._job_type.job_name);
                        cmd.Parameters.AddWithValue("@unit_pay", c._job_type.unit_pay);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.employees:
                        CmdText = "INSERT INTO employees(employee_id, employee_name, employee_contact_number) VALUES(@employee_id, @employee_name, @employee_contact_number)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@employee_id", null);
                        cmd.Parameters.AddWithValue("@employee_name", c._employees.employee_name);
                        cmd.Parameters.AddWithValue("@employee_contact_number", c._employees.employee_contact_number);
                        Debug.WriteLine(cmd.Parameters.ToString());
                        break;
                    case Constants.Project_Labour_Allocation:
                        CmdText = "INSERT INTO project_labour_allocation ( project_labour_allocation_id , labourer_id, project_id ) VALUES ( @project_labour_allocation_id , @labourer_id,  @project_id )";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@project_labour_allocation_id",null);
                        cmd.Parameters.AddWithValue("@labourer_id", c._project_labour_allocation.labourer_id);
                        cmd.Parameters.AddWithValue("@project_id", c._project_labour_allocation.project_id);
                        Debug.WriteLine(cmd.Parameters.ToString());
                        break;
                    case  Constants.Project_Labour_Working_Day:
                        CmdText = "INSERT INTO project_labour_working_day ( project_labour_allocation_id , working_date) VALUES ( @project_labour_allocation_id , @working_date)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@project_labour_allocation_id", c._project_labour_working_day.project_labour_allocation_id);
                        cmd.Parameters.AddWithValue("@working_date", c._project_labour_working_day.working_date);
                        break;
                    case Constants.Project_Employee_Allocation:
                        CmdText = "INSERT INTO project_employee_allocation( project_employee_allocation_id , employee_id , project_id ) VALUES ( @project_employee_allocation_id , @employee_id , @project_id )";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add node values
                        cmd.Parameters.AddWithValue("@project_employee_allocation_id", null);
                        cmd.Parameters.AddWithValue("@employee_id", c._project_employee_allocation.employee_id);
                        cmd.Parameters.AddWithValue("@project_id", c._project_employee_allocation.project_id);
                        break;
                    case Constants.Project_employee_Working_Day:
                        CmdText = "INSERT INTO project_employee_Working_day (project_employee_allocation_id , working_date) VALUES (@project_employee_allocation_id , @working_date) ";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@project_employee_allocation_id", c._project_employee_working_day.project_employee_allocation_id);
                        cmd.Parameters.AddWithValue("@working_date", c._project_employee_working_day.working_date);
                        break;
                    case Constants.Task_Materials:
                        CmdText = "INSERT INTO task_materials ( task_material_id , task_id , material_id , quantity , unit_buying_price , date_allocated ) VALUES ( @task_material_id , @task_id  , @material_id, @quantity , @unit_buying_price , @date_allocated)";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@task_material_id", c._task_materials.task_materials_id);
                        cmd.Parameters.AddWithValue("@task_id", c._task_materials.task_id);
                        cmd.Parameters.AddWithValue("@material_id", c._task_materials.material_id);
                        cmd.Parameters.AddWithValue("@quantity", c._task_materials.quantity);
                        cmd.Parameters.AddWithValue("@unit_buying_price", c._task_materials.unit_buying_price);
                        cmd.Parameters.AddWithValue("@date_allocated", c._task_materials.date_allocated);
                        Debug.WriteLine(cmd.CommandText.ToString());
                        break;
                    case Constants.Labourers:
                        CmdText = "INSERT INTO labourers (labourer_id , labourer_name , labourer_contact , national_id ) VALUES ( @labourer_id , @labourer_name , @labourer_contact , @national_id ); ";
                        cmd = new MySqlCommand(CmdText, this.conn);
                        // add the node values
                        cmd.Parameters.AddWithValue("@labourer_id", c._labourers.labourer_id);
                        cmd.Parameters.AddWithValue("@labourer_name", c._labourers.labourer_name);
                        cmd.Parameters.AddWithValue("@labourer_contact", c._labourers.labourer_contact);
                        cmd.Parameters.AddWithValue("@national_id", c._labourers.national_id);
                        break;
                }

                return cmd;
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 4
0
 public bool InsertValue(Container c, string option)
 {
     try
     {
         MySqlCommand InsertCommand = new MySqlCommand();
         // get a connection to the database
         if (Connect())
         {
             // enter the value
             // get a command
             InsertCommand = GenerateCommand(c, option);
             InsertCommand.ExecuteNonQuery();
             return true;
         }
         else
         {
             Debug.WriteLine("Unable to connect or insert into the database ");
             return false;
         }
     }
     catch (Exception exp)
     {
         Debug.WriteLine(exp.Message);
         return false;
     }
 }
Exemplo n.º 5
0
        private void RegisterStockCreateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // check for empty value
                CheckForEmpty(this.RegisterStockGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }

                // check if the material already exists
                if (this.AllContainer._employeeslist.Count == 0)
                {
                    RefreshContainer();
                }

                // get the list of all materials
                var result = from item in AllContainer._materialslist
                             where (item.material_name.ToLower().Contains(this.RegisterStockMaterialNameTextBox.Text))
                             select item;
                if (result.Count() > 0)
                {
                    // get the id of the material
                    int material_id = (from _mat in (List<materials>)result.ToList() select (_mat.material_id)).ToList().First();

                    //find the row with the material id provided
                    var s = from item in AllContainer._stock_materialslist
                            where (item.material_id == material_id)
                            select item;
                    if (s.Count() > 0)
                    {
                        stock_materials stock = ((List<stock_materials>)s.ToList()).First();

                        // change the values of the quantity of the stock
                        stock.quanitity += Convert.ToInt32(this.RegisterStockQuantityTextBox.Text);

                        //update the db

                        if (DB1.UpdateValue(stock))
                        {
                            MessageBox.Show("Stock has been updated");
                        }
                        EmptyAllfields(this.RegisterStockGrid);
                    }
                    else
                    {
                        // create a new row for the material
                        Container Entity1 = new Container();
                        Entity1._stock_materials = new stock_materials();
                        Entity1._stock_materials.material_id = material_id;
                        Entity1._stock_materials.quanitity = Convert.ToInt32(this.RegisterStockQuantityTextBox.Text);
                        DB1 = new DBManager();
                        if (DB1.InsertValue(Entity1, Constants.Stock_Materails))
                        {
                            MessageBox.Show("New value entered successfull");
                            EmptyAllfields(this.RegisterStockGrid);
                            RefreshContainer();
                        }
                    }
                }

            }
            catch { }
        }
Exemplo n.º 6
0
        private void RegisterMaterialCreateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // check for empty value
                CheckForEmpty(this.RegisterMaterialsGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }

                // get the values from the fields
                Container Entity1 = new Container();
                Entity1._materials.material_name = this.RegisterMaterialMaterialNameTextBox.Text;
                Entity1._materials.measuring_unit = this.RegisterMaterialMeasuringUnitTextBox.Text;
                DB1 = new DBManager();
                if (DB1.InsertValue(Entity1, Constants.Materials))
                {
                    MessageBox.Show("has been successfully registered");
                    EmptyAllfields(this.RegisterMaterialsGrid);
                    RefreshContainer();
                }
            }
            catch { }
        }
Exemplo n.º 7
0
        private void AssignProjectEmployeeAssignButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // check for empty value
                CheckForEmpty(this.AssignProjectEmployeeGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }
            }
            catch
            { }
            try
            {
                // get the details of employee and project
                DB1 = new DBManager();
                projects prj = (projects)DB1.GetProjects("SELECT * FROM projects where project_name = '" + this.AssignProjectEmployeeProjectNameTextBox.Text + "'").First();
                employees emp = (employees)DB1.GetEmployees("SELECT * FROM employees WHERE employee_name = '" + this.AssignProjectEmployeeEmployeeNameComboBox.SelectedItem.ToString() + "'").First();
                Container c = new Container();
                c._project_employee_allocation = new project_employee_allocation();
                c._project_employee_allocation.employee_id = emp.employee_id;
                c._project_employee_allocation.project_id = prj.project_id;

                if (DB1.InsertValue(c, Constants.Project_Employee_Allocation))
                {
                    MessageBox.Show("Employee allocated");
                    EmptyAllfields(this.AssignProjectEmployeeGrid);
                    RefreshContainer();
                }
            }
            catch { }
        }
Exemplo n.º 8
0
 private void RegisterEmployeeButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         // check for empty value
         CheckForEmpty(this.RegisterEmployeeGrid);
         if (this.textboxstatus == false)
         {
             MessageBox.Show("A field has not been entered");
             textboxstatus = false;
             return;
         }
     }
     catch
     { }
     try
     {
         // get the name of the employee
         Container Entity1 = new Container();
         Entity1._employees.employee_id = 0;
         Entity1._employees.employee_name = this.RegisterEmployeeNameTextBox.Text;
         Entity1._employees.employee_contact_number = this.RegisterEmployeeContactNumberTextBox.Text;
         DBManager DB1 = new DBManager();
         if (DB1.InsertValue(Entity1, Constants.employees))
         {
             MessageBox.Show(this.RegisterEmployeeNameTextBox.Text + " has been successfully registered");
             EmptyAllfields(this.RegisterEmployeeGrid);
             RefreshContainer();
         }
         else
         {
             MessageBox.Show("There was a problem entering data to the database");
             EmptyAllfields(this.RegisterEmployeeGrid);
             RefreshContainer();
         }
     }
     catch { }
 }
Exemplo n.º 9
0
        private void RegisterClientButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                try
                {
                    // check for empty value
                    CheckForEmpty(this.RegisterClientGrid);
                    if (this.textboxstatus == false)
                    {
                        MessageBox.Show("A field has not been entered");
                        textboxstatus = false;
                        return;
                    }
                }
                catch
                { }

                // get the name of the client
                Container Entity1 = new Container();
                Entity1._client.client_name = this.RegisterClientNameTextBox.Text;
                Entity1._client.email = this.RegisterClientEmailTextBox.Text;
                Entity1._client.contact = this.RegisterClientEmailTextBox.Text;
                Entity1._client.client_id = 0;
                DBManager DB1 = new DBManager();
                if (DB1.InsertValue(Entity1, Constants.Client))
                {
                    MessageBox.Show("has been successfully registered");
                    EmptyAllfields(this.RegisterClientGrid);
                    RefreshContainer();
                }
            }
            catch { }
        }
Exemplo n.º 10
0
        private void RefreshContainer()
        {
            DBManager DB1 = new DBManager();

            this.AllContainer = DB1.GetWholeEntity();
        }
Exemplo n.º 11
0
        private void CreateProject_Click(object sender, RoutedEventArgs e)
        {
            // get all the values from the
            // check if any of the values is left empty
            try
            {

                // check for empty ness
                CheckForEmpty(this.RegisterProjectGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }

                try
                {

                    Container Entity1 = new Container();
                    Entity1._project.project_id = 0;
                    Entity1._project.project_name = this.RegisterProjectProjectNameTextBox.Text;
                    Entity1._project.location = this.RegisterProjectLocationTextBox.Text;
                    Entity1._project.description = this.RegisterProjectDescriptionTextBox.Text;
                    Entity1._project.end_date = (DateTime)this.RegisterProjectEndDatePicker.SelectedDate;
                    Entity1._project.start_date = (DateTime)this.RegisterProjectStartDatePicker.SelectedDate;

                    // get the client
                    try
                    {
                        Container container1 = new Container();
                        DB1 = new DBManager();
                        container1 = DB1.GetWholeEntity();
                        List<clients> cc = container1._clientlist;
                        var result = from item in cc
                                     where item.client_name.ToLower().Contains(this.RegisterProjectClientTextBox.Text.ToLower())
                                     select item;

                        if (result != null)
                        {
                            Entity1._project.client_id = Convert.ToInt32(((List<clients>)result.ToList()).First().client_id);
                        }

                    }
                    catch { }

                    if (DB1.InsertValue(Entity1, Constants.Project))
                    {
                        MessageBox.Show("The Project has been registered successfully");
                        EmptyAllfields(this.RegisterProjectGrid);
                    }
                }
                catch { }

            }
            catch { }
        }
Exemplo n.º 12
0
        private void AssignTaskMaterialsAssignButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                RefreshContainer();
                // check for empty value
                CheckForEmpty(this.AssignTaskMaterialsGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }
                // check if the material already exists
                if (this.AllContainer._employeeslist.Count == 0)
                {
                    RefreshContainer();
                }

                // get the detials of the assignment
                Container Entity1 = new Container();
                Entity1._task_materials = new task_materials();

                //get the project id
                var projectresult = from item in DB1.GetProjects("")
                                    where ((item.project_name).Contains(this.AssignTaskMaterialsProjectNameTextBox.Text))
                                    select item;
                int pid = projectresult.ToList().First().project_id;

                // get the task id
                var taskresult = from item in AllContainer._tasklist
                                 where (  (item.task_name.ToLower().Contains(this.AssignTaskMaterialsTaskNameTextBox.Text.ToLower())  ) && (item.project_id == pid)  )
                                 select item;
                if (taskresult.Count() > 0)
                {
                    // get the first id
                    Entity1._task_materials.task_id = taskresult.ToList().First().task_id;
                }
                else
                {
                    return;
                }

                //get the material id
                var materialresult = from item in AllContainer._materialslist
                                     where (item.material_name.ToLower().Contains(this.AssignTaskMaterialsMaterialNameTextBox.Text.ToLower()))
                                     select item;
                if (materialresult.Count() > 0)
                {
                    Entity1._task_materials.material_id = materialresult.ToList().First().material_id;
                }
                else
                {
                    return;
                }

                // get the type of assignment the administrator wishes to do
                MessageBoxResult r = MessageBox.Show("Do you wish to assign from stock", "Assign materials", MessageBoxButton.YesNoCancel);
                if (r == MessageBoxResult.Yes)
                {
                    // remove the values from the stock and update it
                    Entity1._task_materials.unit_buying_price = 0;

                    //update the stock
                    stock_materials s = DB1.GetStock("SELECT * FROM stock_materials WHERE material_id = " + Entity1._task_materials.material_id).First();
                    s.quanitity -= Convert.ToInt32(this.AssignTaskMaterialsQuantityTextBox.Text);
                    DB1.UpdateValue(s);
                }
                else if (r == MessageBoxResult.No)
                {
                    Entity1._task_materials.unit_buying_price = Convert.ToInt32(this.AssignTaskMaterialsUnitBuyingPriceTextBox.Text);
                }
                else if (r == MessageBoxResult.Cancel)
                {
                    return;
                }

                Entity1._task_materials.quantity = Convert.ToInt32(this.AssignTaskMaterialsQuantityTextBox.Text);
                Entity1._task_materials.date_allocated = DateTime.Now;

                DB1 = new DBManager();
                if (DB1.InsertValue(Entity1, Constants.Task_Materials))
                {
                    MessageBox.Show("the materials have been allocated");
                    EmptyAllfields(this.AssignTaskMaterialsGrid);
                    RefreshContainer();
                }

            }
            catch { }
        }
Exemplo n.º 13
0
        private void UpdateProjectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // check for empty ness
                CheckForEmpty(this.UpdateProjectGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }
                DB1 = new DBManager();

                Container Entity1 = new Container();
                Entity1._project.project_id = DB1.GetProjects("SELECT * FROM projects WHERE project_name = '" + this.UpdateProjectProjectNameComboBox.SelectedItem.ToString() + "'").First().project_id;
                Entity1._project.project_name = this.UpdateProjectProjectNameTextBox.Text;
                Entity1._project.location = this.UpdateProjectLocationTextBox.Text;
                Entity1._project.description = this.UpdateProjectDescriptionTextBox.Text;
                Entity1._project.end_date = (DateTime)this.UpdateProjectEndDatePicker.SelectedDate;
                Entity1._project.start_date = (DateTime)this.UpdateProjectStartDatePicker.SelectedDate;

                // get the client
                try
                {
                    List<clients> cc = DB1.GetClients("");
                    var result = from item in cc
                                 where item.client_name.ToLower().Contains(this.RegisterProjectClientTextBox.Text.ToLower())
                                 select item;

                    if (result != null)
                    {
                        Entity1._project.client_id = Convert.ToInt32(((List<clients>)result.ToList()).First().client_id);
                    }

                }
                catch { }

                if (DB1.UpdateProject(Entity1._project))
                {
                    MessageBox.Show("Project Successfully updated");
                    EmptyAllfields(this.UpdateProjectGrid);
                    Initialization();
                    //this.UpdateProjectProjectNameComboBox = new ComboBox();
                    //ComboboxPopulating(this.UpdateProjectProjectNameComboBox, null);
                }

            }
            catch { }
        }
Exemplo n.º 14
0
        private void RegisterTaskCreateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                RefreshContainer();
                // check for empty value
                CheckForEmpty(this.RegisterTaskGrid);
                if (this.textboxstatus == false)
                {
                    MessageBox.Show("A field has not been entered");
                    textboxstatus = false;
                    return;
                }

                // get the project id
                // check if the material already exists
                if (this.AllContainer._employeeslist.Count == 0)
                {
                    RefreshContainer();
                }

                var result = from item in AllContainer._projectlist
                             where (item.project_name.Contains(this.RegisterTaskProjectNameTextBox.Text))
                             select (item.project_id);
                int p_id = ((List<int>)result.ToList()).First();
                result = from item in AllContainer._employeeslist
                         where (item.employee_name.Contains(this.RegisterTaskForemanTextBox.Text))
                         select (item.employee_id);
                int e_id = ((List<int>)result.ToList()).First();

                Container Entity1 = new Container();
                Entity1._task = new task();
                Entity1._task.task_name = this.RegisterTaskTaskNameTextBox.Text;
                Entity1._task.project_id = p_id;
                Entity1._task.employee_id = e_id;
                Entity1._task.budget = Convert.ToInt32(this.RegisterTaskBudgetTextBox.Text);
                Entity1._task.start_date = (DateTime)this.RegisterTaskStartDatePicker.SelectedDate;
                Entity1._task.end_date = (DateTime)this.RegisterTaskDeadlineDatePicker.SelectedDate;

                //register in database
                DB1 = new DBManager();
                if (DB1.InsertValue(Entity1, Constants.Task))
                {
                    MessageBox.Show("the task has been registered");
                    EmptyAllfields(this.RegisterTaskGrid);
                    Initialization();
                }

            }
            catch { }
        }
Exemplo n.º 15
0
        private static Request EmployeeHandler(Request req)
        {
            try
            {
                string response = "invalid id or password";
                employees emp = JsonConvert.DeserializeObject<employees>(req.content);
                Request reply = new Request();

                switch (req.purpose)
                {
                    case Constants.Log_In:
                        // get the name of the employee
                        List<employees> emplist = DB1.GetEmployees("");
                        //check if the id and the password
                        var result = from item in emplist
                                     where ((item.employee_id == emp.employee_id) && (item.password == emp.password))
                                     select item;

                        if (result.Count() > 0)
                        {
                            // get the employee
                            emp = ((List<employees>)result.ToList()).First();
                            //response =  emp.employee_name;

                            //check if the employee is a foreman
                            List<job_type> foremanjobtypelist = DB1.GetJobType("SELECT a.* FROM job_type a, job_description b WHERE (a.job_type_id = b.job_type_id) AND (b.employee_id = " + emp.employee_id + " ) AND (a.job_name =  '" + Constants.Foreman + "')");
                            if (foremanjobtypelist.Count == 0)
                            {
                                // the person is a not a foreman foreman
                                List<job_type> supervisorjobtypelist = DB1.GetJobType("SELECT a.* FROM job_type a, job_description b WHERE (a.job_type_id = b.job_type_id) AND (b.employee_id = " + emp.employee_id + " ) AND((a.job_name = '" + Constants.Supervisor + "'))");
                            }
                            else
                            {
                                // the person is a foreman
                                // get a list of all tasks that are related to him
                                List<task> tasklist = DB1.GetTasks("SELECT a.* FROM tasks a WHERE a.employee_id = " + emp.employee_id);
                                //return the tasks
                                string taskstring = JsonConvert.SerializeObject(tasklist);
                                // generate the request
                                req = new Request();
                                req.category = Constants.Foreman;
                                req.purpose = Constants.Log_In;
                                Container c = new Container();
                                c._tasklist = tasklist;
                                req.content = JsonConvert.SerializeObject(c);

                            }

                        }
                        else { }

                        break;
                }
                return req;
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 16
0
        private static Request LabourerRequestHander(Request req)
        {
            try
            {
                LabourerRequest lr = JsonConvert.DeserializeObject<LabourerRequest>(req.content);
                switch (req.purpose)
                {

                    case Constants.New_Labourer:
                        //inform the user
                        MessageBoxResult mr =  MessageBox.Show("A request has been made to register a new labourer proceed" ,"Labourer registration" , MessageBoxButton.YesNo);
                        if(mr == MessageBoxResult.No)
                        {
                            return null;
                        }
                        Container c = new Container();
                        c._labourers = new labourers();
                        c._project_labour_allocation = new project_labour_allocation();

                        // insert a new value to the labourers table
                        c._labourers.national_id = lr.national_id;
                        c._labourers.labourer_id = lr.labourer_id;
                        c._labourers.labourer_name = lr.labourer_name;
                        c._labourers.labourer_contact = lr.labourer_contact;
                        DB1 = new DBManager();
                        if (DB1.InsertValue(c, Constants.Labourers))
                        {
                            MessageBox.Show("the labourer has been registered");
                        }

                        // get the derived labourer id
                        //allocate the registered labourer
                        c._project_labour_allocation.project_id = lr.project_id;
                        c._project_labour_allocation.labourer_id = DB1.GetLabourers("SELECT * FROM labourers WHERE national_id = '" + lr.national_id + "'").First().labourer_id;

                        if (DB1.InsertValue(c, Constants.Project_Labour_Allocation))
                        {
                            MessageBox.Show("the labourer has been registered to the project");
                        }
                        break;
                    case Constants.Labourers_List:
                        // return the list of labourers to the foreman
                        //
                        DB1 = new DBManager();
                        c = new Container();
                        c._labourerslist = new List<labourers>();
                        c._labourerslist = DB1.GetLabourers("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + "");
                        Debug.WriteLine("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + "");

                        c._employeeslist = new List<employees>();
                        c._employeeslist = DB1.GetEmployees("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + "");
                        Debug.WriteLine("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + "");

                        //c._employees_list = DB1.GetLabourers()
                        req.content = JsonConvert.SerializeObject(c);
                        req.category = Constants.Labourers;
                        req.purpose = Constants.Labourers_List;

                        break;
                    case Constants.Submit_Work_Day:
                        DB1 = new DBManager();
                        c = JsonConvert.DeserializeObject<Container>(req.content);
                        foreach (labourers labour in c._labourerslist)
                        {
                            // get the project allocation id where the labourer id is entered
                            c._project_labour_working_day = new project_labour_working_day();
                            c._project_labour_working_day.project_labour_allocation_id = DB1.GetProjectLabourAllocation("SELECT a.* FROM project_labour_allocation a , labourers b WHERE a.labourer_id = b.labourer_id AND b.labourer_id = " + labour.labourer_id + "").First().project_labour_allocation_id;
                            c._project_labour_working_day.working_date = DateTime.Now.Date;

                            if(!DB1.InsertValue(c , Constants.Project_Labour_Working_Day))
                            {
                                MessageBox.Show("labourer not entered");
                            }
                        }
                        foreach (employees emp in c._employeeslist)
                        {
                            c._project_employee_working_day = new project_employee_working_day();
                            c._project_employee_working_day.project_employee_allocation_id = DB1.GetProjectEmployeeAllocation("SELECT a.* FROM project_employee_allocation a , employees b WHERE a.employee_id = b.employee_id AND b.employee_id = " + emp.employee_id + "").First().project_employee_allocation_id;
                            c._project_employee_working_day.working_date = DateTime.Now.Date;

                            if (!DB1.InsertValue(c, Constants.Project_employee_Working_Day))
                            {
                                MessageBox.Show("employee not entered");
                            }
                        }
                        MessageBox.Show("data entered");
                        break;

                }
                return req;
            }
            catch
            {
                return null ;
            }
        }