Esempio n. 1
0
        private void UpdateCompanyChanges()
        {
            try
            {
                strmaincNum = ViewState["CNum"].ToString();
                companyNum  = int.Parse(strmaincNum);

                using (var dtx = new TrustCompanyEntities())
                {
                    Comp = dtx.Companies.Where(s => s.CNum == companyNum).FirstOrDefault <Company>();
                }

                if (Comp != null)
                {
                    string newstrCompanyNum = txtCompanyNum.Text;
                    int    newintCompanyNum = int.Parse(newstrCompanyNum);
                    Comp.CNum      = newintCompanyNum;
                    Comp.Cname     = txtCompanyName.Text;
                    Comp.Address   = txtAddress.Text;
                    Comp.Telephone = txtTelephone.Text;
                }
                using (var dbCtx = new TrustCompanyEntities())
                {
                    dbCtx.Entry(Comp).State = System.Data.Entity.EntityState.Modified;
                    dbCtx.SaveChanges();
                }
                lblUpdateRow.Visible = true;
                lblUpdateRow.Text    = "Company Updated";
            }
            catch (Exception ex)
            {
                lblUpdateRow.Visible = true;
                lblUpdateRow.Text    = ex.Message;
            }
        }
Esempio n. 2
0
        private void DeleteCompany()
        {
            try
            {
                strmaincNum = ViewState["CNum"].ToString();
                companyNum  = int.Parse(strmaincNum);



                using (var dtx = new TrustCompanyEntities())
                {
                    empComp = dtx.CompanyEmployees.Where(s => s.CNum == companyNum).FirstOrDefault <CompanyEmployee>();
                    if (empComp != null)
                    {
                        throw new Exception("Company has to be Empty From Employees");
                    }

                    Comp = dtx.Companies.Where(s => s.CNum == companyNum).FirstOrDefault <Company>();
                    dtx.Entry(Comp).State = EntityState.Deleted;
                    dtx.SaveChanges();
                }
                lblUpdateRow.Visible = true;
                lblUpdateRow.Text    = "Company Removed";
            }
            catch (Exception ex)
            {
                lblUpdateRow.Visible = true;

                lblUpdateRow.Text = ex.Message;
            }
        }
Esempio n. 3
0
        private void InsertChanges()
        {
            try
            {
                string   strInCompanyNum = ViewState["CompanyNum"].ToString();
                int      intCompanyNum   = int.Parse(strInCompanyNum);
                string   strFname        = txtFName.Text;
                string   strLname        = txtLName.Text;
                string   strGender       = rblGender.SelectedValue;
                string   strEmpId        = txtEmployeeId.Text;
                int      empId           = int.Parse(strEmpId);
                string   strNewBirthDate = dt2.Value;
                DateTime birthDate;
                birthDate = new DateTime(Convert.ToInt16(strNewBirthDate.Substring(0, 4)), Convert.ToInt16(strNewBirthDate.Substring(5, 2)), Convert.ToInt16(strNewBirthDate.Substring(8, 2)));



                using (var db = new TrustCompanyEntities())
                {
                    var employees = db.Set <CompanyEmployee>();
                    employees.Add(new CompanyEmployee {
                        CNum = intCompanyNum, Fname = strFname, Lname = strLname, Gender = strGender, EmployeeId = empId, BirthDate = birthDate
                    });

                    db.SaveChanges();
                    lblRowInsert.Visible = true;
                }
            }
            catch (Exception ex)
            {
                lblRowInsert.Visible = true;
                lblRowInsert.Text    = ex.Message;
            }
        }
Esempio n. 4
0
        private void InsertChanges()
        {
            try
            {
                string newstrCompanyNum = txtCompanyNum.Text;
                int    newintCompanyNum = int.Parse(newstrCompanyNum);
                string strCompanyName   = txtCompanyName.Text;
                string strAddress       = txtAddress.Text;
                string strTelephone     = txtTelephone.Text;


                using (var db = new TrustCompanyEntities())
                {
                    var companies = db.Set <Company>();
                    companies.Add(new Company {
                        CNum = newintCompanyNum, Cname = strCompanyName, Address = strAddress, Telephone = strTelephone
                    });

                    db.SaveChanges();
                    lblRowInsert.Visible = true;
                }
            }
            catch (Exception ex)
            {
                lblRowInsert.Visible = true;
                lblRowInsert.Text    = ex.Message;
            }
        }
Esempio n. 5
0
        private void DeleteEmployee()
        {
            try
            {
                strempId = ViewState["EmpId"].ToString();
                empId    = int.Parse(strempId);

                using (var dtx = new TrustCompanyEntities())
                {
                    empComp = dtx.CompanyEmployees.Where(s => s.EmployeeId == empId).FirstOrDefault <CompanyEmployee>();
                    dtx.Entry(empComp).State = EntityState.Deleted;
                    dtx.SaveChanges();

                    lblUpdateRow.Text = "Employee Removed";
                    strCompanyNum     = ViewState["CompanyNum"].ToString();
                    strcompanyName    = ViewState["CompanyName"].ToString();
                    Response.Redirect("Employees.aspx?id=" + strCompanyNum + "&cName=" + strcompanyName, false);
                }
            }
            catch (Exception ex)
            {
                lblUpdateRow.Visible = true;
                lblUpdateRow.Text    = ex.InnerException.InnerException.Message;
            }
        }
Esempio n. 6
0
        private void UpdateChanges()
        {
            try
            {
                string strEmpId = ViewState["EmpId"].ToString();
                empId = int.Parse(strEmpId);


                using (var dtx = new TrustCompanyEntities())
                {
                    empComp = dtx.CompanyEmployees.Where(s => s.EmployeeId == empId).FirstOrDefault <CompanyEmployee>();
                }

                if (empComp != null)
                {
                    empComp.Fname = txtFName.Text;
                    empComp.Lname = txtLName.Text;
                    string strEmployeeId = txtEmployeeId.Text;
                    empComp.EmployeeId = int.Parse(strEmployeeId);
                    string gender = rblGender.SelectedValue;
                    empComp.Gender = gender;
                    string strNewBirthDate = dt1.Value;
                    BirthDate         = new DateTime(Convert.ToInt16(strNewBirthDate.Substring(0, 4)), Convert.ToInt16(strNewBirthDate.Substring(5, 2)), Convert.ToInt16(strNewBirthDate.Substring(8, 2)));
                    empComp.BirthDate = BirthDate;
                }
                using (var dbCtx = new TrustCompanyEntities())
                {
                    dbCtx.Entry(empComp).State = System.Data.Entity.EntityState.Modified;

                    dbCtx.SaveChanges();
                }
                lblUpdateRow.Visible = true;
            }
            catch (Exception ex)
            {
                lblUpdateRow.Visible = true;
                lblUpdateRow.Text    = ex.Message;
            }
        }