Exemplo n.º 1
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.º 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 List <Money_Request> GetMoneyRequests()
 {
     using (NCOMSEntities db = new NCOMSEntities())
     {
         return(db.Money_Request.ToList <Money_Request>());
     }
 }
Exemplo n.º 4
0
 private List <Staff> GetStaffs()
 {
     using (NCOMSEntities db = new NCOMSEntities())
     {
         return(db.Staffs.ToList <Staff>());
     }
 }
Exemplo n.º 5
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.º 6
0
 private List <Vehicle> GetVehicles()
 {
     using (NCOMSEntities db = new NCOMSEntities())
     {
         List <Vehicle> vehicleList = db.Vehicles.ToList <Vehicle>();
         return(vehicleList);
     }
 }
Exemplo n.º 7
0
 private List <Site> GetSites()
 {
     using (NCOMSEntities db = new NCOMSEntities())
     {
         List <Site> siteList = db.Sites.ToList <Site>();
         return(siteList);
     }
 }
Exemplo n.º 8
0
        // Setting values to the user controllers when form loading
        private void Form_Update_Site_Load(object sender, EventArgs e)
        {
            tb_title.Text          = DataExchanger.site.title;
            tb_description.Text    = DataExchanger.site.description;
            tb_address.Text        = DataExchanger.site.address;
            tb_estimated_cost.Text = DataExchanger.site.estimated_cost.ToString();
            dtp_start_date.Value   = Convert.ToDateTime(DataExchanger.site.start_date);
            dtp_end_date.Value     = Convert.ToDateTime(DataExchanger.site.deadline);

            using (NCOMSEntities db = new NCOMSEntities())
            {
                supervisor = db.Staffs.Where(s => s.staff_id == DataExchanger.staff_Allocated_Site.staff_id).FirstOrDefault();
                cb_supervisor.SelectedItem = supervisor.first_name + " " + supervisor.last_name;
            }
        }
Exemplo n.º 9
0
        private void AddToTheContainer(List <Site> siteList)
        {
            foreach (Site site in siteList)
            {
                UserControl_Site_Item siteItem = new UserControl_Site_Item();
                siteItem.SiteId        = site.site_id;
                siteItem.Title         = site.title;
                siteItem.Description   = site.description;
                siteItem.Address       = site.address;
                siteItem.StartDate     = Convert.ToDateTime(site.start_date).ToString("yyyy-MM-dd");
                siteItem.EndDate       = Convert.ToDateTime(site.deadline).ToString("yyyy-MM-dd");
                siteItem.EstimatedCost = site.estimated_cost.ToString();
                siteItem.Supervisor    = "0";

                using (NCOMSEntities db = new NCOMSEntities())
                {
                    Staff_Allocated_Site staff_Allocated_Site = db.Staff_Allocated_Site.Where(s => s.site_id == site.site_id).FirstOrDefault();
                    Staff supervisor = db.Staffs.Where(s => s.staff_id == staff_Allocated_Site.staff_id).FirstOrDefault();

                    siteItem.Supervisor           = supervisor.first_name + " " + supervisor.last_name;
                    siteItem.StaffAllocatedSiteId = staff_Allocated_Site.staff_allocated_site_id;
                    siteItem.SupervisorId         = supervisor.staff_id;
                }

                siteTitles.Add(site.title);

                int totalDays = Convert.ToDateTime(site.deadline).Subtract(Convert.ToDateTime(site.start_date)).Days;
                int pasedDays = Convert.ToDateTime(site.deadline).Subtract(DateTime.Today).Days;
                int percentage;

                if (pasedDays <= 0)
                {
                    percentage = 100;
                }
                else if (Convert.ToDateTime(site.start_date).Subtract(DateTime.Today).Days >= 0)
                {
                    percentage = 0;
                }
                else
                {
                    percentage = 100 - (Convert.ToInt32(((pasedDays / (double)totalDays) * 100)));
                }

                siteItem.TimeLine = percentage;

                flp_site_item_container.Controls.Add(siteItem);
            }
        }
Exemplo n.º 10
0
        public Form_Add_New_Site()
        {
            InitializeComponent();
            this.ActiveControl = tb_title;

            // Get supervisor list from the database
            using (NCOMSEntities db = new NCOMSEntities())
            {
                supervisorList = db.Staffs.Where(s => s.user_level == "Supervisor").ToList <Staff>();
            }

            // Add Supervisor's names to combo box
            cb_supervisor.Items.Add("-- Select --");
            foreach (Staff staff in supervisorList)
            {
                cb_supervisor.Items.Add(staff.first_name + " " + staff.last_name);
            }
            cb_supervisor.SelectedIndex = 0;
        }
Exemplo n.º 11
0
        private void Btn_save_Click(object sender, EventArgs e)
        {
            vehicle.reg_no           = tb_registration_no.Text.Trim();
            vehicle.date_of_purchase = dtp_date_of_purchase.Value;
            vehicle.description      = tb_description.Text.Trim();

            using (NCOMSEntities db = new NCOMSEntities())
            {
                db.Vehicles.Add(vehicle);
                db.SaveChanges();
            }

            MessageBox.Show("Record Added Successfully");
            this.Close();

            if (Application.OpenForms["Form_ClerkMainWindow"] != null)
            {
                (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_vehicle_Click(null, null);
            }
        }
Exemplo n.º 12
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);
            }
        }
