Пример #1
0
        /// <summary>
        /// 执行数据同步
        /// </summary>
        private void ExecSyncData(string strFileSyncExecRecord_id)
        {
            //所有需要同步数据new
            DataTable dtAll = new DataTable();

            dtAll = new BLL_SyncData().GetList("SyncStatus='0' or SyncStatus='2' ").Tables[0];
            if (dtAll.Rows.Count > 0)
            {
                DataView dataView = dtAll.DefaultView;
                dtAll = dataView.ToTable(true, "TableName", "DataId", "OperateType");
            }

            //ResourceFolder数据
            DataTable dtRF = new DataTable();

            DataRow[] drRF = null;
            if (dtAll.Rows.Count > 0)
            {
                drRF = dtAll.Select("TableName='ResourceFolder'");
            }
            if (drRF != null && drRF.Length > 0)
            {
                dtRF = drRF.CopyToDataTable();
            }

            //ResourceToResourceFolder数据(delete)
            DataTable dtRTRF_Delete = new DataTable();

            DataRow[] drRTRF_Delete = null;
            if (dtAll.Rows.Count > 0)
            {
                drRTRF_Delete = dtAll.Select("TableName='ResourceToResourceFolder' and OperateType='delete'");
            }
            if (drRTRF_Delete != null && drRTRF_Delete.Length > 0)
            {
                dtRTRF_Delete = drRTRF_Delete.CopyToDataTable();
            }

            //ResourceToResourceFolder数据(move,rename)
            DataTable dtRTRF_MoveRename = new DataTable();

            DataRow[] drRTRF_MoveRename = null;
            if (dtAll.Rows.Count > 0)
            {
                drRTRF_MoveRename = dtAll.Select("TableName='ResourceToResourceFolder' and (OperateType='move' or OperateType='rename') ");
            }
            if (drRTRF_MoveRename != null && drRTRF_MoveRename.Length > 0)
            {
                dtRTRF_MoveRename = drRTRF_MoveRename.CopyToDataTable();
            }

            //ResourceToResourceFolder数据(add,modify)
            DataTable dtRTRF_AddModify = new DataTable();

            DataRow[] drRTRF_AddModify = null;
            if (dtAll.Rows.Count > 0)
            {
                drRTRF_AddModify = dtAll.Select("TableName='ResourceToResourceFolder' and (OperateType='modify' or OperateType='add') ");
            }
            if (drRTRF_AddModify != null && drRTRF_AddModify.Length > 0)
            {
                dtRTRF_AddModify = drRTRF_AddModify.CopyToDataTable();
            }
            if (dtRTRF_AddModify.Rows.Count > 0)
            {
                DataView dataView = dtRTRF_AddModify.DefaultView;
                dtRTRF_AddModify = dataView.ToTable(true, "DataId");
            }

            StringBuilder stbRF              = new StringBuilder();
            StringBuilder stbRTRF_Delete     = new StringBuilder();
            StringBuilder stbRTRF_MoveRename = new StringBuilder();
            StringBuilder stbRTRF_AddModify  = new StringBuilder();

            #region ①删除ResourceToResourceFolder数据(delete)
            Rc.Model.Resources.Model_FileSyncExecRecordDetail model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            Rc.BLL.Resources.BLL_FileSyncExecRecordDetail     bll_FileSyncExecRecordDetail   = new Rc.BLL.Resources.BLL_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "①删除ResourceToResourceFolder数据(delete)";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            foreach (DataRow item in dtRTRF_Delete.Rows)
            {
                stbRTRF_Delete = new StringBuilder();
                stbRTRF_Delete.Append("declare @resourceId char(36);");
                stbRTRF_Delete.AppendFormat(@"delete from TestQuestions_Option where TestQuestions_Id in(select TestQuestions_Id from TestQuestions where ResourceToResourceFolder_Id='{0}');
delete from TestQuestions_Score where ResourceToResourceFolder_Id='{0}';
delete from TestQuestions where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder_Property where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder_img where ResourceToResourceFolder_Id='{0}';
select @resourceId=Resource_Id from ResourceToResourceFolder where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder where ResourceToResourceFolder_Id='{0}';
delete from [Resource] where Resource_Id=@resourceId;", item["DataId"]);
                DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_Delete.ToString(), 7200);
                DbHelperSQL.ExecuteSqlByTime(string.Format("update SyncData set SyncStatus='1' where OperateType='delete' and DataId='{0}'; ", item["DataId"]), 60);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion

            #region ②同步ResourceFolder数据
            model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "②同步ResourceFolder数据";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            foreach (DataRow item in dtRF.Rows)
            {
                stbRF = new StringBuilder();
                #region delete
                if (item["OperateType"].ToString() == "delete")
                {
                    stbRF.AppendFormat("delete from ResourceFolder where ResourceFolder_Id='{0}'; ", item["DataId"]);
                }
                #endregion
                DataTable dtSub = new BLL_ResourceFolder().GetList("ResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                if (dtSub.Rows.Count == 1)
                {
                    #region move,rename
                    if (item["OperateType"].ToString() == "move" || item["OperateType"].ToString() == "rename")
                    {
                        stbRF.Append("update ResourceFolder set ");
                        stbRF.AppendFormat("ResourceFolder_ParentId='{0}',", dtSub.Rows[0]["ResourceFolder_ParentId"]);
                        stbRF.AppendFormat("ResourceFolder_Name=N'{0}',", dtSub.Rows[0]["ResourceFolder_Name"]);
                        stbRF.AppendFormat("ResourceFolder_Level='{0}',", dtSub.Rows[0]["ResourceFolder_Level"]);
                        stbRF.AppendFormat("Resource_Type='{0}',", dtSub.Rows[0]["Resource_Type"]);
                        stbRF.AppendFormat("Resource_Class='{0}',", dtSub.Rows[0]["Resource_Class"]);
                        stbRF.AppendFormat("Resource_Version='{0}',", dtSub.Rows[0]["Resource_Version"]);
                        stbRF.AppendFormat("ResourceFolder_Remark='{0}',", dtSub.Rows[0]["ResourceFolder_Remark"]);
                        stbRF.AppendFormat("ResourceFolder_Order='{0}',", dtSub.Rows[0]["ResourceFolder_Order"]);
                        stbRF.AppendFormat("ResourceFolder_Owner='{0}',", dtSub.Rows[0]["ResourceFolder_Owner"]);
                        stbRF.AppendFormat("CreateFUser='******',", dtSub.Rows[0]["CreateFUser"]);
                        stbRF.AppendFormat("CreateTime='{0}',", dtSub.Rows[0]["CreateTime"]);
                        stbRF.AppendFormat("ResourceFolder_isLast='{0}',", dtSub.Rows[0]["ResourceFolder_isLast"]);
                        stbRF.AppendFormat("LessonPlan_Type='{0}',", dtSub.Rows[0]["LessonPlan_Type"]);
                        stbRF.AppendFormat("GradeTerm='{0}',", dtSub.Rows[0]["GradeTerm"]);
                        stbRF.AppendFormat("Subject='{0}',", dtSub.Rows[0]["Subject"]);
                        stbRF.AppendFormat("Book_ID='{0}',", dtSub.Rows[0]["Book_ID"]);
                        stbRF.AppendFormat("ParticularYear='{0}'", dtSub.Rows[0]["ParticularYear"]);
                        stbRF.AppendFormat(" where ResourceFolder_Id='{0}' ", dtSub.Rows[0]["ResourceFolder_Id"]);
                    }
                    #endregion
                    #region add
                    if (item["OperateType"].ToString() == "add")
                    {
                        stbRF.AppendFormat("if(select COUNT(1) from ResourceFolder where ResourceFolder_Id='{0}')=0 insert into ResourceFolder(ResourceFolder_Id,ResourceFolder_ParentId,ResourceFolder_Name,ResourceFolder_Level,Resource_Type,Resource_Class,Resource_Version,ResourceFolder_Remark,ResourceFolder_Order,ResourceFolder_Owner,CreateFUser,CreateTime,ResourceFolder_isLast,LessonPlan_Type,GradeTerm,Subject,Book_ID,ParticularYear)", dtSub.Rows[0]["ResourceFolder_Id"]);
                        stbRF.AppendFormat(" values ('{0}','{1}',N'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}');"
                                           , dtSub.Rows[0]["ResourceFolder_Id"]
                                           , dtSub.Rows[0]["ResourceFolder_ParentId"]
                                           , dtSub.Rows[0]["ResourceFolder_Name"]
                                           , dtSub.Rows[0]["ResourceFolder_Level"]
                                           , dtSub.Rows[0]["Resource_Type"]
                                           , dtSub.Rows[0]["Resource_Class"]
                                           , dtSub.Rows[0]["Resource_Version"]
                                           , dtSub.Rows[0]["ResourceFolder_Remark"]
                                           , dtSub.Rows[0]["ResourceFolder_Order"]
                                           , dtSub.Rows[0]["ResourceFolder_Owner"]
                                           , dtSub.Rows[0]["CreateFUser"]
                                           , dtSub.Rows[0]["CreateTime"]
                                           , dtSub.Rows[0]["ResourceFolder_isLast"]
                                           , dtSub.Rows[0]["LessonPlan_Type"]
                                           , dtSub.Rows[0]["GradeTerm"]
                                           , dtSub.Rows[0]["Subject"]
                                           , dtSub.Rows[0]["Book_ID"]
                                           , dtSub.Rows[0]["ParticularYear"]);
                    }
                    #endregion
                }
                if (!string.IsNullOrEmpty(stbRF.ToString()))
                {
                    DbHelperSQL_Operate.ExecuteSqlByTime(stbRF.ToString(), 7200);
                }
                DbHelperSQL.ExecuteSqlByTime(string.Format("update SyncData set SyncStatus='1' where TableName='ResourceFolder' and DataId='{0}'; ", item["DataId"]), 60);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion

            #region ③更新ResourceToResourceFolder数据(move,rename)
            model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "③更新ResourceToResourceFolder数据(move,rename)";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            foreach (DataRow item in dtRTRF_MoveRename.Rows)
            {
                stbRTRF_MoveRename = new StringBuilder();
                DataTable dtSub = new BLL_ResourceToResourceFolder().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                if (dtSub.Rows.Count == 1)
                {
                    stbRTRF_MoveRename.Append("update ResourceToResourceFolder set ");
                    stbRTRF_MoveRename.AppendFormat("ResourceFolder_Id='{0}',", dtSub.Rows[0]["ResourceFolder_Id"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Id='{0}',", dtSub.Rows[0]["Resource_Id"]);
                    stbRTRF_MoveRename.AppendFormat("File_Name=N'{0}',", dtSub.Rows[0]["File_Name"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Type='{0}',", dtSub.Rows[0]["Resource_Type"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Name=N'{0}',", dtSub.Rows[0]["Resource_Name"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Class='{0}',", dtSub.Rows[0]["Resource_Class"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Version='{0}',", dtSub.Rows[0]["Resource_Version"]);
                    stbRTRF_MoveRename.AppendFormat("File_Owner='{0}',", dtSub.Rows[0]["File_Owner"]);
                    stbRTRF_MoveRename.AppendFormat("CreateFUser='******',", dtSub.Rows[0]["CreateFUser"]);
                    stbRTRF_MoveRename.AppendFormat("CreateTime='{0}',", dtSub.Rows[0]["CreateTime"]);
                    stbRTRF_MoveRename.AppendFormat("UpdateTime='{0}',", dtSub.Rows[0]["UpdateTime"]);
                    stbRTRF_MoveRename.AppendFormat("File_Suffix='{0}',", dtSub.Rows[0]["File_Suffix"]);
                    stbRTRF_MoveRename.AppendFormat("LessonPlan_Type='{0}',", dtSub.Rows[0]["LessonPlan_Type"]);
                    stbRTRF_MoveRename.AppendFormat("GradeTerm='{0}',", dtSub.Rows[0]["GradeTerm"]);
                    stbRTRF_MoveRename.AppendFormat("Subject='{0}',", dtSub.Rows[0]["Subject"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Domain='{0}',", dtSub.Rows[0]["Resource_Domain"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_Url='{0}',", dtSub.Rows[0]["Resource_Url"]);
                    stbRTRF_MoveRename.AppendFormat("Resource_shared='{0}',", dtSub.Rows[0]["Resource_shared"]);
                    stbRTRF_MoveRename.AppendFormat("Book_ID='{0}',", dtSub.Rows[0]["Book_ID"]);
                    stbRTRF_MoveRename.AppendFormat("ParticularYear='{0}',", dtSub.Rows[0]["ParticularYear"]);
                    stbRTRF_MoveRename.AppendFormat("ResourceToResourceFolder_Order='{0}'", dtSub.Rows[0]["ResourceToResourceFolder_Order"]);
                    stbRTRF_MoveRename.AppendFormat(" where ResourceToResourceFolder_Id='{0}'; ", dtSub.Rows[0]["ResourceToResourceFolder_Id"]);
                }
                if (!string.IsNullOrEmpty(stbRTRF_MoveRename.ToString()))
                {
                    DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_MoveRename.ToString(), 7200);
                }
                DbHelperSQL.ExecuteSqlByTime(string.Format("update SyncData set SyncStatus='1' where TableName='ResourceToResourceFolder' and (OperateType='move' or OperateType='rename') and DataId='{0}'; ", item["DataId"]), 60);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion

            #region ④同步ResourceToResourceFolder数据 先删除数据 再增加数据(add,modify)
            model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "④同步ResourceToResourceFolder数据 先删除数据 再增加数据(add,modify)";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            foreach (DataRow item in dtRTRF_AddModify.Rows)
            {
                string resourceId = DbHelperSQL.GetSingle("select isnull(max(Resource_Id),'') from ResourceToResourceFolder where ResourceToResourceFolder_Id='" + item["DataId"] + "'").ToString();
                if (!string.IsNullOrEmpty(resourceId.Trim()))
                {
                    //删除数据
                    stbRTRF_AddModify = new StringBuilder();
                    stbRTRF_AddModify.AppendFormat(@"delete from TestQuestions_Option where TestQuestions_Id in(select TestQuestions_Id from TestQuestions where ResourceToResourceFolder_Id='{0}');
delete from TestQuestions_Score where ResourceToResourceFolder_Id='{0}';
delete from TestQuestions where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder_Property where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder_img where ResourceToResourceFolder_Id='{0}';
delete from ResourceToResourceFolder where ResourceToResourceFolder_Id='{0}';
delete from [Resource] where Resource_Id='{1}';"
                                                   , item["DataId"]
                                                   , resourceId);
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    //新增数据
                    #region Resource
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtRes = new BLL_Resource().GetList("Resource_Id='" + resourceId + "'").Tables[0];
                    stbRTRF_AddModify.Append("insert into Resource(Resource_Id,Resource_MD5,Resource_DataStrem,Resource_ContentHtml,CreateTime,Resource_ContentLength)");
                    stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}');"
                                                   , dtRes.Rows[0]["Resource_Id"]
                                                   , dtRes.Rows[0]["Resource_MD5"]
                                                   , dtRes.Rows[0]["Resource_DataStrem"]
                                                   , dtRes.Rows[0]["Resource_ContentHtml"]
                                                   , dtRes.Rows[0]["CreateTime"]
                                                   , dtRes.Rows[0]["Resource_ContentLength"]);
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                    #region ResourceToResourceFolder
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtRTRF = new BLL_ResourceToResourceFolder().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                    stbRTRF_AddModify.Append("insert into ResourceToResourceFolder(ResourceToResourceFolder_Id,ResourceFolder_Id,Resource_Id,File_Name,Resource_Type,Resource_Name,Resource_Class,Resource_Version,File_Owner,CreateFUser,CreateTime,UpdateTime,File_Suffix,LessonPlan_Type,GradeTerm,Subject,Resource_Domain,Resource_Url,Resource_shared,Book_ID,ParticularYear,ResourceToResourceFolder_Order)");
                    stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}',N'{3}','{4}',N'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}');"
                                                   , dtRTRF.Rows[0]["ResourceToResourceFolder_Id"]
                                                   , dtRTRF.Rows[0]["ResourceFolder_Id"]
                                                   , dtRTRF.Rows[0]["Resource_Id"]
                                                   , dtRTRF.Rows[0]["File_Name"]
                                                   , dtRTRF.Rows[0]["Resource_Type"]
                                                   , dtRTRF.Rows[0]["Resource_Name"]
                                                   , dtRTRF.Rows[0]["Resource_Class"]
                                                   , dtRTRF.Rows[0]["Resource_Version"]
                                                   , dtRTRF.Rows[0]["File_Owner"]
                                                   , dtRTRF.Rows[0]["CreateFUser"]
                                                   , dtRTRF.Rows[0]["CreateTime"]
                                                   , dtRTRF.Rows[0]["UpdateTime"]
                                                   , dtRTRF.Rows[0]["File_Suffix"]
                                                   , dtRTRF.Rows[0]["LessonPlan_Type"]
                                                   , dtRTRF.Rows[0]["GradeTerm"]
                                                   , dtRTRF.Rows[0]["Subject"]
                                                   , dtRTRF.Rows[0]["Resource_Domain"]
                                                   , dtRTRF.Rows[0]["Resource_Url"]
                                                   , dtRTRF.Rows[0]["Resource_shared"]
                                                   , dtRTRF.Rows[0]["Book_ID"]
                                                   , dtRTRF.Rows[0]["ParticularYear"]
                                                   , dtRTRF.Rows[0]["ResourceToResourceFolder_Order"]);
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                    #region ResourceToResourceFolder_img
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtRTRF_Img = new BLL_ResourceToResourceFolder_img().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                    foreach (DataRow item_Img in dtRTRF_Img.Rows)
                    {
                        stbRTRF_AddModify.Append("insert into ResourceToResourceFolder_img(ResourceToResourceFolder_img_id,ResourceToResourceFolder_id,ResourceToResourceFolderImg_Url,ResourceToResourceFolderImg_Order,CreateTime)");
                        stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}');"
                                                       , item_Img["ResourceToResourceFolder_img_id"]
                                                       , item_Img["ResourceToResourceFolder_id"]
                                                       , item_Img["ResourceToResourceFolderImg_Url"]
                                                       , item_Img["ResourceToResourceFolderImg_Order"]
                                                       , item_Img["CreateTime"]);
                    }
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                    #region ResourceToResourceFolder_Property
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtRTRF_Property = new BLL_ResourceToResourceFolder_Property().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                    foreach (DataRow item_Property in dtRTRF_Property.Rows)
                    {
                        stbRTRF_AddModify.Append("insert into ResourceToResourceFolder_Property(ResourceToResourceFolder_Id,BooksCode,BooksUnitCode,GuidDoc,TestPaperName,CreateTime,paperHeaderDoc,paperHeaderHtml)");
                        stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"
                                                       , item_Property["ResourceToResourceFolder_Id"]
                                                       , item_Property["BooksCode"]
                                                       , item_Property["BooksUnitCode"]
                                                       , item_Property["GuidDoc"]
                                                       , item_Property["TestPaperName"]
                                                       , item_Property["CreateTime"]
                                                       , item_Property["paperHeaderDoc"]
                                                       , item_Property["paperHeaderHtml"]);
                    }
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                    #region TestQuestions,TestQuestions_Option
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtTQ = new BLL_TestQuestions().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                    foreach (DataRow item_TQ in dtTQ.Rows)
                    {
                        stbRTRF_AddModify.Append("insert into TestQuestions(TestQuestions_Id,ResourceToResourceFolder_Id,TestQuestions_Num,TestQuestions_Type,TestQuestions_SumScore,TestQuestions_Content,TestQuestions_Answer,CreateTime,topicNumber,Parent_Id,[type])");
                        stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');"
                                                       , item_TQ["TestQuestions_Id"]
                                                       , item_TQ["ResourceToResourceFolder_Id"]
                                                       , item_TQ["TestQuestions_Num"]
                                                       , item_TQ["TestQuestions_Type"]
                                                       , item_TQ["TestQuestions_SumScore"]
                                                       , item_TQ["TestQuestions_Content"]
                                                       , item_TQ["TestQuestions_Answer"]
                                                       , item_TQ["CreateTime"]
                                                       , item_TQ["topicNumber"].ToString().Filter()
                                                       , item_TQ["Parent_Id"]
                                                       , item_TQ["type"]);
                        #region TestQuestions_Option
                        DataTable dtTQ_Option = new BLL_TestQuestions_Option().GetList("TestQuestions_Id='" + item_TQ["TestQuestions_Id"] + "'").Tables[0];
                        foreach (DataRow item_TQ_Option in dtTQ_Option.Rows)
                        {
                            stbRTRF_AddModify.Append("insert into TestQuestions_Option(TestQuestions_Option_Id,TestQuestions_Id,TestQuestions_OptionParent_OrderNum,TestQuestions_Option_Content,TestQuestions_Option_OrderNum,CreateTime,TestQuestions_Score_ID)");
                            stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}');"
                                                           , item_TQ_Option["TestQuestions_Option_Id"]
                                                           , item_TQ_Option["TestQuestions_Id"]
                                                           , item_TQ_Option["TestQuestions_OptionParent_OrderNum"]
                                                           , item_TQ_Option["TestQuestions_Option_Content"].ToString().Filter()
                                                           , item_TQ_Option["TestQuestions_Option_OrderNum"]
                                                           , item_TQ_Option["CreateTime"]
                                                           , item_TQ_Option["TestQuestions_Score_ID"]);
                        }
                        #endregion
                    }
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                    #region TestQuestions_Score
                    stbRTRF_AddModify = new StringBuilder();
                    DataTable dtTQ_Score = new BLL_TestQuestions_Score().GetList("ResourceToResourceFolder_Id='" + item["DataId"] + "'").Tables[0];
                    foreach (DataRow item_TQ_Score in dtTQ_Score.Rows)
                    {
                        stbRTRF_AddModify.Append("insert into TestQuestions_Score(TestQuestions_Score_ID,ResourceToResourceFolder_Id,TestQuestions_Id,TestQuestions_Num,TestQuestions_OrderNum,TestQuestions_Score,AnalyzeHyperlink,AnalyzeHyperlinkData,AnalyzeHyperlinkHtml,AnalyzeText,ComplexityHyperlink,ComplexityText,ContentHyperlink,ContentText,DocBase64,DocHtml,ScoreHyperlink,ScoreText,TargetHyperlink,TrainHyperlinkData,TrainHyperlinkHtml,TargetText,TestCorrect,TestType,TrainHyperlink,TrainText,TypeHyperlink,TypeText,CreateTime,AreaHyperlink,AreaText,kaofaText,testIndex)");
                        stbRTRF_AddModify.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}');"
                                                       , item_TQ_Score["TestQuestions_Score_ID"]
                                                       , item_TQ_Score["ResourceToResourceFolder_Id"]
                                                       , item_TQ_Score["TestQuestions_Id"]
                                                       , item_TQ_Score["TestQuestions_Num"]
                                                       , item_TQ_Score["TestQuestions_OrderNum"]
                                                       , item_TQ_Score["TestQuestions_Score"]
                                                       , item_TQ_Score["AnalyzeHyperlink"]
                                                       , item_TQ_Score["AnalyzeHyperlinkData"]
                                                       , item_TQ_Score["AnalyzeHyperlinkHtml"]
                                                       , item_TQ_Score["AnalyzeText"]
                                                       , item_TQ_Score["ComplexityHyperlink"]
                                                       , item_TQ_Score["ComplexityText"]
                                                       , item_TQ_Score["ContentHyperlink"]
                                                       , item_TQ_Score["ContentText"]
                                                       , item_TQ_Score["DocBase64"]
                                                       , item_TQ_Score["DocHtml"]
                                                       , item_TQ_Score["ScoreHyperlink"]
                                                       , item_TQ_Score["ScoreText"]
                                                       , item_TQ_Score["TargetHyperlink"]
                                                       , item_TQ_Score["TrainHyperlinkData"]
                                                       , item_TQ_Score["TrainHyperlinkHtml"]
                                                       , item_TQ_Score["TargetText"]
                                                       , item_TQ_Score["TestCorrect"]
                                                       , item_TQ_Score["TestType"]
                                                       , item_TQ_Score["TrainHyperlink"]
                                                       , item_TQ_Score["TrainText"]
                                                       , item_TQ_Score["TypeHyperlink"]
                                                       , item_TQ_Score["TypeText"]
                                                       , item_TQ_Score["CreateTime"]
                                                       , item_TQ_Score["AreaHyperlink"]
                                                       , item_TQ_Score["AreaText"]
                                                       , item_TQ_Score["kaofaText"]
                                                       , item_TQ_Score["testIndex"]);
                    }
                    AddLogInfo(string.Format("{0}--结束--", stbRTRF_AddModify.ToString()), true);
                    if (!string.IsNullOrEmpty(stbRTRF_AddModify.ToString()))
                    {
                        DbHelperSQL_Operate.ExecuteSqlByTime(stbRTRF_AddModify.ToString(), 7200);
                    }

                    #endregion
                }

                DbHelperSQL.ExecuteSqlByTime(string.Format("update SyncData set SyncStatus='1' where TableName='ResourceToResourceFolder' and (OperateType='add' or OperateType='modify') and DataId='{0}'; ", item["DataId"]), 60);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion

            #region ⑤同步BookAudit表数据
            model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "⑤同步BookAudit表数据";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            StringBuilder stbBookAudit = new StringBuilder();
            DataTable     dtBookAudit  = new BLL_BookAudit().GetList(" ResourceFolder_Id in(select DataId from SyncData where TableName='BookAudit' and (SyncStatus='0' or SyncStatus='2') ) ").Tables[0];
            foreach (DataRow item in dtBookAudit.Rows)
            {
                stbBookAudit.AppendFormat(@"if(select COUNT(1) from BookAudit where ResourceFolder_Id='{0}')=0 
                begin 
                insert into BookAudit(ResourceFolder_Id,Book_Name,AuditState,AuditRemark,CreateUser,CreateTime) values ('{0}',N'{1}','{2}','{3}','{4}','{5}');"
                                          , item["ResourceFolder_Id"]
                                          , item["Book_Name"]
                                          , item["AuditState"]
                                          , item["AuditRemark"]
                                          , item["CreateUser"]
                                          , item["CreateTime"]);
                stbBookAudit.Append(" end ");
                stbBookAudit.Append(" else ");
                stbBookAudit.Append(" begin ");
                stbBookAudit.AppendFormat(@"if(select COUNT(1) from BookAudit where ResourceFolder_Id='{0}' and (AuditState='{1}' or CreateTime='{2}') )=0 
                begin 
                    update BookAudit set AuditState='{1}',CreateTime='{2}' where ResourceFolder_Id='{0}';
                end ", item["ResourceFolder_Id"], item["AuditState"], item["CreateTime"]);
                stbBookAudit.Append(" end ");

                DbHelperSQL.ExecuteSqlByTime(string.Format("update SyncData set SyncStatus='1' where TableName='BookAudit' and OperateType='bookaudit' and DataId='{0}'; ", item["ResourceFolder_Id"]), 60);
            }
            AddLogInfo(string.Format("{0}--结束--", stbBookAudit.ToString()), true);
            if (!string.IsNullOrEmpty(stbBookAudit.ToString()))
            {
                DbHelperSQL_Operate.ExecuteSqlByTime(stbBookAudit.ToString(), 7200);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion

            #region ⑥同步SyncData表数据
            model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
            model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
            model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
            model_FileSyncExecRecordDetail.Detail_Remark    = "⑥同步SyncData表数据";
            model_FileSyncExecRecordDetail.Detail_Status    = "0";
            model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
            bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

            StringBuilder stbSyncData = new StringBuilder();
            DataTable     dtSyncData  = new BLL_SyncData().GetList("").Tables[0];
            foreach (DataRow item in dtSyncData.Rows)
            {
                stbSyncData.AppendFormat("if(select COUNT(1) from SyncData where SyncDataId='{0}')=0 insert into SyncData(SyncDataId,TableName,DataId,OperateType,CreateTime,SyncStatus)", item["SyncDataId"]);
                stbSyncData.AppendFormat(" values ('{0}','{1}','{2}','{3}','{4}','{5}');"
                                         , item["SyncDataId"]
                                         , item["TableName"]
                                         , item["DataId"]
                                         , item["OperateType"]
                                         , item["CreateTime"]
                                         , item["SyncStatus"]);
            }
            AddLogInfo(string.Format("{0}--结束--", stbSyncData.ToString()), true);
            if (!string.IsNullOrEmpty(stbSyncData.ToString()))
            {
                DbHelperSQL_Operate.ExecuteSqlByTime(stbSyncData.ToString(), 7200);
            }

            model_FileSyncExecRecordDetail.Detail_Status  = "1";
            model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            #endregion
        }
Пример #2
0
        /// <summary>
        /// 下载
        /// </summary>
        /// <param name="dvFile"></param>
        /// <param name="strPathType"></param>
        /// <param name="strFileNameEx"></param>
        /// <param name="strProductPublicUrl"></param>
        /// <param name="strFileSyncExecRecord_id"></param>
        /// <param name="strRemark"></param>
        /// <param name="isCoverDownload">true: 覆盖下载</param>
        private void DownLoadFile(DataRow[] dvFile, string strPathType, string strFileNameEx, string strProductPublicUrl, string strFileSyncExecRecord_id, string strRemark, bool isCoverDownload)
        {
            bool isDownload = false;//是否要下载文件

            foreach (var item in dvFile)
            {
                #region 组织文件源的URL与本地存储的路径
                string strPathCommon = string.Empty;
                string strFileName   = string.Empty;//文件名(没后缀)
                strFileName   = item["FileName"].ToString();
                strPathCommon = string.Format("{0}/{1}/{2}/{3}/{4}/"
                                              , strPathType
                                              , item["ParticularYear"].ToString()
                                              , item["GradeTerm"].ToString()
                                              , item["Resource_Version"].ToString()
                                              , item["Subject"].ToString());
                string strFilePath             = string.Empty;
                string strFileNameFullDocument = strFileName + "." + strFileNameEx;
                string remotingFileUrl         = string.Empty;
                string localFilePath           = string.Empty;
                remotingFileUrl = strProductPublicUrl + "Upload/Resource/" + strPathCommon;
                localFilePath   = strLocalPhsicalPath + strPathCommon;
                string remotingViewFileUrl = string.Empty;
                string localViewFilePath   = string.Empty;
                #endregion
                isDownload = false;
                if (!File.Exists(localFilePath + strFileNameFullDocument))//文件不存在
                {
                    isDownload = true;
                }
                else
                {
                    if (isCoverDownload)//是覆盖下载
                    {
                        isDownload = true;
                    }
                }
                if (isDownload)
                {
                    Rc.Model.Resources.Model_FileSyncExecRecordDetail model_FileSyncExecRecordDetail = new Rc.Model.Resources.Model_FileSyncExecRecordDetail();
                    Rc.BLL.Resources.BLL_FileSyncExecRecordDetail     bll_FileSyncExecRecordDetail   = new Rc.BLL.Resources.BLL_FileSyncExecRecordDetail();
                    model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id = Guid.NewGuid().ToString();
                    model_FileSyncExecRecordDetail.FileSyncExecRecord_id       = strFileSyncExecRecord_id;
                    model_FileSyncExecRecordDetail.Book_Id = item["Book_Id"].ToString();
                    model_FileSyncExecRecordDetail.ResourceToResourceFolder_Id = item["ResourceToResourceFolder_Id"].ToString();
                    model_FileSyncExecRecordDetail.Resource_Type    = item["Resource_Type"].ToString();
                    model_FileSyncExecRecordDetail.FileUrl          = strPathCommon + strFileNameFullDocument;
                    model_FileSyncExecRecordDetail.Detail_Remark    = "开始同步:" + strRemark;
                    model_FileSyncExecRecordDetail.Detail_Status    = "0";
                    model_FileSyncExecRecordDetail.Detail_TimeStart = DateTime.Now;
                    bll_FileSyncExecRecordDetail.Add(model_FileSyncExecRecordDetail);

                    try
                    {
                        string downloadFileMsg = pfunction.DownLoadFileByWebClient(remotingFileUrl, localFilePath, strFileNameFullDocument);

                        model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
                        if (downloadFileMsg != "true")
                        {
                            model_FileSyncExecRecordDetail.Detail_Status = "2";
                            if (downloadFileMsg.Contains("404"))
                            {
                                model_FileSyncExecRecordDetail.Detail_Status = "1";//如果是远程服务器未找到文件,设置为状态为成功
                                // 17-08-21如果是远程服务器未找到文件,删除同步记录
                                bll_FileSyncExecRecordDetail.Delete(model_FileSyncExecRecordDetail.FileSyncExecRecordDetail_id);
                            }
                            else
                            {
                                model_FileSyncExecRecordDetail.Detail_Remark = strRemark + ":" + downloadFileMsg;
                                bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
                            }
                        }
                        else
                        {
                            model_FileSyncExecRecordDetail.Detail_Remark = "同步成功:" + strRemark;
                            if (File.Exists(localFilePath + strFileNameFullDocument))
                            {
                                model_FileSyncExecRecordDetail.Detail_Status = "1";
                            }
                            else //文件不存在,更新同步状态为失败 17-09-11TS
                            {
                                model_FileSyncExecRecordDetail.Detail_Status = "2";
                            }
                            bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
                        }
                    }
                    catch (Exception ex)
                    {
                        //同步异常 删除已创建文件 17-09-11TS
                        if (File.Exists(localFilePath + strFileNameFullDocument))
                        {
                            File.Delete(localFilePath + strFileNameFullDocument);
                        }

                        model_FileSyncExecRecordDetail.Detail_Remark = "同步失败,异常:" + ex.Message.ToString();
                        model_FileSyncExecRecordDetail.Detail_Status = "2";
                        bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);

                        throw;
                    }
                }
            }
        }
        public void SubmitStudentAnswer()
        {
            string StrSql = string.Empty;

            if (string.IsNullOrEmpty(SchoolId))
            {
                StrSql = @"select hw.HomeWork_Id,hw.CreateTime,shw.Student_HomeWork_Id,shw.HomeWork_Id,shw.Student_Id,shw.CreateTime,shwSubmit.Student_HomeWork_Status,shwSubmit.OpenTime,shwSubmit.StudentIP,shwSubmit.Student_Answer_Time 
from Student_HomeWork shw
inner join Student_HomeWork_Submit shwSubmit on shwSubmit.Student_HomeWork_Id=shw.Student_HomeWork_Id and shwSubmit.Student_HomeWork_Status='2'
inner join HomeWork hw on hw.HomeWork_Id=shw.HomeWork_Id
order by hw.CreateTime";
            }
            else
            {
                StrSql = string.Format(@"select hw.HomeWork_Id,hw.CreateTime,shw.Student_HomeWork_Id,shw.HomeWork_Id,shw.Student_Id,shw.CreateTime,shwSubmit.Student_HomeWork_Status,shwSubmit.OpenTime,shwSubmit.StudentIP,shwSubmit.Student_Answer_Time 
from Student_HomeWork shw
inner join Student_HomeWork_Submit shwSubmit on shwSubmit.Student_HomeWork_Id=shw.Student_HomeWork_Id and shwSubmit.Student_HomeWork_Status='2'
inner join HomeWork hw on hw.HomeWork_Id=shw.HomeWork_Id
where shw.Student_Id in(select UserId from VW_UserOnClassGradeSchool vw where vw.SchoolId='{0}')
order by hw.CreateTime", SchoolId);
            }

            DataTable dtShw = Rc.Common.DBUtility.DbHelperSQL.Query(StrSql).Tables[0];

            if (dtShw.Rows.Count == 0)
            {
                #region 记录执行结束信息并保存数据
                model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
                model_FileSyncExecRecordDetail.Detail_Status  = "1";
                model_FileSyncExecRecordDetail.Detail_Remark  = "执行完成.没有待执行数据";
                bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
                #endregion
                return;
            }

            try
            {
                #region 自动提交学生答案
                int    sucNum  = 0;
                int    failNum = 0;
                string resInfo = string.Empty;
                foreach (DataRow itemShw in dtShw.Rows)
                {
                    try
                    {
                        #region 提交单份学生作业
                        string         savePath   = string.Empty;
                        Model_HomeWork modelHW    = new BLL_HomeWork().GetModel(itemShw["HomeWork_Id"].ToString());
                        string         homeWorkId = modelHW.HomeWork_Id;
                        string         rtrfId     = modelHW.ResourceToResourceFolder_Id;
                        string         resourceId = itemShw["Student_HomeWork_Id"].ToString(); //学生作业ID
                        string         userId     = itemShw["Student_Id"].ToString();          //学生ID
                        Model_ResourceToResourceFolder modelRTRFolder = new BLL_ResourceToResourceFolder().GetModel(rtrfId);
                        string filePath = pfunction.ConvertToLongDateTime(itemShw["CreateTime"].ToString(), "yyyy-MM-dd") + "\\" + itemShw["HomeWork_Id"] + "\\" + itemShw["Student_HomeWork_Id"].ToString() + ".txt";

                        if (File.Exists(Server.MapPath(uploadAnswerPath) + filePath))
                        {
                            resInfo = File.ReadAllText(Server.MapPath(uploadAnswerPath) + filePath);
                            Rc.Interface.testPaperAnswerSubmitModel resModel = Newtonsoft.Json.JsonConvert.DeserializeObject <Rc.Interface.testPaperAnswerSubmitModel>(resInfo);

                            Rc.Common.SystemLog.SystemLog.AddLogFromBS("", resourceId, string.Format("开始自动提交学生作业|操作人{0}|学生作业Id{1}|方法{2}", userId, resourceId, "testpaperanswersubmit"));
                            #region 学生作业表
                            Model_Student_HomeWork_Submit modelSHWSubmit = new Model_Student_HomeWork_Submit();
                            modelSHWSubmit = new BLL_Student_HomeWork_Submit().GetModel(itemShw["Student_HomeWork_Id"].ToString());
                            modelSHWSubmit.Student_HomeWork_Status = 1;
                            #endregion
                            #region 学生作业答案表
                            if (modelRTRFolder.Resource_Class == Rc.Common.Config.Resource_ClassConst.云资源)
                            {
                                savePath = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\"
                                                         , pfunction.ToShortDate(modelHW.CreateTime.ToString())//作业布置时间
                                                         , modelRTRFolder.ParticularYear, modelRTRFolder.GradeTerm
                                                         , modelRTRFolder.Resource_Version, modelRTRFolder.Subject);
                            }
                            if (modelRTRFolder.Resource_Class == Rc.Common.Config.Resource_ClassConst.自有资源)
                            {
                                savePath = string.Format("{0}\\"
                                                         , pfunction.ToShortDate(modelHW.CreateTime.ToString()));//作业布置时间);
                            }

                            //获取这个试卷的所有试题分值
                            string strSqlScore = string.Empty;
                            strSqlScore = string.Format(@"select [TestQuestions_Score_ID],TestQuestions_ID ,TestQuestions_Score,TestQuestions_OrderNum,TestType
 FROM TestQuestions_Score where ResourceToResourceFolder_Id='{0}'  ", rtrfId);
                            DataTable dtTQ_Score = Rc.Common.DBUtility.DbHelperSQL.Query(strSqlScore).Tables[0];

                            List <Model_Student_HomeWorkAnswer>         listSHWA = new List <Model_Student_HomeWorkAnswer>();
                            List <Rc.Interface.TestPaperAnswerModel>    listTestPaperAnswerModel = resModel.answerJson; //普通题型
                            List <Rc.Interface.TestPaperAnswerModelBig> TestPaperAnswerModelBig  = resModel.listBig;    //综合题型
                            #region 普通题型 list
                            int num = 0;
                            if (listTestPaperAnswerModel != null)
                            {
                                foreach (var item in listTestPaperAnswerModel)
                                {
                                    if (item != null && item.list != null)
                                    {
                                        num++;
                                        int detailNum = 0;
                                        foreach (var itemSub in item.list)
                                        {
                                            if (itemSub != null)
                                            {
                                                detailNum++;
                                                DataRow[] drTQ_Score = dtTQ_Score.Select(string.Format(" TestQuestions_ID='{0}'  and TestQuestions_OrderNum={1} ", item.Testid, detailNum));
                                                if (drTQ_Score != null && drTQ_Score.Length > 0)
                                                {
                                                    #region 学生答题表
                                                    Model_Student_HomeWorkAnswer modelSHWA = new Model_Student_HomeWorkAnswer();
                                                    modelSHWA.TestQuestions_Id = item.Testid;
                                                    string student_HomeWorkAnswer_Id = Guid.NewGuid().ToString();
                                                    modelSHWA.TestQuestions_Score_ID    = drTQ_Score[0]["TestQuestions_Score_ID"].ToString();
                                                    modelSHWA.Student_HomeWorkAnswer_Id = student_HomeWorkAnswer_Id;
                                                    modelSHWA.Student_HomeWork_Id       = resourceId;
                                                    modelSHWA.Student_Id                    = userId;
                                                    modelSHWA.HomeWork_Id                   = homeWorkId;
                                                    modelSHWA.TestQuestions_Num             = num;
                                                    modelSHWA.TestQuestions_Detail_OrderNum = detailNum;

                                                    if (itemSub.isHTML == "F")//是否以HTML提交 F: 文本提交; T: HTML提交(选择题,文本提交, 其余均为HTML提交)
                                                    {
                                                        modelSHWA.Student_Answer = itemSub.answerChooses;
                                                    }
                                                    else if (itemSub.isHTML == "T")//HTML提交
                                                    {
                                                        Model_TestQuestions modelTQ = new BLL_TestQuestions().GetModel(item.Testid);
                                                        if (modelTQ.TestQuestions_Type == "truefalse")//判断题答案保存到数据库
                                                        {
                                                            modelSHWA.Student_Answer = itemSub.answerHTML;
                                                        }
                                                        else
                                                        {
                                                            #region 学生答案 保存文件
                                                            if (!String.IsNullOrEmpty(itemSub.answerHTML))
                                                            {
                                                                pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerHTML, true);
                                                            }
                                                            if (!String.IsNullOrEmpty(itemSub.answerImageBase64))
                                                            {
                                                                pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.i.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerImageBase64, true);
                                                            }
                                                            if (!String.IsNullOrEmpty(itemSub.answerDocBase64))
                                                            {
                                                                pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.d.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerDocBase64, true);
                                                            }
                                                            #endregion
                                                        }
                                                    }
                                                    else //默认存HTML
                                                    {
                                                        #region 学生答案 保存文件
                                                        if (!String.IsNullOrEmpty(itemSub.answerHTML))
                                                        {
                                                            pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerHTML, true);
                                                        }
                                                        if (!String.IsNullOrEmpty(itemSub.answerImageBase64))
                                                        {
                                                            pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.i.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerImageBase64, true);
                                                        }
                                                        if (!String.IsNullOrEmpty(itemSub.answerDocBase64))
                                                        {
                                                            pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.d.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerDocBase64, true);
                                                        }
                                                        #endregion
                                                    }
                                                    //写入客户端的判卷
                                                    modelSHWA.Student_Score = 0;//学生得分默认值(NULL的话统计的时候会出现数据不正确)
                                                    if (itemSub.isRight == "true")
                                                    {
                                                        modelSHWA.Student_Answer_Status = "right";
                                                        decimal temp_decimal = 0;
                                                        decimal.TryParse(drTQ_Score[0]["TestQuestions_Score"].ToString(), out temp_decimal);
                                                        modelSHWA.Student_Score = temp_decimal;
                                                        modelSHWA.isRead        = 1;
                                                    }
                                                    else if (itemSub.isRight == "false")
                                                    {
                                                        modelSHWA.Student_Answer_Status = "wrong";
                                                        modelSHWA.isRead = 1;
                                                    }
                                                    else
                                                    {
                                                        modelSHWA.Student_Answer_Status = "unknown";
                                                        modelSHWA.isRead = 0;
                                                    }
                                                    modelSHWA.CreateTime = DateTime.Now;
                                                    string strTestQuestions_NumStr = item.topicNumber.Filter();
                                                    if (!string.IsNullOrEmpty(strTestQuestions_NumStr))
                                                    {
                                                        if (strTestQuestions_NumStr.Length >= 10)
                                                        {
                                                            strTestQuestions_NumStr = strTestQuestions_NumStr.Substring(0, 10);
                                                        }
                                                    }
                                                    modelSHWA.TestQuestions_NumStr = strTestQuestions_NumStr;//item.topicNumber
                                                    listSHWA.Add(modelSHWA);
                                                    #endregion
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            #region 综合题型 listBig
                            if (TestPaperAnswerModelBig != null)
                            {
                                num = 0;
                                foreach (var itemBig in TestPaperAnswerModelBig)
                                {
                                    if (itemBig != null && itemBig.list != null)
                                    {
                                        foreach (var item in itemBig.list)
                                        {
                                            if (item != null && item.list != null)
                                            {
                                                num++;
                                                int detailNum = 0;
                                                foreach (var itemSub in item.list)
                                                {
                                                    if (itemSub != null)
                                                    {
                                                        detailNum++;
                                                        DataRow[] drTQ_Score = dtTQ_Score.Select(string.Format(" TestQuestions_ID='{0}'  and TestQuestions_OrderNum={1} ", item.Testid, detailNum));
                                                        if (drTQ_Score != null && drTQ_Score.Length > 0)
                                                        {
                                                            #region 学生答题表
                                                            Model_Student_HomeWorkAnswer modelSHWA = new Model_Student_HomeWorkAnswer();
                                                            modelSHWA.TestQuestions_Id = item.Testid;
                                                            string student_HomeWorkAnswer_Id = Guid.NewGuid().ToString();
                                                            modelSHWA.TestQuestions_Score_ID    = drTQ_Score[0]["TestQuestions_Score_ID"].ToString();
                                                            modelSHWA.Student_HomeWorkAnswer_Id = student_HomeWorkAnswer_Id;
                                                            modelSHWA.Student_HomeWork_Id       = resourceId;
                                                            modelSHWA.Student_Id                    = userId;
                                                            modelSHWA.HomeWork_Id                   = homeWorkId;
                                                            modelSHWA.TestQuestions_Num             = num;
                                                            modelSHWA.TestQuestions_Detail_OrderNum = detailNum;

                                                            //if (modelRTRFolder.Resource_Class == Rc.Common.Config.Resource_ClassConst.云资源)
                                                            //{
                                                            //    savePath = string.Format("{0}\\{1}\\{2}\\{3}\\{4}\\"
                                                            //       , pfunction.ToShortDate(modelHW.CreateTime.ToString())//作业布置时间
                                                            //       , modelRTRFolder.ParticularYear, modelRTRFolder.GradeTerm
                                                            //       , modelRTRFolder.Resource_Version, modelRTRFolder.Subject);
                                                            //}
                                                            //if (modelRTRFolder.Resource_Class == Rc.Common.Config.Resource_ClassConst.自有资源)
                                                            //{
                                                            //    savePath = string.Format("{0}\\"
                                                            //        , pfunction.ToShortDate(modelHW.CreateTime.ToString()));//作业布置时间);
                                                            //}
                                                            if (itemSub.isHTML == "F")//是否以HTML提交 F: 文本提交; T: HTML提交(选择题,文本提交, 其余均为HTML提交)
                                                            {
                                                                modelSHWA.Student_Answer = itemSub.answerChooses;
                                                            }
                                                            else if (itemSub.isHTML == "T")//HTML提交
                                                            {
                                                                Model_TestQuestions modelTQ = new BLL_TestQuestions().GetModel(item.Testid);
                                                                if (modelTQ.TestQuestions_Type == "truefalse")//判断题答案保存到数据库
                                                                {
                                                                    modelSHWA.Student_Answer = itemSub.answerHTML;
                                                                }
                                                                else
                                                                {
                                                                    #region 学生答案 保存文件
                                                                    if (!String.IsNullOrEmpty(itemSub.answerHTML))
                                                                    {
                                                                        pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerHTML, true);
                                                                    }
                                                                    if (!String.IsNullOrEmpty(itemSub.answerImageBase64))
                                                                    {
                                                                        pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.i.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerImageBase64, true);
                                                                    }
                                                                    if (!String.IsNullOrEmpty(itemSub.answerDocBase64))
                                                                    {
                                                                        pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.d.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerDocBase64, true);
                                                                    }
                                                                    #endregion
                                                                }
                                                            }
                                                            else //默认存HTML
                                                            {
                                                                #region 学生答案 保存文件
                                                                if (!String.IsNullOrEmpty(itemSub.answerHTML))
                                                                {
                                                                    pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerHTML, true);
                                                                }
                                                                if (!String.IsNullOrEmpty(itemSub.answerImageBase64))
                                                                {
                                                                    pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.i.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerImageBase64, true);
                                                                }
                                                                if (!String.IsNullOrEmpty(itemSub.answerDocBase64))
                                                                {
                                                                    pfunction.WriteToFile(string.Format("{0}studentAnswer\\{1}{2}.d.txt", uploadPath, savePath, student_HomeWorkAnswer_Id), itemSub.answerDocBase64, true);
                                                                }
                                                                #endregion
                                                            }
                                                            //写入客户端的判卷
                                                            modelSHWA.Student_Score = 0;//学生得分默认值(NULL的话统计的时候会出现数据不正确)
                                                            if (itemSub.isRight == "true")
                                                            {
                                                                modelSHWA.Student_Answer_Status = "right";
                                                                decimal temp_decimal = 0;
                                                                decimal.TryParse(drTQ_Score[0]["TestQuestions_Score"].ToString(), out temp_decimal);
                                                                modelSHWA.Student_Score = temp_decimal;
                                                                modelSHWA.isRead        = 1;
                                                            }
                                                            else if (itemSub.isRight == "false")
                                                            {
                                                                modelSHWA.Student_Answer_Status = "wrong";
                                                                modelSHWA.isRead = 1;
                                                            }
                                                            else
                                                            {
                                                                modelSHWA.Student_Answer_Status = "unknown";
                                                                modelSHWA.isRead = 0;
                                                            }
                                                            modelSHWA.CreateTime = DateTime.Now;
                                                            string strTestQuestions_NumStr = item.topicNumber.Filter();
                                                            if (!string.IsNullOrEmpty(strTestQuestions_NumStr))
                                                            {
                                                                if (strTestQuestions_NumStr.Length >= 10)
                                                                {
                                                                    strTestQuestions_NumStr = strTestQuestions_NumStr.Substring(0, 10);
                                                                }
                                                            }
                                                            modelSHWA.TestQuestions_NumStr = strTestQuestions_NumStr;//item.topicNumber
                                                            listSHWA.Add(modelSHWA);
                                                            #endregion
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            #endregion

                            if (new BLL_Student_HomeWorkAnswer().StudentAnswerSubmit(modelSHWSubmit, listSHWA) > 0)
                            {
                                sucNum++;
                                #region 保存学生答题JSON串
                                //重置answerHTML为空,保存分值
                                List <Model_Student_HomeWorkAnswer> listStuScore = new BLL_Student_HomeWorkAnswer().GetModelList("Student_HomeWork_Id='" + resourceId + "'");
                                #region 普通题型 list
                                if (resModel.answerJson != null)
                                {
                                    foreach (var item in resModel.answerJson)
                                    {
                                        if (item != null && item.list != null)
                                        {
                                            int sNum = 0;
                                            foreach (var itemTQ_S in item.list)
                                            {
                                                if (itemTQ_S != null)
                                                {
                                                    itemTQ_S.answerHTML = "";
                                                    sNum++;
                                                    List <Model_Student_HomeWorkAnswer> listStuScoreSub = listStuScore.Where(o => o.TestQuestions_Id == item.Testid && o.TestQuestions_Detail_OrderNum == sNum).ToList();
                                                    if (listStuScoreSub.Count > 0)
                                                    {
                                                        itemTQ_S.studentScore = listStuScoreSub[0].Student_Score.ToString();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                #endregion
                                #region 综合题型 listBig
                                if (resModel.listBig != null)
                                {
                                    foreach (var item in resModel.listBig)
                                    {
                                        if (item != null && item.list != null)
                                        {
                                            foreach (var itemSub in item.list)
                                            {
                                                if (itemSub != null && itemSub.list != null)
                                                {
                                                    int sNum = 0;
                                                    foreach (var itemTQ_S in itemSub.list)
                                                    {
                                                        if (itemTQ_S != null)
                                                        {
                                                            itemTQ_S.answerHTML = "";
                                                            sNum++;
                                                            List <Model_Student_HomeWorkAnswer> listStuScoreSub = listStuScore.Where(o => o.TestQuestions_Id == itemSub.Testid && o.TestQuestions_Detail_OrderNum == sNum).ToList();
                                                            if (listStuScoreSub.Count > 0)
                                                            {
                                                                itemTQ_S.studentScore = listStuScoreSub[0].Student_Score.ToString();
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                #endregion

                                string savePathForTch = string.Format("{0}\\", pfunction.ToShortDate(modelHW.CreateTime.ToString()));
                                savePathForTch = "{0}{1}\\" + savePathForTch + "{2}\\{2}.txt";
                                object stuAnswer = new
                                {
                                    list    = resModel.answerJson,
                                    listBig = resModel.listBig
                                };
                                pfunction.WriteToFile(string.Format(savePathForTch, uploadPath, "studentAnswerForMarking", resourceId)
                                                      , Newtonsoft.Json.JsonConvert.SerializeObject(stuAnswer), true);
                                #endregion
                                Rc.Common.SystemLog.SystemLog.AddLogFromBS("", resourceId, string.Format("成功-自动提交学生作业|操作人{0}|学生作业Id{1}|方法{2}", userId, resourceId, "testpaperanswersubmit"));
                            }
                            else
                            {
                                failNum++;
                                Rc.Common.SystemLog.SystemLog.AddLogFromBS("", resourceId, string.Format("失败-自动提交学生作业|操作人{0}|学生作业Id{1}|方法{2}", userId, resourceId, "testpaperanswersubmit"));
                            }
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        failNum++;
                        Rc.Common.SystemLog.SystemLog.AddLogFromBS("", itemShw["Student_HomeWork_Id"].ToString()
                                                                   , string.Format("失败-自动提交学生作业|操作人{0}|学生作业Id{1}|方法{2}。错误:{3}"
                                                                                   , itemShw["Student_Id"].ToString()
                                                                                   , itemShw["Student_HomeWork_Id"].ToString()
                                                                                   , "testpaperanswersubmit"
                                                                                   , ex.Message.ToString().Filter()
                                                                                   )
                                                                   );
                    }


                    Rc.Common.SystemLog.SystemLog.AddLogFromBS("", itemShw["Student_HomeWork_Id"].ToString(), string.Format("完成-自动提交学生作业|操作人{0}|学生作业Id{1}|方法{2}", itemShw["Student_Id"].ToString(), itemShw["Student_HomeWork_Id"].ToString(), "testpaperanswersubmit"));
                }

                #endregion
                #region 记录执行结束信息并保存数据
                model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
                model_FileSyncExecRecordDetail.Detail_Status  = "1";
                model_FileSyncExecRecordDetail.Detail_Remark  = string.Format("执行完成.数据总数{0},成功数{1},失败数{2}", dtShw.Rows.Count, sucNum, failNum);
                bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
                #endregion
            }
            catch (Exception ex)
            {
                model_FileSyncExecRecordDetail.Detail_TimeEnd = DateTime.Now;
                model_FileSyncExecRecordDetail.Detail_Status  = "2";
                model_FileSyncExecRecordDetail.Detail_Remark  = "执行失败:" + ex.Message.ToString();
                bll_FileSyncExecRecordDetail.Update(model_FileSyncExecRecordDetail);
            }
        }