public bool DeleteRecord(Model.IModel.IModelObject KeyObject) { Sys_RoleMaster_rlm_Info info = null; try { info = KeyObject as Sys_RoleMaster_rlm_Info; using (VPMSDBDataContext db = new VPMSDBDataContext()) { Sys_RoleMaster_rlm rlm = db.Sys_RoleMaster_rlms.Single <Sys_RoleMaster_rlm>(i => i.rlm_iRecordID == info.rlm_iRecordID); for (int i = 0; i < rlm.Sys_UserRoles_usrs.Count; i++) { Sys_UserRoles_usr sta = rlm.Sys_UserRoles_usrs[i]; db.Sys_UserRoles_usrs.DeleteOnSubmit(sta); } db.Sys_RoleMaster_rlms.DeleteOnSubmit(rlm); db.SubmitChanges(); return(true); } } catch (Exception Ex) { throw Ex; } }
public bool InsertRecord(Sys_RoleMaster_rlm_Info infoObject) { if (infoObject == null) { return(false); } using (VPMSDBDataContext db = new VPMSDBDataContext()) { Sys_RoleMaster_rlm rlm = new Sys_RoleMaster_rlm(); try { rlm = Common.General.CopyObjectValue <Sys_RoleMaster_rlm_Info, Sys_RoleMaster_rlm>(infoObject); if (infoObject.userMasterList != null && infoObject.userMasterList.Count > 0) { for (int i = 0; i < infoObject.userMasterList.Count; i++) { Sys_UserMaster_usm_Info usmInfo = infoObject.userMasterList[i]; Sys_UserRoles_usr item = new Sys_UserRoles_usr(); item.usr_cUserLoginID = usmInfo.usm_cUserLoginID; item.usr_cRoleID = infoObject.rlm_cRoleID; //courseitem.cum_cNumber; rlm.Sys_UserRoles_usrs.Add(item); //db.Sys_UserRoles_usrs.InsertOnSubmit(item); } } db.Sys_RoleMaster_rlms.InsertOnSubmit(rlm); db.SubmitChanges(); return(true); } catch (Exception Ex) { throw Ex; } } }
public bool UpdateRecord(Sys_RoleMaster_rlm_Info infoObject) { string sqlString = string.Empty; using (VPMSDBDataContext db = new VPMSDBDataContext()) { Sys_RoleMaster_rlm rlm = new Sys_RoleMaster_rlm(); Sys_RoleMaster_rlm_Info info = new Sys_RoleMaster_rlm_Info(); try { rlm = db.Sys_RoleMaster_rlms.SingleOrDefault(t => t.rlm_iRecordID == infoObject.rlm_iRecordID); for (int i = 0; i < rlm.Sys_UserRoles_usrs.Count; i++) { Sys_UserRoles_usr sta = rlm.Sys_UserRoles_usrs[i]; db.Sys_UserRoles_usrs.DeleteOnSubmit(sta); } info = Common.General.CopyObjectValue <Sys_RoleMaster_rlm, Sys_RoleMaster_rlm_Info>(rlm); IEnumerable <Sys_RoleMaster_rlm_Info> IErlm = null; IEnumerable <Sys_UserRoles_usr_Info> IEusr = null; sqlString += "UPDATE Sys_RoleMaster_rlm" + Environment.NewLine; sqlString += " SET rlm_cRoleID='" + infoObject.rlm_cRoleID + "'," + Environment.NewLine; sqlString += " rlm_cRoleDesc='" + infoObject.rlm_cRoleDesc + "'," + Environment.NewLine; sqlString += " rlm_cLast='" + infoObject.rlm_cLast + "'," + Environment.NewLine; sqlString += " rlm_dLastDate='" + infoObject.rlm_dLastDate.Value.ToString(DefineConstantValue.gc_DateTimeFormat) + "'" + Environment.NewLine; sqlString += " WHERE rlm_iRecordID='" + infoObject.rlm_iRecordID + "'"; IErlm = db.ExecuteQuery <Sys_RoleMaster_rlm_Info>(sqlString, new object[] { }); sqlString = string.Empty; sqlString += "DELETE FROM Sys_UserRoles_usr WHERE usr_cRoleID='" + infoObject.rlm_cRoleID + "'"; IEusr = db.ExecuteQuery <Sys_UserRoles_usr_Info>(sqlString, new object[] { }); if (infoObject.userMasterList != null && infoObject.userMasterList.Count > 0) { for (int i = 0; i < infoObject.userMasterList.Count; i++) { sqlString = string.Empty; Sys_UserMaster_usm_Info usmInfo = infoObject.userMasterList[i]; sqlString += "INSERT INTO Sys_UserRoles_usr" + Environment.NewLine; sqlString += "(usr_cUserLoginID, usr_cRoleID)" + Environment.NewLine; sqlString += " VALUES " + Environment.NewLine; sqlString += "('" + usmInfo.usm_cUserLoginID + "','" + infoObject.rlm_cRoleID + "')"; IEusr = db.ExecuteQuery <Sys_UserRoles_usr_Info>(sqlString, new object[] { }); } } //if (rlm != null) //{ // //usm = Common.General.SetDataToLingQEntity(usm, infoObject);//时间溢出 // rlm.rlm_cRoleDesc = infoObject.rlm_cRoleDesc; // rlm.rlm_cLast = infoObject.rlm_cLast; // rlm.rlm_dLastDate = infoObject.rlm_dLastDate.Value; // if (infoObject.userMasterList != null && infoObject.userMasterList.Count > 0) // { // for (int i = 0; i < infoObject.userMasterList.Count; i++) // { // Sys_UserMaster_usm_Info usmInfo = infoObject.userMasterList[i]; // Sys_UserRoles_usr item = new Sys_UserRoles_usr(); // item.usr_cUserLoginID = usmInfo.usm_cUserLoginID; // item.usr_cRoleID = infoObject.rlm_cRoleID; // //courseitem.cum_cNumber; // rlm.Sys_UserRoles_usrs.Add(item); // //db.Sys_UserRoles_usrs.InsertOnSubmit(item); // } // } // db.SubmitChanges(); //} return(true); } catch (Exception Ex) { throw Ex; } } }