Exemplo n.º 13
0
        // Create a entry in database
        private void Btn_save_Click(object sender, EventArgs e)
        {
            site.title          = tb_title.Text.Trim();
            site.description    = tb_description.Text.Trim();
            site.address        = tb_address.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())
            {
                db.Sites.Add(site);
                db.SaveChanges();
            }

            // Inserting supervisor record to staff_allocated_site table
            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;

                Site insertedSite = db.Sites.Where(s => s.title == tb_title.Text).FirstOrDefault();
                staff_Allocated_Site.site_id      = insertedSite.site_id;
                staff_Allocated_Site.started_date = DateTime.Now;
                staff_Allocated_Site.end_date     = insertedSite.deadline;

                db.Staff_Allocated_Site.Add(staff_Allocated_Site);
                db.SaveChanges();
            }

            this.Close();

            // reload the container
            if (Application.OpenForms["Form_ClerkMainWindow"] != null)
            {
                (Application.OpenForms["Form_ClerkMainWindow"] as Form_ClerkMainWindow).Btn_nav_dashboard_Click(null, null);
            }
        }
Exemplo n.º 14
0
        private void AddToTheContainer(List <Money_Request> moneyRequestList)
        {
            foreach (Money_Request moneyRequest in moneyRequestList)
            {
                UserControl_MoneyRequest_Item_D1 moneyRequestItem = new UserControl_MoneyRequest_Item_D1();

                using (NCOMSEntities db = new NCOMSEntities())
                {
                    moneyRequestItem.SiteTitle = db.Sites.Where(m => m.site_id == moneyRequest.site_id).FirstOrDefault().title.ToString();
                    Staff_Allocated_Site staff_Allocated_Site = db.Staff_Allocated_Site.Where(m => m.site_id == moneyRequest.site_id).FirstOrDefault();
                    Staff supervisor = db.Staffs.Where(m => m.staff_id == staff_Allocated_Site.staff_id).FirstOrDefault();
                    moneyRequestItem.SupervisorName = supervisor.first_name + " " + supervisor.last_name;
                }

                moneyRequestItem.SiteId         = moneyRequest.site_id;
                moneyRequestItem.Amount         = float.Parse(moneyRequest.amount.ToString());
                moneyRequestItem.RequestedDate  = Convert.ToDateTime(moneyRequest.requested_on).ToString("yyyy-MM-dd");
                moneyRequestItem.RequestedTime  = moneyRequest.requested_at.ToString();
                moneyRequestItem.Description    = moneyRequest.description;
                moneyRequestItem.MoneyRequestId = moneyRequest.request_id;

                flp_money_request_item_container.Controls.Add(moneyRequestItem);
            }
        }
Exemplo n.º 15
0
        private async void Btn_save_Click(object sender, EventArgs e)
        {
            staffMember.first_name    = tb_firstName.Text.Trim();
            staffMember.last_name     = tb_lastName.Text.Trim();
            staffMember.nic           = tb_nicNumber.Text.Trim();
            staffMember.email         = tb_email.Text.Trim();
            staffMember.address       = tb_address.Text.Trim();
            staffMember.date_of_birth = dtp_dateOfBirth.Value;
            staffMember.join_on       = dtp_joinOn.Value;
            staffMember.user_name     = tb_userName.Text.Trim();
            staffMember.password      = tb_tempPasword.Text.Trim();

            if (rb_female.Checked)
            {
                staffMember.gender = "F";
            }
            else if (rb_male.Checked)
            {
                staffMember.gender = "M";
            }

            staffMember.designation = cb_designation.Text.ToString();

            switch (cb_designation.Text.ToString())
            {
            case desig1:
                staffMember.user_level = level1;
                break;

            case desig2:
                staffMember.user_level = level2;
                break;

            case desig3:
                staffMember.user_level = level3;
                break;

            case desig4:
                staffMember.user_level = level4;
                break;
            }

            staffMember.profile_picture = ConvertImageToBinary(pb_profile.Image);

            using (NCOMSEntities db = new NCOMSEntities())
            {
                db.Staffs.Add(staffMember);
                await db.SaveChangesAsync();
            }

            // adding multivalued mobile number

            using (NCOMSEntities db = new NCOMSEntities())
            {
                Staff insertedStaffMember = db.Staffs.Where(s => s.first_name == tb_firstName.Text.Trim() && s.last_name == tb_lastName.Text.Trim()).FirstOrDefault();

                if (tb_mobile_one.Text.ToString().Length != 0)
                {
                    mobileOne          = new Staff_Mobile();
                    mobileOne.staff_id = insertedStaffMember.staff_id;
                    mobileOne.mobile   = tb_mobile_one.Text.Trim();
                }

                if (tb_mobile_two.Text.ToString().Length != 0)
                {
                    mobileTwo          = new Staff_Mobile();
                    mobileTwo.staff_id = insertedStaffMember.staff_id;
                    mobileTwo.mobile   = tb_mobile_two.Text.Trim();
                }

                db.Staff_Mobile.Add(mobileOne);
                db.Staff_Mobile.Add(mobileTwo);
                db.SaveChanges();
            }

            MessageBox.Show("Record Added Successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }