protected void RadGridDays_Load(object sender, EventArgs e) { var cVacationSchema = new CVacationSchema(); CVacationTypeInfoModel vacationTypeInfoModel = cVacationSchema.GetVacationTypeInfoModel(Convert.ToInt32(ViewState["UserId"])); ((RadGrid)sender).DataSource = cVacationSchema.Get(vacationTypeInfoModel); }
protected void StaffButtonClicked(object sender, RadToolBarEventArgs e) { if (e.Item.Text == @"New") { ResetForm(); } else if (e.Item.Text == @"Update" && RadGridUser.SelectedValue != null) { if (IsValid) { var cUser = new CUser(); var user = cUser.Get(Convert.ToInt32(RadGridUser.SelectedValue)); if (string.IsNullOrEmpty(tbPassWord.Text) == false) { user.Password = CCryptography.EncryptPlainTextToCipherText(tbPassWord.Text.Trim()); } user.FirstName = tbFName.Text; user.MidName = tbMName.Text; user.LastName = tbLName.Text; user.DOB = tbDOB.SelectedDate; user.MaritalStatus = ddlMarital.SelectedValue; user.Gender = ddlGender.SelectedValue; user.Email = tbWEmail.Text.Trim(); user.Phone = tbWPhone.Text.Trim(); user.EContactName = tbEName.Text; user.ERelation = tbERelation.Text; user.EPhone = tbEPhone.Text; user.EAddress = tbEAddress.Text; // only HR or IT can modify those things. if (CurrentGroupId == (int)CConstValue.UserGroupForUserInformation.HR || CurrentGroupId == (int)CConstValue.UserGroupForUserInformation.IT) { user.UserPositionId = Convert.ToInt32(RadComboBoxUserPosition.SelectedValue); user.SINNo = Convert.ToInt32(tbSIN.Text); user.SiteLocationId = Convert.ToInt32(RadComboBoxSiteLocation.SelectedValue); user.EmployeeNumber = tbEmpNo.Text; user.IsActive = cbActive.Checked; int?supervisor = string.IsNullOrEmpty(RadComboBoxSuper.SelectedValue) ? (int?)null : Convert.ToInt32(RadComboBoxSuper.SelectedValue); if (user.Supervisor != supervisor) { user.Supervisor = supervisor; var cApp = new CApproval(); var appList = cApp.GetList(Convert.ToInt32(RadGridUser.SelectedValue)); foreach (var app in appList) { app.Supervisor = user.Supervisor; app.IsActive = user.IsActive; app.UpdatedId = CurrentUserId; app.UpdatedDate = DateTime.Now; cApp.Update(app); } } } user.Address1 = tbPAddess1.Text; user.Address2 = tbPAddess2.Text; user.City = tbPCity.Text; user.Province = tbPProvince.Text; user.PostalCode = tbPPostal.Text; user.HomePhone = tbPHomePhone.Text; user.CellPhone = tbPCell.Text; user.PersonalEmail = tbPEmail.Text; user.UpdatedId = CurrentUserId; user.UpdatedDate = DateTime.Now; if (AsyncUploadPicture.UploadedFiles.Count > 0) { UploadedFile file = AsyncUploadPicture.UploadedFiles[0]; byte[] fileData = new byte[file.InputStream.Length]; file.InputStream.Read(fileData, 0, (int)file.InputStream.Length); user.Picture = fileData; } if (cUser.Update(user)) { RadGridUser.Rebind(); ShowMessage("Updated Staff Info Successfully"); } else { ShowMessage("Failed To Update Staff Info"); } } } else if (e.Item.Text == @"Save") { if (IsValid) { var cUser = new CUser(); var user = new Erp2016.Lib.User(); if (CurrentSiteId != 1) { user.SiteLocationId = Convert.ToInt32(CurrentSiteLocationId); } else { user.SiteLocationId = Convert.ToInt32(RadComboBoxSiteLocation.SelectedValue); } user.LoginId = tbUserID.Text; user.Password = CCryptography.EncryptPlainTextToCipherText(tbPassWord.Text.Trim()); user.FirstName = tbFName.Text; user.MidName = tbMName.Text; user.LastName = tbLName.Text; user.SINNo = Convert.ToInt32(tbSIN.Text); user.DOB = tbDOB.SelectedDate; user.MaritalStatus = ddlMarital.SelectedValue; user.Gender = ddlGender.SelectedValue; user.Email = tbWEmail.Text.Trim(); user.Phone = tbWPhone.Text.Trim(); user.UserPositionId = Convert.ToInt32(RadComboBoxUserPosition.SelectedValue); if (!string.IsNullOrEmpty(RadComboBoxSuper.SelectedValue)) { user.Supervisor = Convert.ToInt32(RadComboBoxSuper.SelectedValue); } user.EmployeeNumber = tbEmpNo.Text; user.EContactName = tbEName.Text; user.ERelation = tbERelation.Text; user.EPhone = tbEPhone.Text; user.EAddress = tbEAddress.Text; user.Address1 = tbPAddess1.Text; user.Address2 = tbPAddess2.Text; user.City = tbPCity.Text; user.Province = tbPProvince.Text; user.PostalCode = tbPPostal.Text; user.HomePhone = tbPHomePhone.Text; user.CellPhone = tbPCell.Text; user.PersonalEmail = tbPEmail.Text; user.IsActive = true; user.CreatedId = CurrentUserId; user.CreatedDate = DateTime.Now; if (AsyncUploadPicture.UploadedFiles.Count > 0) { UploadedFile file = AsyncUploadPicture.UploadedFiles[0]; byte[] fileData = new byte[file.InputStream.Length]; file.InputStream.Read(fileData, 0, (int)file.InputStream.Length); user.Picture = fileData; } int newUserId = cUser.Add(user); if (newUserId > 0) { var tempSupervisor = user.Supervisor ?? CConstValue.UserSystemId; var cApproval = new CApproval(); var approval = cApproval.GetAppType(tempSupervisor); foreach (var a in approval) { var type = new Approval(); type.ApproveType = a.ApproveType; type.UserId = newUserId; type.Supervisor = a.UserId; type.IsActive = true; type.CreatedId = CurrentUserId; type.CreatedDate = DateTime.Now; cApproval.Add(type); } // vacation Schema var cVacationSchema = new CVacationSchema(); var isKgic = new CSite().Get(new CSiteLocation().Get(user.SiteLocationId).SiteId).Abbreviation.ToLower() == "kgic"; for (var i = 1; i <= 6; i++) { var vacationType = 0; var date = i % 2 == 0 ? DateTime.Today.AddYears(1) : DateTime.Today; switch (i) { case 1: case 2: vacationType = (int)CConstValue.VacationType.PaidVacationDay; break; case 3: case 4: vacationType = (int)CConstValue.VacationType.SickDay; break; case 5: case 6: if (isKgic == false) { continue; } vacationType = (int)CConstValue.VacationType.EntitlementDay; break; } cVacationSchema.Add(new VacationSchema { Date = date, UserId = newUserId, VacationType = vacationType, TotalDays = 0, CreatedId = CurrentUserId, CreatedDate = DateTime.Now }); } // user permission new CUserPermission().SetBasicPermission(user, CurrentUserId); RadGridUser.Rebind(); ShowMessage(new CUser().GetUserName(user) + " has been successfully created"); } else { ShowMessage("Failed To Add Staff Info"); } } } else if (e.Item.Text == "Permission") { if (RadGridUser.SelectedValue != null) { RunClientScript("ShowPermission(" + RadGridUser.SelectedValue + ");"); } } else if (e.Item.Text == "User Information") { if (RadGridUser.SelectedValue != null) { RunClientScript("ShowUserInformation(" + RadGridUser.SelectedValue + ");"); } } }