Exemplo n.º 1
0
        public bool SaveGeneralData()
        {
            var result = false;

            try
            {
                using (var ctx = new EF6.RT2020Entities())
                {
                    #region save core data
                    var staff = ctx.Staff.Find(_StaffId);
                    if (staff == null)
                    {
                        #region add new dbo.Staff
                        staff             = new EF6.Staff();
                        staff.StaffId     = Guid.NewGuid();
                        staff.StaffNumber = _StaffNumber;
                        staff.CreatedOn   = DateTime.Now;
                        staff.CreatedBy   = ConfigHelper.CurrentUserId;
                        staff.Status      = Convert.ToInt32(EnumHelper.Status.Active.ToString("d"));

                        ctx.Staff.Add(staff);

                        _StaffId = staff.StaffId;
                        #endregion
                    }
                    else
                    {
                        staff.Status = Convert.ToInt32(EnumHelper.Status.Modified.ToString("d"));
                    }

                    staff.StaffCode    = txtInitial.Text.Trim();
                    staff.FirstName    = txtFirstName.Text.Trim();
                    staff.LastName     = txtLastName.Text.Trim();
                    staff.FullName     = txtName.Text.Trim();
                    staff.FullName_Chs = txtNameChs.Text.Trim();
                    staff.FullName_Cht = txtNameCht.Text.Trim();
                    staff.Password     = txtPassword.Text.Trim();
                    if ((Guid)cboDeptCode.SelectedValue != Guid.Empty)
                    {
                        staff.DeptId = (Guid)cboDeptCode.SelectedValue;
                    }
                    if ((Guid)cboPosition.SelectedValue != Guid.Empty)
                    {
                        staff.JobTitleId = (Guid)cboPosition.SelectedValue;
                    }
                    if ((Guid)cmbStaffGrade.SelectedValue != Guid.Empty)
                    {
                        staff.GroupId = (Guid)cmbStaffGrade.SelectedValue;
                    }

                    staff.DownloadToCounter = true;
                    staff.DownloadToPOS     = true;
                    staff.ModifiedOn        = DateTime.Now;
                    staff.ModifiedBy        = ConfigHelper.CurrentUserId;

                    ctx.SaveChanges();

                    // 2013.11.27 paulus: 要同時更新 UserProfile 的資料,否則 login 時就沒有這個 Staff 的資料
                    RT2020.Controls.UserProfile.SaveRec(staff.StaffId, (int)EnumHelper.UserType.Staff, staff.StaffNumber, staff.Password, staff.StaffCode);

                    #region log activity (Update)
                    RT2020.Controls.Log4net.LogInfo(ctx.Entry(staff).State == EntityState.Added ?
                                                    RT2020.Controls.Log4net.LogAction.Create : RT2020.Controls.Log4net.LogAction.Update,
                                                    staff.ToString());
                    #endregion

                    #endregion

                    #region save staff HR
                    var hr = ctx.StaffHR.Where(x => x.StaffId == _StaffId).FirstOrDefault();
                    if (hr == null)
                    {
                        #region add new dbo.StaffHR
                        hr         = new EF6.StaffHR();
                        hr.HRId    = Guid.NewGuid();
                        hr.StaffId = _StaffId;

                        ctx.StaffHR.Add(hr);
                        #endregion
                    }

                    hr.HiredOn              = datHiredOn.Value;
                    hr.EmploymentNumber     = txtEmploymen.Text.Trim();
                    hr.MedicalNumber        = txtMedical.Text.Trim();
                    hr.TC_PunchEnable_InOut = chkPunch.Checked;
                    hr.TC_AdminEnable       = chkAdministration.Checked;

                    ctx.SaveChanges();
                    #endregion
                }

                #region SaveSmartTagValues
                foreach (Control Ctrl in Controls)
                {
                    if (Ctrl.Name.Contains("SmartTag") && !Ctrl.Name.StartsWith("lbl"))
                    {
                        StaffSmartTagEx.SaveSmartTagValue(_StaffId, Ctrl);
                    }
                }
                #endregion

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Exemplo n.º 2
0
        public bool SavePersonalData()
        {
            var result = false;

            try
            {
                #region SaveSmartTagValues
                foreach (Control Ctrl in Controls)
                {
                    if (Ctrl.Name.Contains("SmartTag") && !Ctrl.Name.StartsWith("lbl"))
                    {
                        StaffSmartTagEx.SaveSmartTagValue(_StaffId, Ctrl);
                    }
                }
                #endregion

                #region Save Address, HR
                using (var ctx = new EF6.RT2020Entities())
                {
                    #region Save Address
                    var sa = ctx.StaffAddress.Where(x => x.StaffId == _StaffId).FirstOrDefault();
                    if (sa != null)
                    {
                        #region add new dbo.StaffAddress
                        sa           = new EF6.StaffAddress();
                        sa.AddressId = Guid.NewGuid();
                        sa.StaffId   = _StaffId;
                        ctx.StaffAddress.Add(sa);
                        #endregion
                    }
                    sa.Address = txtAddress.Text.Trim();
                    if (cmbCountry.SelectedIndex >= 0)
                    {
                        if ((Guid)cmbCountry.SelectedValue != Guid.Empty)
                        {
                            sa.CountryId = (Guid)cmbCountry.SelectedValue;
                        }
                    }
                    if (cmbProvince.SelectedIndex >= 0)
                    {
                        if ((Guid)cmbProvince.SelectedValue != Guid.Empty)
                        {
                            sa.ProvinceId = (Guid)cmbProvince.SelectedValue;
                        }
                    }
                    if (cmbCity.SelectedIndex >= 0)
                    {
                        if ((Guid)cmbCity.SelectedValue != Guid.Empty)
                        {
                            sa.CityId = (Guid)cmbCity.SelectedValue;
                        }
                    }
                    sa.PostalCode     = txtPostal.Text.Trim();
                    sa.PhoneTag1Value = txtPhoneTag1.Text.Trim();
                    sa.PhoneTag2Value = txtPhoneTag2.Text.Trim();
                    sa.PhoneTag3Value = txtPhoneTag3.Text.Trim();
                    sa.PhoneTag4Value = txtPhoneTag4.Text.Trim();

                    ctx.SaveChanges();
                    #endregion

                    #region Save HR
                    decimal salary = 0;
                    decimal.TryParse(txtSalary.Text.Trim(), out salary);

                    var hr = ctx.StaffHR.Where(x => x.StaffId == _StaffId).FirstOrDefault();
                    if (hr == null)
                    {
                        #region add new dbo.StaffHR
                        hr         = new EF6.StaffHR();
                        hr.HRId    = Guid.NewGuid();
                        hr.StaffId = _StaffId;

                        ctx.StaffHR.Add(hr);
                        #endregion
                    }

                    hr.Salary            = salary;
                    hr.BankAccountNumber = txtBankAC.Text.Trim();

                    ctx.SaveChanges();
                    #endregion
                }
                #endregion

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }