using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.DCGL.ServerCheck
{
    public partial class CheckRectify : PageBase
    {
        private static string proType;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                proType = Request.Params["proType"] ?? string.Empty;
                this.GetButtonPower();
                //btnNew.OnClientClick = Window1.GetShowReference("CheckRectifyEdit.aspx") + "return false;";              
                ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
                // 绑定表格
                BindGrid();
            }
        }
        /// 
        /// 绑定数据
        ///  
        private void BindGrid()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append($@"SELECT S.CheckRectifyId,S.CheckRectifyCode,S.ProjectId,S.ProjectName,S.UnitId,U.UnitName,S.CheckDate,CASE S.HandleState WHEN '{BLL.Const.State_1}' THEN '未签发' WHEN '{BLL.Const.State_2}' THEN '未上报' ELSE '已上报' END AS HandleState,
                            S.IssueMan,S.IssueDate,ISNULL(TotalCount.TotalCount,0) AS TotalCount ,ISNULL(CompleteCount.CompleteCount,0) AS CompleteCount,(ISNULL(TotalCount.TotalCount,0) -ISNULL(CompleteCount.CompleteCount,0)) AS UnCompleteCount ");
            sb.Append("FROM dbo.DCGL_Check_CheckRectify AS S LEFT JOIN dbo.Base_Unit AS U ON U.UnitId = S.UnitId ");
            sb.Append("     LEFT JOIN (SELECT COUNT(*) AS TotalCount, CheckRectifyId FROM dbo.DCGL_Check_CheckRectifyItem GROUP BY CheckRectifyId) AS TotalCount ON S.CheckRectifyId=TotalCount.CheckRectifyId ");
            sb.Append("     LEFT JOIN (SELECT COUNT(*) AS CompleteCount, CheckRectifyId FROM dbo.DCGL_Check_CheckRectifyItem WHERE RealEndDate IS NOT NULL GROUP BY CheckRectifyId) AS CompleteCount ON S.CheckRectifyId=CompleteCount.CheckRectifyId ");
            if (!string.IsNullOrWhiteSpace(proType) && proType == "1")
            {//只查询本项目检查数据
                sb.Append($"WHERE S.ProjectId='{this.CurrUser.LoginProjectId}' ");
            }
            sb.Append("ORDER BY HandleState");
            SqlParameter[] parameter = new SqlParameter[] { };
            DataTable tb = SQLHelper.GetDataTableRunText(sb.ToString(), parameter);
            // 2.获取当前分页数据
            //var table = this.GetPagedDataTable(Grid1, tb1);
            Grid1.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
            for (int i = 0; i < Grid1.Rows.Count; i++)
            {
                Model.DCGL_Check_CheckRectify rectify = BLL.DCGLCheckRectifyService.GetCheckRectifyByCheckRectifyId(Grid1.Rows[i].DataKeys[0].ToString());
                if (rectify != null)
                {
                    if (rectify.HandleState == "1")
                    {
                        Grid1.Rows[i].RowCssClass = "yellow";
                    }
                    else if (rectify.HandleState == "2")
                    {
                        Grid1.Rows[i].RowCssClass = "red";
                    }
                }
            }
        }
        /// 
        /// 分页
        ///  
        /// 
        /// 排序
        ///  
        /// 
        /// 分页显示条数下拉框
        ///  
        /// 
        /// 右键编辑事件
        ///  
        /// 
        /// Grid行双击事件
        ///  
        /// 
        /// 编辑数据方法
        ///  
        private void EditData()
        {
            if (Grid1.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
                return;
            }
            string CheckRectifyId = Grid1.SelectedRowID;
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckRectifyEdit.aspx?CheckRectifyId={0}", CheckRectifyId, "编辑 - ")));
        }
        #endregion
        /// 
        /// 关闭弹出窗
        ///  
        /// 
        /// 获取按钮权限
        ///  
        /// 
        /// 导出方法
        ///  
        /// 
