public bool IsExistRecord(object KeyObject) { using (VPMSDBDataContext db = new VPMSDBDataContext()) { DataRightsRole_drr drr = new DataRightsRole_drr(); try { drr = Common.General.CopyObjectValue <object, DataRightsRole_drr>(KeyObject); IQueryable <DataRightsRole_drr> taQuery = (from ta in db.DataRightsRole_drrs where ta.drr_cNumber == drr.drr_cNumber select ta); if (taQuery.Count() > 0) { return(true); } else { return(false); } } catch (Exception Ex) { throw Ex; } } }
public bool DeleteRecord(Model.IModel.IModelObject KeyObject) { DataRightsRole_drr_Info info = null; info = KeyObject as DataRightsRole_drr_Info; using (VPMSDBDataContext db = new VPMSDBDataContext()) { try { db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); DataRightsRole_drr drr = db.DataRightsRole_drrs.Single <DataRightsRole_drr>(i => i.drr_iRecordID == info.drr_iRecordID); IEnumerable <DataRightsRole_TeacherList_dtl> _teacher = from t in db.DataRightsRole_TeacherList_dtls where t.dtl_cRoleNumber == drr.drr_cNumber select t; db.DataRightsRole_TeacherList_dtls.DeleteAllOnSubmit(_teacher); db.SubmitChanges(); IEnumerable <DataRightsRole_ClassList_dtc> _class = from t in db.DataRightsRole_ClassList_dtcs where t.dtc_cRoleNumber == drr.drr_cNumber select t; db.DataRightsRole_ClassList_dtcs.DeleteAllOnSubmit(_class); db.SubmitChanges(); IEnumerable <DataRightsRoleUser_dru> _roleUser = from t in db.DataRightsRoleUser_drus where t.dru_cRoleNumber == drr.drr_cNumber select t; db.DataRightsRoleUser_drus.DeleteAllOnSubmit(_roleUser); db.SubmitChanges(); //for (int i = 0; i < drr.DataRightsRole_TeacherList_dtls.Count; i++) //{ // DataRightsRole_TeacherList_dtl sta = drr.DataRightsRole_TeacherList_dtls[i]; // db.DataRightsRole_TeacherList_dtls.DeleteOnSubmit(sta); //} //for (int i = 0; i < drr.DataRightsRole_ClassList_dtcs.Count; i++) //{ // DataRightsRole_ClassList_dtc sta = drr.DataRightsRole_ClassList_dtcs[i]; // db.DataRightsRole_ClassList_dtcs.DeleteOnSubmit(sta); //} db.DataRightsRole_drrs.DeleteOnSubmit(drr); db.SubmitChanges(); db.Transaction.Commit(); return(true); } catch (Exception Ex) { db.Transaction.Rollback(); return(false); } } }
public bool UpdateRecord(DataRightsRole_drr_Info infoObject) { string sqlString = string.Empty; using (VPMSDBDataContext db = new VPMSDBDataContext()) { DataRightsRole_drr_Info info = new DataRightsRole_drr_Info(); DataRightsRole_drr drrInfo = new DataRightsRole_drr(); try { drrInfo = db.DataRightsRole_drrs.SingleOrDefault(t => t.drr_iRecordID == infoObject.drr_iRecordID); IEnumerable <DataRightsRole_TeacherList_dtl> _teacher = (from ta in db.DataRightsRole_TeacherList_dtls where ta.dtl_cRoleNumber == infoObject.drr_cNumber orderby ta.dtl_iRecordID ascending select ta); db.DataRightsRole_TeacherList_dtls.DeleteAllOnSubmit(_teacher); db.SubmitChanges(); //foreach (var item in _teacher) //{ // db.DataRightsRole_TeacherList_dtls.DeleteOnSubmit(item); // db.SubmitChanges(); //} IEnumerable <DataRightsRole_ClassList_dtc> _class = (from ta in db.DataRightsRole_ClassList_dtcs where ta.dtc_cRoleNumber == infoObject.drr_cNumber orderby ta.dtc_iRecordID ascending select ta); db.DataRightsRole_ClassList_dtcs.DeleteAllOnSubmit(_class); db.SubmitChanges(); //foreach (var item in _class) //{ // db.DataRightsRole_ClassList_dtcs.DeleteOnSubmit(item); // db.SubmitChanges(); //} info = Common.General.CopyObjectValue <DataRightsRole_drr, DataRightsRole_drr_Info>(drrInfo); IEnumerable <DataRightsRole_drr_Info> IDrr = null; IEnumerable <DataRightsRole_TeacherList_dtl_Info> ITeacher = null; IEnumerable <DataRightsRole_ClassList_dtc_Info> IClass = null; sqlString += " UPDATE DataRightsRole_drr" + Environment.NewLine; sqlString += " SET drr_cNumber='" + infoObject.drr_cNumber + "'," + Environment.NewLine; sqlString += " drr_cName='" + infoObject.drr_cName + "'," + Environment.NewLine; sqlString += " drr_cRemark='" + infoObject.drr_cRemark + "'," + Environment.NewLine; sqlString += " drr_cLast='" + infoObject.drr_cLast + "'," + Environment.NewLine; sqlString += " drr_dLastDate='" + infoObject.drr_dLastDate.Value.ToString(DefineConstantValue.gc_DateTimeFormat) + "'" + Environment.NewLine; sqlString += " WHERE drr_iRecordID='" + infoObject.drr_iRecordID + "'"; IDrr = db.ExecuteQuery <DataRightsRole_drr_Info>(sqlString, new object[] { }); if (infoObject.teacherList != null && infoObject.teacherList.Count > 0) { for (int i = 0; i < infoObject.teacherList.Count; i++) { sqlString = string.Empty; DataRightsRole_TeacherList_dtl_Info teacherInfo = infoObject.teacherList[i]; sqlString += "INSERT INTO DataRightsRole_TeacherList_dtl" + Environment.NewLine; sqlString += "(dtl_cRoleNumber, dtl_cDataRightType,dtl_iIsAllRights,dtl_cTeacherNum)" + Environment.NewLine; sqlString += " VALUES " + Environment.NewLine; sqlString += "('" + infoObject.drr_cNumber + "','" + teacherInfo.dtl_cDataRightType + "','" + teacherInfo.dtl_iIsAllRights + "','" + teacherInfo.dtl_cTeacherNum + "')"; ITeacher = db.ExecuteQuery <DataRightsRole_TeacherList_dtl_Info>(sqlString, new object[] { }); } } if (infoObject.classList != null && infoObject.classList.Count > 0) { for (int i = 0; i < infoObject.classList.Count; i++) { sqlString = string.Empty; DataRightsRole_ClassList_dtc_Info classInfo = infoObject.classList[i]; sqlString += "INSERT INTO DataRightsRole_ClassList_dtc" + Environment.NewLine; sqlString += "(dtc_cRoleNumber, dtc_cDataRightType,dtc_iIsAllRights,dtc_cSchoolNum,dtc_cSpecialtyNum,dtc_cGraduationPeriod,dtc_cClassNum)" + Environment.NewLine; sqlString += " VALUES " + Environment.NewLine; sqlString += "('" + infoObject.drr_cNumber + "','" + classInfo.dtc_cDataRightType + "','" + classInfo.dtc_iIsAllRights + "','" + classInfo.dtc_cSchoolNum + "','" + classInfo.dtc_cSpecialtyNum + "','" + classInfo.dtc_cGraduationPeriod + "','" + classInfo.dtc_cClassNum + "')"; IClass = db.ExecuteQuery <DataRightsRole_ClassList_dtc_Info>(sqlString, new object[] { }); } } return(true); } catch { return(false); } } }
public bool InsertRecord(DataRightsRole_drr_Info infoObject) { if (infoObject == null) { return(false); } using (VPMSDBDataContext db = new VPMSDBDataContext()) { db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); DataRightsRole_drr drr = new DataRightsRole_drr(); try { if (infoObject.teacherList != null && infoObject.teacherList.Count > 0) { for (int i = 0; i < infoObject.teacherList.Count; i++) { DataRightsRole_TeacherList_dtl_Info teacherInfo = infoObject.teacherList[i]; DataRightsRole_TeacherList_dtl item = new DataRightsRole_TeacherList_dtl(); item.dtl_cRoleNumber = infoObject.drr_cNumber; item.dtl_cDataRightType = teacherInfo.dtl_cDataRightType; item.dtl_iIsAllRights = teacherInfo.dtl_iIsAllRights; item.dtl_cTeacherNum = teacherInfo.dtl_cTeacherNum; //drr.DataRightsRole_TeacherList_dtls.Add(item); db.DataRightsRole_TeacherList_dtls.InsertOnSubmit(item); db.SubmitChanges(); } } if (infoObject.classList != null && infoObject.classList.Count > 0) { for (int i = 0; i < infoObject.classList.Count; i++) { DataRightsRole_ClassList_dtc_Info classInfo = infoObject.classList[i]; DataRightsRole_ClassList_dtc item = new DataRightsRole_ClassList_dtc(); item.dtc_cRoleNumber = infoObject.drr_cNumber; item.dtc_cDataRightType = classInfo.dtc_cDataRightType; item.dtc_iIsAllRights = classInfo.dtc_iIsAllRights; item.dtc_cSchoolNum = classInfo.dtc_cSchoolNum; item.dtc_cSpecialtyNum = classInfo.dtc_cSpecialtyNum; item.dtc_cGraduationPeriod = classInfo.dtc_cGraduationPeriod; item.dtc_cClassNum = classInfo.dtc_cClassNum; //drr.DataRightsRole_ClassList_dtcs.Add(item); db.DataRightsRole_ClassList_dtcs.InsertOnSubmit(item); db.SubmitChanges(); } } infoObject.drr_cLast = infoObject.drr_cAdd; drr = Common.General.CopyObjectValue <DataRightsRole_drr_Info, DataRightsRole_drr>(infoObject); db.DataRightsRole_drrs.InsertOnSubmit(drr); db.SubmitChanges(); // db.SubmitChanges(); db.Transaction.Commit(); return(true); } catch (Exception Ex) { db.Transaction.Rollback(); return(false); } } }