示例#1
0
        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);
                }
            }
        }
示例#2
0
        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);
                }
            }
        }