protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string name = Session["fullName"].ToString();
                string role = Session["role"].ToString();
            }
            catch (Exception)
            {
                Response.Redirect("../Default.aspx");
            }
            if (!IsPostBack)
            {
                niapsEntities1 db       = new niapsEntities1();
                int            sId      = Int32.Parse(getStaffId());
                var            staffRec = db.currentStaffRecords.Where(st => st.Id == sId).First();
                stid.Text = staffRec.staffId;

                dept.Text        = staffRec.department;
                degree.Text      = staffRec.degree;
                doj.Text         = (staffRec.date_Joined).ToString();
                disc.Text        = staffRec.qualification;
                doc.Text         = staffRec.dateOfConfirmation.ToString();
                designation.Text = staffRec.designation;
                var ste = db.staffRecords.Where(s => s.staffId == staffRec.staffId).First();
                lname.Text = ste.lName;
                fname.Text = ste.fName;
            }

            try
            {
                niapsEntities1 db   = new niapsEntities1();
                string         name = Session["fullName"].ToString();
                // Insert the update transaction into the staff update history table first
                staffUpdateHistory stu = new staffUpdateHistory();
                stu.staffId   = stid.Text;
                stu.updatDate = DateTime.Now;
                stu.updatedBy = name;
                string message = getOldRecord();
                // message += ": New Record: Staff Name:" + lname.Text + ", " + fname.Text + " " + mname.Text + ", Designation:" + des.Text + ",GSM: " + gsm.Text + "Email:" + email.Text + "" + ", Address" + address.Text + ", Marital Status:" + mstatus.Text + ",Status:" + status.Text;
                stu.description = message;
                db.staffUpdateHistories.Add(stu);
                db.SaveChanges();
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 2
0
        protected void update_Click(object sender, EventArgs e)
        {
            try
            {
                niapsEntities1     db    = new niapsEntities1();
                string             uname = Session["fullName"].ToString();
                staffUpdateHistory stu   = new staffUpdateHistory();
                stu.staffId   = stid.Text;
                stu.updatDate = DateTime.Now;
                stu.updatedBy = uname;
                string message = getOldRecord();
                stu.description = message;
                db.staffUpdateHistories.Add(stu);
                db.SaveChanges();
                niapsEntities1 db2 = new niapsEntities1();
                string         sid = stid.Text;
                var            str = db2.staffRecords.FirstOrDefault(ai => ai.staffId == sid);
                // str.staffId = sid;
                str.lName  = lname.Text;
                str.fName  = fname.Text;
                str.gender = gender.Text;
                string   date1   = dob.Text;
                DateTime dobirth = DateTime.Parse(date1);
                str.dateOfBirth = dobirth;
                str.middleName  = mname.Text;
                // str.designation = des.Text;
                str.age    = Int32.Parse(age.Text);
                str.mobile = gsm.Text;

                var    lg  = db.LGAs.Where(l => l.name == lga.Text).First();
                string loc = lg.LGACode.ToString();
                str.Lga = loc;

                var ste = db.states.Where(s => s.state1 == state.Text).First();

                str.state                = ste.stateCode;
                str.address              = address.Text;
                str.email                = email.Text;
                str.marritalStatus       = mstatus.Text;
                str.formOfIdentification = foid.Text;
                str.idNumber             = idNumber.Text;
                db2.SaveChanges();

                niapsEntities1 db3 = new niapsEntities1();
                string         sId = Request.QueryString["staffId"].ToString();
                var            kin = db3.staffNextOfKins.FirstOrDefault(ki => ki.staffId == sId);
                kin.lname         = kinLastName.Text;
                kin.fName         = kinFirstName.Text;
                kin.address       = kinAddress.Text;
                kin.gender        = kinGender.Text;
                kin.contactMobile = kinGsm.Text;
                kin.relationship  = relationship.Text;
                db3.SaveChanges();

                niapsEntities1 db4  = new niapsEntities1();
                var            empl = db4.currentStaffRecords.FirstOrDefault(emp => emp.staffId == sId);
                empl.degree             = degree.Text;
                empl.designation        = designation.Text;
                empl.qualification      = disc.Text;
                empl.dateOfConfirmation = DateTime.Parse(dc.Text);
                empl.date_Joined        = DateTime.Parse(djoined.Text);
                empl.probationPeriod    = Int32.Parse(pbp.Text);
                empl.department         = dept.Text;
                db4.SaveChanges();

                stid.Text   = "";
                lname.Text  = "";
                fname.Text  = "";
                gender.Text = "";
                dob.Text    = "";
                mname.Text  = "";
                age.Text    = "";
                gsm.Text    = "";

                lga.Text = "";

                state.Text    = "";
                address.Text  = "";
                email.Text    = "";
                mstatus.Text  = "";
                foid.Text     = "";
                idNumber.Text = "";

                kinLastName.Text  = "";
                kinFirstName.Text = "";
                kinAddress.Text   = "";
                kinGender.Text    = "";
                kinGsm.Text       = "";
                relationship.Text = "";
                degree.Text       = "";
                designation.Text  = "";
                disc.Text         = "";
                dc.Text           = "";
                djoined.Text      = "";
                pbp.Text          = "";

                msg.Text = "staff updated successfully";
            }
            catch (Exception)
            {
                msg.Text = "error occured! could not update";
            }
        }