Exemplo n.º 1
0
        // Update the selected entry
        private void Btn_update_Click(object sender, EventArgs e)
        {
            site.site_id        = DataExchanger.site.site_id;
            site.title          = tb_title.Text.Trim();
            site.address        = tb_address.Text.Trim();
            site.description    = tb_description.Text.Trim();
            site.estimated_cost = float.Parse(tb_estimated_cost.Text.Trim());
            site.start_date     = dtp_start_date.Value;
            site.deadline       = dtp_end_date.Value;

            using (NCOMSEntities db = new NCOMSEntities())
            {
                string firstName          = cb_supervisor.Text.ToString().Substring(0, cb_supervisor.Text.ToString().IndexOf(" "));
                Staff  selectedSupervisor = db.Staffs.Where(s => s.first_name == firstName).FirstOrDefault();
                staff_Allocated_Site.staff_id = selectedSupervisor.staff_id;
                staff_Allocated_Site.site_id  = DataExchanger.site.site_id;
                staff_Allocated_Site.staff_allocated_site_id = DataExchanger.staff_Allocated_Site.staff_allocated_site_id;
                staff_Allocated_Site.started_date            = DateTime.Now;
                staff_Allocated_Site.end_date = DataExchanger.staff_Allocated_Site.end_date;

                db.Entry(staff_Allocated_Site).State = System.Data.Entity.EntityState.Modified;
                db.Entry(site).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            MessageBox.Show(String.Concat(site.title, " Record Updated"), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();

            if (Application.OpenForms["Form_ClerkMainWindow"] != null)
            {
                (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_dashboard_Click(null, null);
            }
        }
Exemplo n.º 2
0
        private void Btn_delete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are You Sure To Delete This Record?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                using (NCOMSEntities db = new NCOMSEntities())
                {
                    Site site = new Site();

                    site.site_id        = _site_id;
                    site.title          = _title;
                    site.address        = _address;
                    site.description    = _description;
                    site.estimated_cost = float.Parse(_estimated_cost.ToString());
                    site.start_date     = Convert.ToDateTime(_start_date);
                    site.deadline       = Convert.ToDateTime(_end_date);

                    var entry = db.Entry(site);
                    if (entry.State == System.Data.Entity.EntityState.Detached)
                    {
                        db.Sites.Attach(site);
                    }

                    db.Sites.Remove(site);
                    db.SaveChanges();


                    if (Application.OpenForms["Form_ClerkMainWindow"] != null)
                    {
                        (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_dashboard_Click(null, null);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Btn_delete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to delete this record?", "Caution", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (NCOMSEntities db = new NCOMSEntities())
                {
                    Vehicle vehicle = new Vehicle();

                    vehicle.vehicle_id       = _vehicle_id;
                    vehicle.date_of_purchase = Convert.ToDateTime(_date_of_purchase);
                    vehicle.description      = _description;
                    vehicle.reg_no           = _registration_number;

                    var entry = db.Entry(vehicle);
                    if (entry.State == System.Data.Entity.EntityState.Detached)
                    {
                        db.Vehicles.Attach(vehicle);
                    }

                    db.Vehicles.Remove(vehicle);
                    db.SaveChanges();

                    if (Application.OpenForms["Form_ClerkMainWindow"] != null)
                    {
                        (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_vehicle_Click(null, null);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void Btn_update_Click(object sender, EventArgs e)
        {
            vehicle.vehicle_id       = DataExchanger.vehicle.vehicle_id;
            vehicle.reg_no           = tb_registration_no.Text.Trim();
            vehicle.description      = tb_description.Text.Trim();
            vehicle.date_of_purchase = dtp_date_of_purchase.Value;

            using (NCOMSEntities db = new NCOMSEntities())
            {
                db.Entry(vehicle).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            MessageBox.Show("Record Updated");
            this.Close();

            if (Application.OpenForms["Form_ClerkMainWindow"] != null)
            {
                (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_vehicle_Click(null, null);
            }
        }