public bool DeletePRByIds(string deleteKeys, ref string strError) { List <string> listKeys = deleteKeys.Split(',').ToList(); using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { List <CasContractFilingEntity> listContractFilings = new List <CasContractFilingEntity>(); foreach (string id in listKeys) { listContractFilings.Add(GetById <CasContractFilingEntity>(id)); } broker.BeginTransaction(); DataAccess.Delete <CasContractFilingEntity>(listContractFilings, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
/// <summary> /// 保存到目标数据库 /// </summary> /// <param name="tableMap"></param> /// <param name="dtSource"></param> private void SaveToTargetDB(TableMap tableMap, DataTable dtSource) { // 目标为数据表的情况 string curProcess = ""; DataAccessBroker broker = DataAccessFactory.Instance(this.TargetDataAccessCfg); try { // 事务开始 curProcess = "事务开始"; broker.BeginTransaction(); DatabaseCommand.SaveToTargetDB(broker, tableMap, dtSource); // 事务提交 curProcess = "事务提交"; broker.Commit(); } catch (Exception ex) { // 事务回滚 broker.RollBack(); throw ex; } finally { broker.Close(); } // 写日志 LogManager.Current.WriteCommonLog(this.JobCode, "成功将数据保存到目标表" + tableMap.TargetTable.TableName, this.ThreadName); }
/// <summary> /// 用户开始注册,生成手机短信的验证码 /// </summary> /// <param name="phone"></param> /// <param name="userName"></param> /// <returns></returns> public string NewUserSentSMSCode(string phone, string userName, string flagstatus) { Random rd = new Random(); var aa = rd.Next(1000, 10000); string SMSCode = aa.ToString(); using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { string sql = @" INSERT INTO [eContract].[dbo].[UserPhoneSMSCode](phonenumber,sendtime,expiretime,smscode,spare2,SMSId,flagstatus) VALUES ( '" + phone + "', GETDATE() , 20 ,'" + SMSCode + "','',NEWID(),'" + flagstatus + "')"; var success = broker.ExecuteSQL(sql); broker.Commit(); } catch (Exception e) { } } /*var reciever = emailAddress; * var cc = ""; * var title = "用户注册"; * var content = "感谢您注册磐石系统账号,您的验证码是:" + verificationCode; * LubrSentMail lubrmial = new LubrSentMail(); * lubrmial.SendEmail(reciever, title, content, null);*/ return(SMSCode); }
/// <summary> /// 新增POApprovalSet /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool InsertApprovalSet(CasPoApprovalSettingsEntity entity) { var poApprovalSetEntities = new List <CasPoApprovalSettingsEntity>(); string[] userId = entity.ApprovalUserValue.ToString().Split(','); for (int i = 0; i < userId.Length; i++) { var poApprovalSetEntity = new CasPoApprovalSettingsEntity(); poApprovalSetEntity.PoApprovalId = Guid.NewGuid().ToString(); poApprovalSetEntity.Company = entity.Company; poApprovalSetEntity.ContractTypeId = entity.ContractTypeId; poApprovalSetEntity.UserId = userId[i]; poApprovalSetEntity.CreatedBy = WebCaching.UserId; poApprovalSetEntity.CreateTime = DateTime.Now; poApprovalSetEntity.LastModifiedBy = WebCaching.UserId; poApprovalSetEntity.LastModifiedTime = DateTime.Now; poApprovalSetEntities.Add(poApprovalSetEntity); } using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); DataAccess.Insert <CasPoApprovalSettingsEntity>(poApprovalSetEntities, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } //return true; }
/// <summary> /// 用户开始注册,生成邮箱的验证码 /// </summary> /// <param name="phone"></param> /// <param name="userName"></param> /// <param name="emailAddress"></param> /// <returns></returns> public string NewUserSentVerificationCode(string phone, string userName, string emailAddress) { Random rd = new Random(); var aa = rd.Next(100000, 999999); string verificationCode = aa.ToString(); emailAddress = emailAddress.TrimStart().TrimEnd(); using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { string sql = @" INSERT INTO dbo.[User]( userid ,username ,password ,age ,realname ,idcard ,userclass ,createtime ,endtime ,logintime ,emailaddress ,phonenumber,VerificationCode) VALUES ( NEWID() ,'" + userName + "' ,'' ,0 ,'" + userName + "' ,'' ,0 ,GETDATE() ,GETDATE() ,GETDATE() ,'" + emailAddress + "' ,'" + phone + "','" + verificationCode + "')"; var success = broker.ExecuteSQL(sql); broker.Commit(); } catch (Exception e) { } } var reciever = emailAddress; var cc = ""; var title = "用户注册"; var content = "感谢您注册磐石系统账号,您的验证码是:" + verificationCode; LubrSentMail lubrmial = new LubrSentMail(); lubrmial.SendEmail(reciever, title, content, null); return(""); }
/// <summary> /// 删除部门 /// </summary> /// <param name="DeptIds"></param> /// <returns></returns> public virtual bool DeleteDepartmentDomain(List <string> DeptIds) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { List <CasDeptUserEntity> lDeptUser = new List <CasDeptUserEntity>(); List <CasDepartmentEntity> lDepartment = new List <CasDepartmentEntity>(); foreach (string id in DeptIds) { lDepartment.Add(GetById <CasDepartmentEntity>(id)); lDeptUser.AddRange(GetDeptUserDomainByDeptID(id)); } broker.BeginTransaction(); DataAccess.Delete <CasDepartmentEntity>(lDepartment, broker); DataAccess.Delete <CasDeptUserEntity>(lDeptUser, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
public virtual bool DeleteUserByIdList(List <string> idList, string userid) { string sql = ""; using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { foreach (string id in idList) { sql = "UPDATE " + CasUserTable.C_TableName; //sql += " SET " + CasUserTable.C_IS_DELETE + "=1 "; sql += " WHERE " + CasUserTable.C_USER_ID + "='" + id + "'"; broker.ExecuteSQL(sql); } broker.Commit(); WebCaching.UserCaching = null; return(true); } catch { broker.RollBack(); return(false); } } }
public bool UpdatePageControls(string pageID, int pageType, List <SecPageControlEntity> list) { List <SecPageControlEntity> oldPageControls = GetPageControls(pageID, pageType); List <SecPageControlEntity> insertList = new List <SecPageControlEntity>(); List <SecPageControlEntity> updateList = new List <SecPageControlEntity>(); List <SecPageControlEntity> deleteList = new List <SecPageControlEntity>(); foreach (var item1 in oldPageControls) { bool find = false; foreach (var item2 in list) { if (item2.ControlId == item1.ControlId) { find = true; if (item1.ControlName != item2.ControlName || item1.ServerId != item2.ServerId) { updateList.Add(item2); } } } if (!find) { deleteList.Add(item1); } } foreach (var item2 in list) { if (string.IsNullOrEmpty(item2.ControlId)) { item2.ControlId = Guid.NewGuid().ToString(); insertList.Add(item2); } } using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); DataAccess.Update(updateList, broker); DataAccess.Insert(insertList, broker); foreach (var item in deleteList) { broker.ExecuteSQL("DELETE FROM [SEC_ROLE_CONTROL] WHERE [CONTROL_ID]='" + item.ControlId + "' and [PAGE_TYPE]=" + pageType); } DataAccess.Delete(deleteList, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
public virtual bool Save(CasDepartmentDomain casDepartmentDomain, ref string strError) { casDepartmentDomain.CasDepartmentEntity.LastModifiedTime = DateTime.Now; casDepartmentDomain.CasDepartmentEntity.LastModifiedBy = WebCaching.UserId; bool isSuccess = true; using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); if (!string.IsNullOrEmpty(casDepartmentDomain.CasDepartmentEntity.DeptId)) { isSuccess = Update(casDepartmentDomain.CasDepartmentEntity, broker); if (isSuccess && casDepartmentDomain.CasDepartmentEntity.DeptType.HasValue && casDepartmentDomain.CasDepartmentEntity.DeptType.Value == 2) { isSuccess = UpdateDepartmentInfo(casDepartmentDomain, broker); } } else { casDepartmentDomain.CasDepartmentEntity.DeptId = Guid.NewGuid().ToString(); isSuccess = Insert(casDepartmentDomain.CasDepartmentEntity, broker); if (isSuccess && casDepartmentDomain.CasDepartmentEntity.DeptType.HasValue && casDepartmentDomain.CasDepartmentEntity.DeptType.Value == 2) { isSuccess = UpdateDepartmentInfo(casDepartmentDomain, broker); } } if (isSuccess) { broker.Commit(); } else { strError = "Update failed"; broker.RollBack(); } } catch (Exception ex) { broker.RollBack(); strError = ex.Message; } } return(isSuccess); }
/// <summary> /// 更新合同审批 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool UpdateApprovalEntites(CasContractApprovalStepEntity entity) { if (string.IsNullOrWhiteSpace(entity.ContractApprovalStepId)) { return(false); } var strsql = new StringBuilder(); strsql.AppendFormat("DELETE FROM CAS_CONTRACT_APPROVAL_STEP_APPROVAL_DEPT WHERE CONTRACT_APPROVAL_STEP_ID= {0}", Utils.ToSQLStr(entity.ContractApprovalStepId).Trim()); var val = DataAccess.SelectScalar(strsql.ToString()); var approvalEntites = new List <CasContractApprovalStepApprovalDeptEntity>(); string[] approvalD = new string[] { }; if (!string.IsNullOrWhiteSpace(entity.ExaminationValue)) { approvalD = entity.ExaminationValue.ToString().Split(','); } for (int j = 0; j < approvalD.Length; j++) { var approvalEntity = new CasContractApprovalStepApprovalDeptEntity(); approvalEntity.ContractApprovalStepApprovalDeptId = Guid.NewGuid().ToString(); approvalEntity.ContractApprovalStepId = entity.ContractApprovalStepId; approvalEntity.DeptId = approvalD[j]; approvalEntity.CreatedBy = WebCaching.UserId; approvalEntity.CreateTime = DateTime.Now; approvalEntity.LastModifiedBy = WebCaching.UserId; approvalEntity.LastModifiedTime = DateTime.Now; approvalEntites.Add(approvalEntity); } using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); DataAccess.Insert <CasContractApprovalStepApprovalDeptEntity>(approvalEntites, broker); DataAccess.Update(entity, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
/// <summary> /// 跟新用户的登录密码 /// </summary> /// <param name="userEntity"></param> public void UpdateUser(LubrUserEntity userEntity) { //首先我得获取用户的id var phone = userEntity.phonenumber.ToString().Trim(); var account = userEntity.username.ToString().Trim(); var userID = GetUserIdByPhoneAndAccount(phone, account); using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); CasUserEntity user = SystemService.UserService.GetById <CasUserEntity>(userID); user.Password = Encryption.Encrypt(userEntity.password); user.LastModifiedBy = "忘记密码"; user.LastModifiedTime = DateTime.Now; DataAccess.Update(user, broker); broker.Commit(); } }
/// <summary> /// 删除实体 /// </summary> public virtual bool Delete <T>(List <string> listId) where T : EntityBase, new() { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); Delete <T>(listId, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); Log(ex); return(false); } } }
/// <summary> /// 操作RoleUser提交功能,先删除,后插入 /// </summary> /// <param name="userIds"></param> /// <returns></returns> public virtual bool SaveFunctionRoleUserDomain(List <SecUserRoleEntity> DeleteDic, List <SecUserRoleEntity> InsertDic) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); DataAccess.Delete <SecUserRoleEntity>(DeleteDic, broker); DataAccess.Insert <SecUserRoleEntity>(InsertDic, broker); broker.Commit(); return(true); } catch { broker.RollBack(); return(false); } } }
/// <summary> /// 初始化选中年份所有周六、周日为非工作日 /// </summary> /// <param name="year"></param> /// <returns></returns> public virtual bool InitHoliday(string year, ref string strError) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { string startDate = year + "-01-01"; string endDate = year + "-12-31"; broker.BeginTransaction(); string sqlString = "DELETE FROM CAS_HOLIDAY WHERE HOLIDAY_DATE >= '" + startDate + "' AND HOLIDAY_DATE <= '" + endDate + "'"; broker.ExecuteNonQuery(sqlString, null, CommandType.Text); DateTime dtStartDate = DateTime.Parse(startDate); DateTime dtEndDate = DateTime.Parse(endDate); for (DateTime dt = dtStartDate; dt <= dtEndDate; dt = dt.AddDays(1)) { if (((int)dt.DayOfWeek == 0) || ((int)dt.DayOfWeek == 6)) { CasHolidayEntity casHolidayEntity = new CasHolidayEntity(); casHolidayEntity.HolidayId = Guid.NewGuid().ToString(); casHolidayEntity.HolidayDate = dt; casHolidayEntity.IsDeleted = false; casHolidayEntity.CreateTime = DateTime.Now; casHolidayEntity.CreatedBy = WebCaching.UserId; casHolidayEntity.LastModifiedTime = DateTime.Now; casHolidayEntity.LastModifiedBy = WebCaching.UserId; Insert(casHolidayEntity, broker); } } broker.Commit(); return(true); } catch (Exception ex) { strError = ex.Message; broker.RollBack(); return(false); } } }
public virtual bool DeleteApprovalStep(string ApprovalStepID) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { List <CasContractApprovalStepApplyDeptEntity> applyDeptEntity = new List <CasContractApprovalStepApplyDeptEntity>(); List <CasContractApprovalStepApprovalDeptEntity> approvalDeptEntity = new List <CasContractApprovalStepApprovalDeptEntity>(); var entity = GetById <CasContractApprovalStepEntity>(ApprovalStepID); var strsql = new StringBuilder(); strsql.AppendFormat(" SELECT CONTRACT_APPROVAL_STEP_APPLY_DEPT_ID FROM CAS_CONTRACT_APPROVAL_STEP_APPLY_DEPT WHERE CONTRACT_APPROVAL_STEP_ID='{0}'", ApprovalStepID); DataSet dataSet = DataAccess.SelectDataSet(strsql.ToString()); string[] ary = Array.ConvertAll <DataRow, string>(dataSet.Tables[0].Rows.Cast <DataRow>().ToArray(), r => r["CONTRACT_APPROVAL_STEP_APPLY_DEPT_ID"].ToString()); var strsqlAppro = new StringBuilder(); strsqlAppro.AppendFormat(" SELECT CONTRACT_APPROVAL_STEP_APPROVAL_DEPT_ID FROM CAS_CONTRACT_APPROVAL_STEP_APPROVAL_DEPT WHERE CONTRACT_APPROVAL_STEP_ID='{0}'", ApprovalStepID); DataSet dataSetAppro = DataAccess.SelectDataSet(strsqlAppro.ToString()); string[] aryAppro = Array.ConvertAll <DataRow, string>(dataSetAppro.Tables[0].Rows.Cast <DataRow>().ToArray(), r => r["CONTRACT_APPROVAL_STEP_APPROVAL_DEPT_ID"].ToString()); foreach (string id in ary) { applyDeptEntity.Add(GetById <CasContractApprovalStepApplyDeptEntity>(id)); } foreach (string id in aryAppro) { approvalDeptEntity.Add(GetById <CasContractApprovalStepApprovalDeptEntity>(id)); } broker.BeginTransaction(); DataAccess.Delete <CasContractApprovalStepApplyDeptEntity>(applyDeptEntity, broker); DataAccess.Delete <CasContractApprovalStepApprovalDeptEntity>(approvalDeptEntity, broker); Delete(entity); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
/// <summary> /// 新增用户 /// </summary> /// <param name="delUserId"></param> /// <returns></returns> public virtual bool InsertUserDomain(UserDomain userDomain) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { Insert(userDomain.CasUserEntity, broker); broker.Commit(); WebCaching.UserCaching = null; return(true); } catch (Exception ex) { broker.RollBack(); throw ex; } } }
/// <summary> /// 更新用户 /// </summary> /// <param name="userDomain"></param> /// <returns></returns> public virtual bool UpdateUserDomain(UserDomain userDomain) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { string user_id = userDomain.CasUserEntity.UserId; Update(userDomain.CasUserEntity, broker); broker.Commit(); WebCaching.UserCaching = null; return(true); } catch (Exception ex) { broker.RollBack(); SystemService.LogErrorService.InsertLog(ex); return(false); } } }
/// <summary> /// 领导批注 /// </summary> /// <param name="casContractApprovalResultEntity"></param> /// <returns></returns> public bool OptionCommnet(CasContractApprovalResultEntity casContractApprovalResultEntity) { bool flag = false; using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); try { string sql = $@"UPDATE dbo.CAS_CONTRACT_APPROVER SET STATUS = 3 WHERE APPROVER_TYPE = 1 AND CONTRACT_ID = '{casContractApprovalResultEntity.ContractId}' AND APPROVER_ID = '{casContractApprovalResultEntity.ApproverId}' AND STATUS = 2"; //审批人表更改领导批注状态为已批注 broker.ExecuteSQL(sql); //插入审批结果 flag = DataAccess.Insert(casContractApprovalResultEntity); if (flag) { broker.Commit(); } else { broker.RollBack(); } } catch (Exception e) { flag = false; broker.RollBack(); SystemService.LogErrorService.InsertLog(e); } } return(flag); }
/// <summary> /// 增加/修改角色关联的菜单 lucas 2011-04-08 /// </summary> /// <param name="oldRoleMenu"></param> /// <param name="newRoleMenu"></param> /// <returns></returns> public virtual bool AddRoleMenu(string systemName, List <RolePageDomain> oldRoleMenuDomain, List <RolePageDomain> newRoleMenuDomain) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); //获取roleMenu、DataScope 实体列表 List <SecRolePageEntity> oldRoleMenu = new List <SecRolePageEntity>(); foreach (RolePageDomain oldMenu in oldRoleMenuDomain) { oldRoleMenu.Add(oldMenu.SecRolePageEntity); } List <SecRolePageEntity> newRoleMenu = new List <SecRolePageEntity>(); foreach (RolePageDomain newMenu in newRoleMenuDomain) { newRoleMenu.Add(newMenu.SecRolePageEntity); } //执行数据操作 DataAccess.Delete <SecRolePageEntity>(oldRoleMenu, broker); DataAccess.Insert <SecRolePageEntity>(newRoleMenu, broker); UserDomain user = (new UserBLL()).GetUserDomainByUserAccount(systemName, CurrentUser.CasUserEntity.UserAccount); WebCaching.CurrentUser = user; broker.Commit(); return(true); } catch (Exception ex) { SystemService.LogErrorService.InsertLog(ex); broker.RollBack(); return(false); } } }
/// <summary> /// 删除大区 /// </summary> /// <param name="RegionIds"></param> /// <returns></returns> public virtual bool DeleteRegionDomain(List <string> RegionIds) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { List <CasRegionEntity> lRegion = new List <CasRegionEntity>(); foreach (string id in RegionIds) { lRegion.Add(GetById <CasRegionEntity>(id)); } broker.BeginTransaction(); DataAccess.Delete <CasRegionEntity>(lRegion, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
/// <summary> /// 删除角色 /// </summary> /// <param name="parameterIds"></param> /// <returns></returns> public virtual bool DeleteRoleDomain(List <string> RoleIds) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { List <SecUserRoleEntity> lUserRole; List <SecRolePageEntity> IRoleMunu; //List<SecRolePermissionEntity> IRolePermis; List <SecRoleEntity> IRoleEntity = new List <SecRoleEntity>(); IRoleMunu = new List <SecRolePageEntity>(); //IRolePermis = new List<SecRolePermissionEntity>(); lUserRole = new List <SecUserRoleEntity>(); foreach (string id in RoleIds) { lUserRole.AddRange(GetFunctionRoleUserDomainByRoleID(id)); IRoleMunu.AddRange(GetFunctionRolePageDomainByRoleID(id)); //IRolePermis.AddRange(GetFunctionRolePermissionDomainByRoleID(id)); IRoleEntity.Add(new SecRoleEntity { RoleId = id }); } broker.BeginTransaction(); DataAccess.Delete <SecUserRoleEntity>(lUserRole, broker); DataAccess.Delete <SecRolePageEntity>(IRoleMunu, broker); //DataAccess.Delete<SecRolePermissionEntity>(IRolePermis, broker); DataAccess.Delete <SecRoleEntity>(IRoleEntity, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
/// <summary> /// 注册新的用户 /// </summary> /// <param name="userEntity"></param> public void RegisterNewUser(LubrUserEntity userEntity) { using (DataAccessBroker broker = DataAccessFactory.Instance()) { broker.BeginTransaction(); CasUserEntity user = new CasUserEntity(); user.UserId = Guid.NewGuid().ToString(); user.UserAccount = userEntity.username; user.UserCode = userEntity.username; user.ChineseName = userEntity.username; user.EnglishName = userEntity.username; var password = Encryption.Encrypt(userEntity.password); user.Password = password; user.Status = 0; user.IsDeleted = false; user.CreatedBy = "self"; user.CreateTime = DateTime.Now; user.LastModifiedBy = "self"; user.LastModifiedTime = DateTime.Now; user.PhoneNumber = userEntity.phonenumber; DataAccess.Insert(user, broker); broker.Commit(); } }
/// <summary> /// 保存新增数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool InsertApprovalEntites(CasContractApprovalStepEntity entity) { var applyEntites = new List <CasContractApprovalStepApplyDeptEntity>(); var approvalEntites = new List <CasContractApprovalStepApprovalDeptEntity>(); string[] applyID; if (entity.ApprovalRole == ApplyTypeEnum.AllDepartment.GetHashCode()) { applyID = GetAllDepartmentID(); entity.ApprovalRole = ApplyTypeEnum.Department.GetHashCode(); } else { if (!string.IsNullOrWhiteSpace(entity.ApprovalDepValue) && entity.ApprovalRole == ApplyTypeEnum.Department.GetHashCode()) { applyID = entity.ApprovalDepValue.ToString().Split(','); } else { applyID = entity.ApprovalUserValue.ToString().Split(','); } } string[] approvalD = new string[] { }; if (!string.IsNullOrWhiteSpace(entity.ExaminationValue)) { approvalD = entity.ExaminationValue.ToString().Split(','); } for (int i = 0; i < applyID.Length; i++) { var applyEntity = new CasContractApprovalStepApplyDeptEntity(); applyEntity.ContractApprovalStepApplyDeptId = Guid.NewGuid().ToString(); applyEntity.ContractApprovalStepId = entity.ContractApprovalStepId; applyEntity.ApplyType = (int)entity.ApprovalRole; applyEntity.DeptId = applyID[i]; applyEntity.CreatedBy = WebCaching.UserId; applyEntity.CreateTime = DateTime.Now; applyEntity.LastModifiedBy = WebCaching.UserId; applyEntity.LastModifiedTime = DateTime.Now; applyEntites.Add(applyEntity); } for (int j = 0; j < approvalD.Length; j++) { var approvalEntity = new CasContractApprovalStepApprovalDeptEntity(); approvalEntity.ContractApprovalStepApprovalDeptId = Guid.NewGuid().ToString(); approvalEntity.ContractApprovalStepId = entity.ContractApprovalStepId; approvalEntity.DeptId = approvalD[j]; approvalEntity.CreatedBy = WebCaching.UserId; approvalEntity.CreateTime = DateTime.Now; approvalEntity.LastModifiedBy = WebCaching.UserId; approvalEntity.LastModifiedTime = DateTime.Now; approvalEntites.Add(approvalEntity); } using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); DataAccess.Insert <CasContractApprovalStepApplyDeptEntity>(applyEntites, broker); DataAccess.Insert <CasContractApprovalStepApprovalDeptEntity>(approvalEntites, broker); DataAccess.Insert(entity, broker); broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } }
public bool Save(CasProxyApprovalEntity entity, ref string strError) { if (!string.IsNullOrEmpty(entity.ProxyApprovalId)) { List <string> agentUserIds = entity.AgentUserId.Split(',').ToList(); using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); Delete <CasProxyApprovalEntity>(new List <string> { entity.ProxyApprovalId }, broker); foreach (string agentUserId in agentUserIds) { CasProxyApprovalEntity casProxyApprovalEntity = new CasProxyApprovalEntity(); casProxyApprovalEntity.ProxyApprovalId = Guid.NewGuid().ToString(); casProxyApprovalEntity.AgentUserId = agentUserId; casProxyApprovalEntity.AuthorizedUserId = entity.AuthorizedUserId; casProxyApprovalEntity.BeginTime = entity.BeginTime; casProxyApprovalEntity.EndTime = entity.EndTime; casProxyApprovalEntity.IsDeleted = false; casProxyApprovalEntity.CreateTime = DateTime.Now; casProxyApprovalEntity.CreatedBy = WebCaching.UserId; casProxyApprovalEntity.LastModifiedTime = DateTime.Now; casProxyApprovalEntity.LastModifiedBy = WebCaching.UserId; casProxyApprovalEntity.TerminationTime = null;// entity.EndTime; Insert(casProxyApprovalEntity, broker); } broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } } else { List <string> agentUserIds = entity.AgentUserId.Split(',').ToList(); using (DataAccessBroker broker = DataAccessFactory.Instance()) { try { broker.BeginTransaction(); foreach (string agentUserId in agentUserIds) { CasProxyApprovalEntity casProxyApprovalEntity = new CasProxyApprovalEntity(); casProxyApprovalEntity.ProxyApprovalId = Guid.NewGuid().ToString(); casProxyApprovalEntity.AgentUserId = agentUserId; casProxyApprovalEntity.AuthorizedUserId = entity.AuthorizedUserId; casProxyApprovalEntity.BeginTime = entity.BeginTime; casProxyApprovalEntity.EndTime = entity.EndTime; casProxyApprovalEntity.IsDeleted = false; casProxyApprovalEntity.CreateTime = DateTime.Now; casProxyApprovalEntity.CreatedBy = WebCaching.UserId; casProxyApprovalEntity.LastModifiedTime = DateTime.Now; casProxyApprovalEntity.LastModifiedBy = WebCaching.UserId; casProxyApprovalEntity.TerminationTime = null;//entity.EndTime; Insert(casProxyApprovalEntity, broker); } broker.Commit(); return(true); } catch (Exception ex) { broker.RollBack(); return(false); } } } }
/// <summary> /// 保存header和detail到数据,一笔header与对应的几笔detail作为一个事务 /// </summary> /// <param name="dtHeader"></param> /// <param name="dtDetail"></param> private void SaveHeaderDetailToTarget(ref Hashtable parameters, DataTable dtHeader, DataTable dtDetail, string dataSplitOperator) { List <string> dataIDList = (List <string>)parameters[DDPConst.Param_DataIDList]; int nError = 0; int nSuccess = 0; DataAccessBroker brokerTarget = DataAccessFactory.Instance(this.TargetDataAccessCfg); try { // header sql this.HeaderTableMap.InitialFieldMapByDataTable(dtHeader); string insertSqlHeader = this.HeaderTableMap.GetTargetInsertSQL(brokerTarget.ParameterPrefix.ToString()); // detail sql if (dtDetail.Rows.Count > 0) { this.DetailTableMap.InitialFieldMapByDataTable(dtDetail.Rows[0]); } string insertSqlDetail = this.DetailTableMap.GetTargetInsertSQL(brokerTarget.ParameterPrefix.ToString()); for (int i = 0; i < dtHeader.Rows.Count; i++) { Application.DoEvents(); string recordsCondition = ""; // 一条header DataRow rowHeader = dtHeader.Rows[i]; // 一笔完整的记录一个事务,包括header和detail brokerTarget.BeginTransaction(); try { // 并出关联字段及值,便出检索detail string refFieldSql = ""; string refValueSql = ""; string[] refFieldList = this.DetailTableMap.SourceTable.RefFields.Split(new char[] { ',' }); for (int x = 0; x < refFieldList.Length; x++) { string refField = refFieldList[x]; if (refFieldSql != "") { refFieldSql += "+'|'+"; } refFieldSql += refField; if (refValueSql != "") { refValueSql += "|"; } refValueSql += rowHeader[refField].ToString(); } recordsCondition = refFieldSql + "='" + refValueSql + "'"; // 找到Detail数据 DataRow[] detailRowList = dtDetail.Select(recordsCondition); LogManager.Current.WriteCommonLog(this.JobCode, refValueSql + "对应" + detailRowList.Length.ToString() + "条detail记录。", this.ThreadName); // 将header插入到数据库 DataAccessParameterCollection dpcHeader = this.HeaderTableMap.GetTargetParameters(rowHeader, this.HeaderTableMap.TargetTable.NullFieldNameList); brokerTarget.ExecuteSQL(insertSqlHeader, dpcHeader); // 将detail插入到数据库 for (int j = 0; j < detailRowList.Length; j++) { // detail DataRow rowDetail = detailRowList[j]; DataAccessParameterCollection dpcDetail = this.DetailTableMap.GetTargetParameters(rowDetail, this.DetailTableMap.TargetTable.NullFieldNameList); brokerTarget.ExecuteSQL(insertSqlDetail, dpcDetail); } // 事务提交 brokerTarget.Commit(); LogManager.Current.WriteCommonLog(this.JobCode, recordsCondition + "记录保存数据库成功。", this.ThreadName); nSuccess++; } catch (Exception ex) { // 事务回滚 brokerTarget.RollBack(); LogManager.Current.WriteErrorLog(this.JobCode, recordsCondition + "记录保存数据库出错:" + ex.Message, this.ThreadName); // 从DataIDList中移出此笔记录,这样就不会更新最新时间了 string dataID = this.GetFieldValue(rowHeader, this.HeaderTableMap.SourceTable.PrimaryKeys, dataSplitOperator); dataIDList.Remove(dataID); nError++; // 继续下面的记录 continue; } } } catch (Exception ex) { throw ex; } finally { brokerTarget.Close(); } // 写日志 string errorInfo = "来源共" + dtHeader.Rows.Count.ToString() + "笔记录," + nSuccess.ToString() + "笔保存成功," + nError.ToString() + "笔保存失败。"; LogManager.Current.WriteCommonLog(this.JobCode, errorInfo, this.ThreadName); // 保存到参数里,传给外面 parameters[DDPConst.Param_Info] = errorInfo; // 将错误的记录数保存在参数里 if (nError > 0) { parameters[DDPConst.Param_ErrorCount] = nError; } }