");
            foreach (List rows in mht.MultiTable)
            {
                sb.Append("");
                foreach (object[] cell in rows)
                {
                    int rowspan = Convert.ToInt32(cell[0]);
                    int colspan = Convert.ToInt32(cell[1]);
                    GridColumn column = cell[2] as GridColumn;
                    sb.AppendFormat("{3} ",
                       rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
                       colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
                      colspan != 1 ? " style=\"text-align:center;\"" : "",
                        column.HeaderText);
                }
                sb.Append(" ");
            }
            foreach (GridRow row in grid.Rows)
            {
                sb.Append("");
                foreach (GridColumn column in mht.Columns)
                {
                    string html = row.Values[column.ColumnIndex].ToString();
                    if (column.ColumnID == "tfNumber")
                    {
                        html = (row.FindControl("lblNumber") as AspNet.Label).Text;
                    }
                    if (column.ColumnID == "UnitName")
                    {
                        html = (row.FindControl("lblUnit") as AspNet.Label).Text;
                    }
                    if (column.ColumnID == "ProjectName")
                    {
                        //html = (row.FindControl("lblProjectId") as AspNet.Label).Text;
                        html = (row.FindControl("lblProjectName") as AspNet.Label).Text;
                    }
                    sb.AppendFormat("{0} ", html);
                }
                sb.Append(" ");
            }
            sb.Append(" 
");
            return sb.ToString();
        }
        #region 多表头处理
        /// 
        /// 多表头处理
        ///  
        public class MultiHeaderTable
        {
            // 包含 rowspan,colspan 的多表头,方便生成 HTML 的 table 标签
            public List> MultiTable = new List>();
            // 最终渲染的列数组
            public List Columns = new List();
            public void ResolveMultiHeaderTable(GridColumnCollection columns)
            {
                List row = new List();
                foreach (GridColumn column in columns)
                {
                    object[] cell = new object[4];
                    cell[0] = 1;    // rowspan
                    cell[1] = 1;    // colspan
                    cell[2] = column;
                    cell[3] = null;
                    row.Add(cell);
                }
                ResolveMultiTable(row, 0);
                ResolveColumns(row);
            }
            private void ResolveColumns(List row)
            {
                foreach (object[] cell in row)
                {
                    GroupField groupField = cell[2] as GroupField;
                    if (groupField != null && groupField.Columns.Count > 0)
                    {
                        List subrow = new List();
                        foreach (GridColumn column in groupField.Columns)
                        {
                            subrow.Add(new object[]
                           {
                               1,
                                1,
                               column,
                                groupField
                            });
                        }
                        ResolveColumns(subrow);
                    }
                    else
                    {
                        Columns.Add(cell[2] as GridColumn);
                    }
                }
            }
            private void ResolveMultiTable(List row, int level)
            {
                List nextrow = new List();
                foreach (object[] cell in row)
                {
                    GroupField groupField = cell[2] as GroupField;
                    if (groupField != null && groupField.Columns.Count > 0)
                    {
                        // 如果当前列包含子列,则更改当前列的 colspan,以及增加父列(向上递归)的colspan
                        cell[1] = Convert.ToInt32(groupField.Columns.Count);
                        PlusColspan(level - 1, cell[3] as GridColumn, groupField.Columns.Count - 1);
                        foreach (GridColumn column in groupField.Columns)
                        {
                            nextrow.Add(new object[]
                           {
                               1,
                                1,
                                column,
                                groupField
                           });
                        }
                    }
                }
                MultiTable.Add(row);
                // 如果当前下一行,则增加上一行(向上递归)中没有子列的列的 rowspan
                if (nextrow.Count > 0)
                {
                    PlusRowspan(level);
                    ResolveMultiTable(nextrow, level + 1);
                }
            }
            private void PlusRowspan(int level)
            {
                if (level < 0)
                {
                    return;
                }
                foreach (object[] cells in MultiTable[level])
                {
                    GroupField groupField = cells[2] as GroupField;
                    if (groupField != null && groupField.Columns.Count > 0)
                    {
                        // ...
                    }
                    else
                    {
                        cells[0] = Convert.ToInt32(cells[0]) + 1;
                    }
                }
                PlusRowspan(level - 1);
            }
            private void PlusColspan(int level, GridColumn parent, int plusCount)
            {
                if (level < 0)
                {
                    return;
                }
                foreach (object[] cells in MultiTable[level])
                {
                    GridColumn column = cells[2] as GridColumn;
                    if (column == parent)
                    {
                        cells[1] = Convert.ToInt32(cells[1]) + plusCount;
                        PlusColspan(level - 1, cells[3] as GridColumn, plusCount);
                    }
                }
            }
        }
        #endregion
        #endregion
        /// 
        /// 从集团获取
        ///  
        /// 
        ///  获取督查检查整改
        ///  
        ///  ids = new List();
                                foreach (var item in getData)
                                {
                                    string getCheckRectifyId = item["CheckRectifyId"].ToString();
                                    if (!ids.Contains(getCheckRectifyId))
                                    {
                                        var newRectify = db.DCGL_Check_CheckRectify.FirstOrDefault(e => e.CheckRectifyId == getCheckRectifyId);
                                        if (newRectify == null)
                                        {
                                            ids.Add(getCheckRectifyId);
                                            Model.DCGL_Check_CheckRectify newCheckRectify = new Model.DCGL_Check_CheckRectify
                                            {
                                                CheckRectifyId = getCheckRectifyId,
                                                CheckRectifyCode = item["CheckRectifyCode"].ToString(),
                                                ProjectId = item["ProjectId"].ToString(),
                                                ProjectName = item["ProjectName"].ToString(),
                                                UnitId = unitId,
                                                CheckDate = Funs.GetNewDateTime(item["CheckDate"].ToString()),
                                                IssueMan = item["IssueMan"].ToString(),
                                                IssueDate = Funs.GetNewDateTime(item["IssueDate"].ToString()),
                                                HandleState = item["HandleState"].ToString()
                                            };
                                            db.DCGL_Check_CheckRectify.InsertOnSubmit(newCheckRectify);
                                            db.SubmitChanges();
                                        }
                                        else
                                        {
                                            newRectify.CheckRectifyCode = item["CheckRectifyCode"].ToString();
                                            db.SubmitChanges();
                                        }
                                        //获取对应主表主键的明细集合
                                        string getNoticeItemId = item["NoticeItemId"].ToString();
                                        var notice = db.DCGL_Check_CheckInfo_TableNoticeItem.FirstOrDefault(x => x.ID == getNoticeItemId);
                                        if (notice == null)
                                        {
                                            Model.DCGL_Check_CheckInfo_TableNoticeItem newCheckRectifyItem = new Model.DCGL_Check_CheckInfo_TableNoticeItem
                                            {
                                                ID = getNoticeItemId,
                                                CheckInfoId = item["CheckInfoId"].ToString(),
                                                SortIndex = Funs.GetNewInt(item["SortIndex"].ToString()),
                                                Describe = item["Describe"].ToString(),
                                                Standards = item["Standards"].ToString(),
                                                Advice = item["Advice"].ToString(),
                                                LimitTime = Funs.GetNewDateTime(item["LimitTime"].ToString()),
                                                Situation = item["Situation"].ToString(),
                                                Remark = item["Remark"].ToString(),
                                                Url = item["Url"].ToString(),
                                                AffUrl = item["AffUrl"].ToString(),
                                                RiskLevel = item["RiskLevel"].ToString(),
                                                ProblemTypes = item["ProblemTypes"].ToString(),
                                                ProblemSubTypeId = item["ProblemSubTypeId"].ToString(),
                                                ProblemSubType = item["ProblemSubType"].ToString(),
                                                States = item["States"].ToString(),
                                                //WorkType = item["WorkType"].ToString(),
                                                //DangerPoint = item["DangerPoint"].ToString(),
                                                //RiskExists = item["RiskExists"].ToString(),
                                                //IsProject = Convert.ToBoolean(item["IsProject"].ToString()),
                                                //CheckMan = item["CheckMan"].ToString(),
                                                //SubjectUnitMan = item["SubjectUnitMan"].ToString(),
                                            };
                                            db.DCGL_Check_CheckInfo_TableNoticeItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                        BLL.CommonService.DeleteAttachFileById(getNoticeItemId);//删除附件
                                                                                                ////上传附件
                                        string getAttachFileId = item["AttachFileId"].ToString();
                                        if (!string.IsNullOrEmpty(getAttachFileId))
                                        {
                                            List resultList = new List();
                                            string filePath = item["FilePath"].ToString();
                                            string attachSource = item["AttachSource"].ToString();
                                            string attachUrl = item["AttachUrl"].ToString();
                                            BLL.FileInsertService.InsertAttachFileRecord(getAttachFileId, getNoticeItemId, attachSource, attachUrl);
                                            //if (!string.IsNullOrWhiteSpace(filePath) && !string.IsNullOrWhiteSpace(attachSource) && !string.IsNullOrWhiteSpace(attachUrl))
                                            //{
                                            //    resultList = FileInsertService.FilePathTransStream(filePath, attachUrl);
                                            //}
                                            //BLL.FileInsertService.InsertAttachFile(getAttachFileId, getNoticeItemId, attachSource, attachUrl, resultList);                                            
                                        }
                                        string getCheckRectifyItemId = item["CheckRectifyItemId"].ToString();
                                        var oldItem = db.DCGL_Check_CheckRectifyItem.FirstOrDefault(e => e.CheckRectifyItemId == getCheckRectifyItemId);
                                        if (oldItem == null)
                                        {
                                            Model.DCGL_Check_CheckRectifyItem newCheckRectifyItem = new Model.DCGL_Check_CheckRectifyItem
                                            {
                                                CheckRectifyItemId = getCheckRectifyItemId,
                                                CheckRectifyId = getCheckRectifyId,
                                                NoticeItemId = getNoticeItemId,
                                                ConfirmMan = item["ConfirmMan"].ToString(),
                                                ConfirmManName = item["ConfirmManName"].ToString(),
                                                ConfirmDate = Funs.GetNewDateTime(item["ConfirmDate"].ToString()),
                                                OrderEndDate = Funs.GetNewDateTime(item["OrderEndDate"].ToString()),
                                                OrderEndPerson = item["OrderEndPerson"].ToString(),
                                                RealEndDate = Funs.GetNewDateTime(item["RealEndDate"].ToString()),
                                            };
                                            db.DCGL_Check_CheckRectifyItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                    }
                                    else
                                    {
                                        //获取对应主表主键的明细集合
                                        string getNoticeItemId = item["NoticeItemId"].ToString();
                                        var notice = db.DCGL_Check_CheckInfo_TableNoticeItem.FirstOrDefault(x => x.ID == getNoticeItemId);
                                        if (notice == null)
                                        {
                                            Model.DCGL_Check_CheckInfo_TableNoticeItem newCheckRectifyItem = new Model.DCGL_Check_CheckInfo_TableNoticeItem
                                            {
                                                ID = getNoticeItemId,
                                                CheckInfoId = item["CheckInfoId"].ToString(),
                                                SortIndex = Funs.GetNewInt(item["SortIndex"].ToString()),
                                                Describe = item["Describe"].ToString(),
                                                Standards = item["Standards"].ToString(),
                                                Advice = item["Advice"].ToString(),
                                                LimitTime = Funs.GetNewDateTime(item["LimitTime"].ToString()),
                                                Situation = item["Situation"].ToString(),
                                                Remark = item["Remark"].ToString(),
                                                Url = item["Url"].ToString(),
                                                AffUrl = item["AffUrl"].ToString(),
                                                RiskLevel = item["RiskLevel"].ToString(),
                                                ProblemTypes = item["ProblemTypes"].ToString(),
                                                ProblemSubTypeId = item["ProblemSubTypeId"].ToString(),
                                                ProblemSubType = item["ProblemSubType"].ToString(),
                                                States = item["States"].ToString(),
                                                //WorkType = item["WorkType"].ToString(),
                                                //DangerPoint = item["DangerPoint"].ToString(),
                                                //RiskExists = item["RiskExists"].ToString(),
                                                //IsProject = Convert.ToBoolean(item["IsProject"].ToString()),
                                                //CheckMan = item["CheckMan"].ToString(),
                                                //SubjectUnitMan = item["SubjectUnitMan"].ToString(),
                                            };
                                            db.DCGL_Check_CheckInfo_TableNoticeItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                        BLL.CommonService.DeleteAttachFileById(getNoticeItemId);//删除附件
                                                                                                ////上传附件
                                        string getAttachFileId = item["AttachFileId"].ToString();
                                        if (!string.IsNullOrEmpty(getAttachFileId))
                                        {
                                            List resultList = new List();
                                            string attachSource = item["AttachSource"].ToString();
                                            string attachUrl = item["AttachUrl"].ToString();
                                            BLL.FileInsertService.InsertAttachFileRecord(getAttachFileId, getNoticeItemId, attachSource, attachUrl);
                                            //if (!string.IsNullOrWhiteSpace(filePath) && !string.IsNullOrWhiteSpace(attachSource) && !string.IsNullOrWhiteSpace(attachUrl))
                                            //{
                                            //    resultList = FileInsertService.FilePathTransStream(filePath, attachUrl);
                                            //}
                                            //BLL.FileInsertService.InsertAttachFile(getAttachFileId, getNoticeItemId, attachSource, attachUrl, resultList);
                                        }
                                        string getCheckRectifyItemId = item["CheckRectifyItemId"].ToString();
                                        var oldItem = db.DCGL_Check_CheckRectifyItem.FirstOrDefault(e => e.CheckRectifyItemId == getCheckRectifyItemId);
                                        if (oldItem == null)
                                        {
                                            Model.DCGL_Check_CheckRectifyItem newCheckRectifyItem = new Model.DCGL_Check_CheckRectifyItem
                                            {
                                                CheckRectifyItemId = getCheckRectifyItemId,
                                                CheckRectifyId = getCheckRectifyId,
                                                NoticeItemId = getNoticeItemId,
                                                ConfirmMan = item["ConfirmMan"].ToString(),
                                                ConfirmManName = item["ConfirmManName"].ToString(),
                                                ConfirmDate = Funs.GetNewDateTime(item["ConfirmDate"].ToString()),
                                                OrderEndDate = Funs.GetNewDateTime(item["OrderEndDate"].ToString()),
                                                OrderEndPerson = item["OrderEndPerson"].ToString(),
                                                RealEndDate = Funs.GetNewDateTime(item["RealEndDate"].ToString()),
                                            };
                                            db.DCGL_Check_CheckRectifyItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                        responeData.message = "获取成功:整改明细记录" + getData.Count().ToString() + "条";
                    }
                }
            }
            catch (Exception ex)
            {
                responeData.code = 0;
                responeData.message = "获取失败:" + ex.Message;
                ErrLogInfo.WriteLog("督查检查通知单获取!", ex);
            }
            return responeData;
        }
        #endregion
        #region 获取
        /// 
        ///  获取
        ///  
        ///  ids = new List();
                                foreach (var item in getData)
                                {
                                    string getCheckRectifyId = item["CheckRectifyId"].ToString();
                                    if (!ids.Contains(getCheckRectifyId))
                                    {
                                        var newRectify = db.DCGL_Check_CheckRectify.FirstOrDefault(e => e.CheckRectifyId == getCheckRectifyId);
                                        if (newRectify == null)
                                        {
                                            ids.Add(getCheckRectifyId);
                                            Model.DCGL_Check_CheckRectify newCheckRectify = new Model.DCGL_Check_CheckRectify
                                            {
                                                CheckRectifyId = getCheckRectifyId,
                                                CheckRectifyCode = item["CheckRectifyCode"].ToString(),
                                                ProjectId = item["ProjectId"].ToString(),
                                                ProjectName = item["ProjectName"].ToString(),
                                                UnitId = unitId,
                                                CheckDate = Funs.GetNewDateTime(item["CheckDate"].ToString()),
                                                IssueMan = item["IssueMan"].ToString(),
                                                IssueDate = Funs.GetNewDateTime(item["IssueDate"].ToString()),
                                                HandleState = item["HandleState"].ToString()
                                            };
                                            db.DCGL_Check_CheckRectify.InsertOnSubmit(newCheckRectify);
                                            db.SubmitChanges();
                                        }
                                        else
                                        {
                                            newRectify.CheckRectifyCode = item["CheckRectifyCode"].ToString();
                                            db.SubmitChanges();
                                        }
                                        //获取对应主表主键的明细集合
                                        string getNoticeItemId = item["NoticeItemId"].ToString();
                                        var notice = db.DCGL_Check_CheckInfo_TableNoticeItem.FirstOrDefault(x => x.ID == getNoticeItemId);
                                        if (notice == null)
                                        {
                                            Model.DCGL_Check_CheckInfo_TableNoticeItem newCheckRectifyItem = new Model.DCGL_Check_CheckInfo_TableNoticeItem
                                            {
                                                ID = getNoticeItemId,
                                                CheckInfoId = item["CheckInfoId"].ToString(),
                                                SortIndex = Funs.GetNewInt(item["SortIndex"].ToString()),
                                                Describe = item["Describe"].ToString(),
                                                Standards = item["Standards"].ToString(),
                                                Advice = item["Advice"].ToString(),
                                                LimitTime = Funs.GetNewDateTime(item["LimitTime"].ToString()),
                                                Situation = item["Situation"].ToString(),
                                                Remark = item["Remark"].ToString(),
                                                Url = item["Url"].ToString(),
                                                AffUrl = item["AffUrl"].ToString(),
                                                RiskLevel = item["RiskLevel"].ToString(),
                                                ProblemTypes = item["ProblemTypes"].ToString(),
                                                ProblemSubTypeId = item["ProblemSubTypeId"].ToString(),
                                                ProblemSubType = item["ProblemSubType"].ToString(),
                                                States = item["States"].ToString(),
                                                //WorkType = item["WorkType"].ToString(),
                                                //DangerPoint = item["DangerPoint"].ToString(),
                                                //RiskExists = item["RiskExists"].ToString(),
                                                //IsProject = Convert.ToBoolean(item["IsProject"].ToString()),
                                                //CheckMan = item["CheckMan"].ToString(),
                                                //SubjectUnitMan = item["SubjectUnitMan"].ToString(),
                                            };
                                            db.DCGL_Check_CheckInfo_TableNoticeItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                        BLL.CommonService.DeleteAttachFileById(getNoticeItemId);//删除附件
                                                                                                ////上传附件
                                        string getAttachFileId = item["AttachFileId"].ToString();
                                        if (!string.IsNullOrEmpty(getAttachFileId))
                                        {
                                            JArray byteList = item["FileContext"] as JArray;
                                            List resultList = new List();
                                            foreach (JToken token in byteList)
                                            {
                                                byte[] byteArray = Convert.FromBase64String(token.ToString());
                                                resultList.Add(byteArray);
                                            }
                                            //List fileContext = new List();
                                            //fileContext.Add(Convert.FromBase64String(item["FileContext"].ToString()));
                                            BLL.FileInsertService.InsertAttachFile(getAttachFileId, getNoticeItemId, item["AttachSource"].ToString(), item["AttachUrl"].ToString(), resultList);
                                        }
                                        string getCheckRectifyItemId = item["CheckRectifyItemId"].ToString();
                                        var oldItem = db.DCGL_Check_CheckRectifyItem.FirstOrDefault(e => e.CheckRectifyItemId == getCheckRectifyItemId);
                                        if (oldItem == null)
                                        {
                                            Model.DCGL_Check_CheckRectifyItem newCheckRectifyItem = new Model.DCGL_Check_CheckRectifyItem
                                            {
                                                CheckRectifyItemId = getCheckRectifyItemId,
                                                CheckRectifyId = getCheckRectifyId,
                                                NoticeItemId = getNoticeItemId,
                                                ConfirmMan = item["ConfirmMan"].ToString(),
                                                ConfirmManName = item["ConfirmManName"].ToString(),
                                                ConfirmDate = Funs.GetNewDateTime(item["ConfirmDate"].ToString()),
                                                OrderEndDate = Funs.GetNewDateTime(item["OrderEndDate"].ToString()),
                                                OrderEndPerson = item["OrderEndPerson"].ToString(),
                                                RealEndDate = Funs.GetNewDateTime(item["RealEndDate"].ToString()),
                                            };
                                            db.DCGL_Check_CheckRectifyItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                    }
                                    else
                                    {
                                        //获取对应主表主键的明细集合
                                        string getNoticeItemId = item["NoticeItemId"].ToString();
                                        var notice = db.DCGL_Check_CheckInfo_TableNoticeItem.FirstOrDefault(x => x.ID == getNoticeItemId);
                                        if (notice == null)
                                        {
                                            Model.DCGL_Check_CheckInfo_TableNoticeItem newCheckRectifyItem = new Model.DCGL_Check_CheckInfo_TableNoticeItem
                                            {
                                                ID = getNoticeItemId,
                                                CheckInfoId = item["CheckInfoId"].ToString(),
                                                SortIndex = Funs.GetNewInt(item["SortIndex"].ToString()),
                                                Describe = item["Describe"].ToString(),
                                                Standards = item["Standards"].ToString(),
                                                Advice = item["Advice"].ToString(),
                                                LimitTime = Funs.GetNewDateTime(item["LimitTime"].ToString()),
                                                Situation = item["Situation"].ToString(),
                                                Remark = item["Remark"].ToString(),
                                                Url = item["Url"].ToString(),
                                                AffUrl = item["AffUrl"].ToString(),
                                                RiskLevel = item["RiskLevel"].ToString(),
                                                ProblemTypes = item["ProblemTypes"].ToString(),
                                                ProblemSubTypeId = item["ProblemSubTypeId"].ToString(),
                                                ProblemSubType = item["ProblemSubType"].ToString(),
                                                States = item["States"].ToString(),
                                                //WorkType = item["WorkType"].ToString(),
                                                //DangerPoint = item["DangerPoint"].ToString(),
                                                //RiskExists = item["RiskExists"].ToString(),
                                                //IsProject = Convert.ToBoolean(item["IsProject"].ToString()),
                                                //CheckMan = item["CheckMan"].ToString(),
                                                //SubjectUnitMan = item["SubjectUnitMan"].ToString(),
                                            };
                                            db.DCGL_Check_CheckInfo_TableNoticeItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                        BLL.CommonService.DeleteAttachFileById(getNoticeItemId);//删除附件
                                                                                                ////上传附件
                                        string getAttachFileId = item["AttachFileId"].ToString();
                                        if (!string.IsNullOrEmpty(getAttachFileId))
                                        {
                                            JArray byteList = item["FileContext"] as JArray;
                                            List resultList = new List();
                                            foreach (JToken token in byteList)
                                            {
                                                byte[] byteArray = Convert.FromBase64String(token.ToString());
                                                resultList.Add(byteArray);
                                            }
                                            //List fileContext = new List();
                                            //fileContext.Add(Convert.FromBase64String(item["FileContext"].ToString()));
                                            BLL.FileInsertService.InsertAttachFile(getAttachFileId, getNoticeItemId, item["AttachSource"].ToString(), item["AttachUrl"].ToString(), resultList);
                                        }
                                        string getCheckRectifyItemId = item["CheckRectifyItemId"].ToString();
                                        var oldItem = db.DCGL_Check_CheckRectifyItem.FirstOrDefault(e => e.CheckRectifyItemId == getCheckRectifyItemId);
                                        if (oldItem == null)
                                        {
                                            Model.DCGL_Check_CheckRectifyItem newCheckRectifyItem = new Model.DCGL_Check_CheckRectifyItem
                                            {
                                                CheckRectifyItemId = getCheckRectifyItemId,
                                                CheckRectifyId = getCheckRectifyId,
                                                NoticeItemId = getNoticeItemId,
                                                ConfirmMan = item["ConfirmMan"].ToString(),
                                                ConfirmManName = item["ConfirmManName"].ToString(),
                                                ConfirmDate = Funs.GetNewDateTime(item["ConfirmDate"].ToString()),
                                                OrderEndDate = Funs.GetNewDateTime(item["OrderEndDate"].ToString()),
                                                OrderEndPerson = item["OrderEndPerson"].ToString(),
                                                RealEndDate = Funs.GetNewDateTime(item["RealEndDate"].ToString()),
                                            };
                                            db.DCGL_Check_CheckRectifyItem.InsertOnSubmit(newCheckRectifyItem);
                                            db.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                        responeData.message = "获取成功:整改明细记录" + getData.Count().ToString() + "条";
                    }
                }
            }
            catch (Exception ex)
            {
                responeData.code = 0;
                responeData.message = "获取失败:" + ex.Message;
                ErrLogInfo.WriteLog("督查检查通知单获取!", ex);
            }
            return responeData;
        }
        #endregion
    }
}