private void LoadSmartTagValues() { foreach (Control Ctrl in Controls) { StaffSmartTagEx.LoadSmartTagValue(_StaffId, Ctrl); } }
private void LoadSmartTagValues() { foreach (Control Ctrl in Controls) { if (Ctrl.Name.Contains("SmartTag") && !Ctrl.Name.StartsWith("lbl")) { StaffSmartTagEx.LoadSmartTagValue(_StaffId, Ctrl); } } }
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); }
private void GetSmartValue(Guid staffId, Control Ctrl) { string sql = "StaffId = '" + staffId.ToString() + "' AND TagId = '{0}'"; string key = "SmartTag"; Guid tagId = Guid.Empty; if (Ctrl != null && Ctrl.Name.Contains(key)) { if (Ctrl.Tag != null) { tagId = (Guid)Ctrl.Tag; var oTag = StaffSmartTagEx.Get(staffId, tagId); if (oTag != null) { if (Ctrl.GetType().Equals(typeof(TextBox))) { TextBox txtTag = Ctrl as TextBox; txtTag.Text = oTag.SmartTagValue; } if (Ctrl.GetType().Equals(typeof(MaskedTextBox))) { MaskedTextBox txtTag = Ctrl as MaskedTextBox; txtTag.Text = oTag.SmartTagValue; } if (Ctrl.GetType().Equals(typeof(ComboBox))) { var id = Guid.Empty; if (Guid.TryParse(oTag.SmartTagValue, out id)) { // 2020.12.28 paulus: 如果係 combo box,個 value = dbo.SmartTag_Options.OptionId ComboBox cboTag = Ctrl as ComboBox; //cboTag.Text = oTag.SmartTagValue; cboTag.SelectedValue = id; } } if (Ctrl.GetType().Equals(typeof(DateTimePicker))) { DateTimePicker dtpTag = Ctrl as DateTimePicker; //2014.01.08 paulus: 可以唔輸入 birthday,先決係要有 ShowCheckBox,然後根據 value //舊 code: dtpTag.Value = (oTag.SmartTagValue.Length == 0) ? DateTime.Now : Convert.ToDateTime(ReformatDateTime(oTag.SmartTagValue)); if (dtpTag.ShowCheckBox) { if (oTag.SmartTagValue.Length == 0) { dtpTag.Value = dtpTag.MinDate; dtpTag.Checked = false; } else { dtpTag.Value = Convert.ToDateTime(DateTimeHelper.ReformatDateTime(oTag.SmartTagValue)); dtpTag.Checked = true; } } else { dtpTag.Value = (oTag.SmartTagValue.Length == 0) ? dtpTag.MinDate : Convert.ToDateTime(DateTimeHelper.ReformatDateTime(oTag.SmartTagValue)); } } } } } }
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); }