Пример #1
0
        public static JObject DraftRecognition(string sid, string ProjectKeyword, string DocAttrJson, string ContentJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }


                Project m_Project = dbsource.GetProjectByKeyWord(ProjectKeyword);


                if (m_Project == null)
                {
                    reJo.msg = "参数错误!文件夹不存在!";
                    return(reJo.Value);
                }

                #region 获取信函参数内容

                //获取信函参数内容
                string fileCode = "", projectName = "", contractCode = "",
                       sendDate = "", sendCode = "", recCode = "",
                       recType = "", materialType = "";

                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(DocAttrJson);

                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    ////获取函件编号
                    //if (strName == "documentCode") documentCode = strValue.Trim();

                    //获取文件编码
                    if (strName == "fileCode")
                    {
                        fileCode = strValue.Trim();
                    }

                    //获取项目名称
                    else if (strName == "projectName")
                    {
                        projectName = strValue;
                    }

                    //获取合同号
                    else if (strName == "contractCode")
                    {
                        contractCode = strValue;
                    }

                    //获取发文日期
                    else if (strName == "sendDate")
                    {
                        sendDate = strValue;
                    }

                    //获取发文编码
                    else if (strName == "sendCode")
                    {
                        sendCode = strValue;
                    }

                    //获取收文编码
                    else if (strName == "recCode")
                    {
                        recCode = strValue;
                    }

                    //获取来文类型
                    else if (strName == "recType")
                    {
                        recType = strValue;
                    }

                    //获取物资类型
                    else if (strName == "materialType")
                    {
                        materialType = strValue;
                    }
                }


                if (string.IsNullOrEmpty(fileCode))
                {
                    reJo.msg = "请填写文件编号!";
                    return(reJo.Value);
                }
                else if (string.IsNullOrEmpty(projectName))
                {
                    reJo.msg = "请填写工程名称!";
                    return(reJo.Value);
                }


                #endregion

                #region 获取材料或设备列表
                List <Material> materialList = new List <Material>();
                if (!string.IsNullOrEmpty(ContentJson))
                {
                    int    index   = 0;
                    JArray jaFiles = (JArray)JsonConvert.DeserializeObject(ContentJson);

                    foreach (JObject joAttr in jaFiles)
                    {
                        string strMatName     = joAttr["matName"].ToString();     //材料(设备)名称
                        string strSpec        = joAttr["spec"].ToString();        //规格型号
                        string strMeaUnit     = joAttr["meaUnit"].ToString();     //计量单位
                        string strDesignNum   = joAttr["designNum"].ToString();   //设计图号
                        string strBrand       = joAttr["brand"].ToString();       //品牌
                        string strQuantity    = joAttr["quantity"].ToString();    //报审数量
                        string strAudit       = joAttr["audit"].ToString();       //意见
                        string strPrice       = joAttr["price"].ToString();       //报审单价
                        string strCostPrice   = joAttr["costPrice"].ToString();   //造价员单价
                        string strCenterPrice = joAttr["centerPrice"].ToString(); //财务中心单价
                        string strTenderPrice = joAttr["tenderPrice"].ToString(); //招标部单价
                        string strAuditPrice  = joAttr["auditPrice"].ToString();  //审核 合价
                        string strRemark      = joAttr["remark"].ToString();      //备注

                        if (string.IsNullOrEmpty(strMatName))
                        {
                            continue;
                        }

                        index++;
                        string   strIndex = index.ToString();
                        Material afItem   = new Material()
                        {
                            No          = strIndex,
                            MatName     = strMatName,
                            Spec        = strSpec,
                            MeaUnit     = strMeaUnit,
                            DesignNum   = strDesignNum,
                            Brand       = strBrand,
                            Quantity    = strQuantity,
                            Audit       = strAudit,
                            Price       = strPrice,
                            CostPrice   = strCostPrice,
                            CenterPrice = strCenterPrice,
                            TenderPrice = strTenderPrice,
                            AuditPrice  = strAuditPrice,
                            Remark      = strRemark
                        };

                        materialList.Add(afItem);
                    }
                }
                #endregion


                #region 根据信函模板,生成信函文档

                //获取立项单文档所在的目录
                //Project m_Project = m_NewProject;

                List <TempDefn> docTempDefnByCode = m_Project.dBSource.GetTempDefnByCode("PRICEFILE");
                TempDefn        docTempDefn       = (docTempDefnByCode != null && docTempDefnByCode.Count > 0) ? docTempDefnByCode[0] : null;
                if (docTempDefn == null)
                {
                    reJo.msg = "没有与其相关的模板管理,创建无法正常完成";
                    return(reJo.Value);
                }

                IEnumerable <string> source = from docx in m_Project.DocList select docx.Code;
                string filename             = fileCode + " " + projectName + "认质认价报审单";
                if (source.Contains <string>(filename))
                {
                    for (int i = 1; i < 0x3e8; i++)
                    {
                        filename = fileCode + " " + projectName + "认质认价报审单" + i.ToString();
                        if (!source.Contains <string>(filename))
                        {
                            //reJo.msg = "新建信函出错!";
                            //return reJo.Value;
                            break;
                        }
                    }
                }

                //文档名称
                Doc docItem = m_Project.NewDoc(filename + ".docx", filename, "", docTempDefn);
                if (docItem == null)
                {
                    reJo.msg = "新建认质认价单出错!";
                    return(reJo.Value);
                }

                #endregion

                #region 设置信函文档附加属性


                AttrData data;
                //文件编码
                if ((data = docItem.GetAttrDataByKeyWord("PR_FILECODE")) != null)
                {
                    data.SetCodeDesc(fileCode);
                }
                //工程名称
                if ((data = docItem.GetAttrDataByKeyWord("PR_PROJECTNAME")) != null)
                {
                    data.SetCodeDesc(projectName);
                }
                //合同号
                if ((data = docItem.GetAttrDataByKeyWord("PR_CONTRACTCODE")) != null)
                {
                    data.SetCodeDesc(contractCode);
                }
                //发文日期
                if ((data = docItem.GetAttrDataByKeyWord("PR_SENDDATE")) != null)
                {
                    data.SetCodeDesc(sendDate);
                }

                //发文编号
                if ((data = docItem.GetAttrDataByKeyWord("PR_SENDCODE")) != null)
                {
                    data.SetCodeDesc(sendCode);
                }
                //来文编号
                if ((data = docItem.GetAttrDataByKeyWord("PR_RECCODE")) != null)
                {
                    data.SetCodeDesc(recCode);
                }
                //来文类型
                if ((data = docItem.GetAttrDataByKeyWord("PR_RECTYPE")) != null)
                {
                    data.SetCodeDesc(recType);
                }
                //采购类型
                if ((data = docItem.GetAttrDataByKeyWord("PR_MATERIALTYPE")) != null)
                {
                    data.SetCodeDesc(materialType);
                }
                //材料列表
                if ((data = docItem.GetAttrDataByKeyWord("PR_CONTENT")) != null)
                {
                    data.SetCodeDesc(ContentJson);
                }


                ////保存项目属性,存进数据库
                docItem.AttrDataList.SaveData();

                #endregion

                #region 录入数据进入word表单

                string strDocList = "";//获取附件

                //录入数据进入表单
                Hashtable htUserKeyWord = new Hashtable();


                //格式化日期
                DateTime senddate    = Convert.ToDateTime(sendDate);
                string   strSenddate = senddate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");


                htUserKeyWord.Add("FILECODE", fileCode);         //文件编码
                htUserKeyWord.Add("PROJECTNAME", projectName);   //发送方
                htUserKeyWord.Add("CONTRACTCODE", contractCode); //合同号
                htUserKeyWord.Add("SENDDATE", strSenddate);      //日期
                htUserKeyWord.Add("SENDCODE", sendCode);         //编号
                htUserKeyWord.Add("RECCODE", recCode);           //来文编号
                htUserKeyWord.Add("RECTYPE", recType);           //来文类型
                htUserKeyWord.Add("MATERIALTYPE", materialType); //采购类型 (材料或者设备)


                //htUserKeyWord.Add("RHEADER", sendCode);//页眉里面的编码


                //htUserKeyWord["PREPAREDSIGN"] = curUser.O_username;
                //htUserKeyWord["DRAFTTIME"] = DateTime.Now.ToString("yyyy.MM.dd");


                #region 获取项目名称
                Project proj = docItem.Project;
                //Project rootProj = new Project();
                string  rootProjDesc = "";
                Project rootProj     = CommonFunction.getParentProjectByTempDefn(proj, "HXNY_DOCUMENTSYSTEM");

                #endregion
                string proSource = "";
                if (rootProj != null)
                {
                    proSource = rootProj.GetValueByKeyWord("PRO_COMPANY").ToString();

                    //    //string proAddress = rootProj.GetValueByKeyWord("PRO_ADDRESS").ToString();
                    //    //string proTel = rootProj.GetValueByKeyWord("PRO_NUMBER").ToString();

                    //    //htUserKeyWord.Add("PRO_ADDRESS", proAddress);//项目地址
                    //    //htUserKeyWord.Add("PRO_TEL", proTel);//项目电话

                    //    //htUserKeyWord["PROJECTDESC"] = "(" + rootProj.Description + "项目部)";
                }

                //添加附件
                List <string> list3 = new List <string>();
                foreach (Material mat in materialList)
                {
                    list3.Add(mat.No);
                    list3.Add(mat.MatName);
                    list3.Add(mat.Spec);
                    list3.Add(mat.MeaUnit);
                    list3.Add(mat.DesignNum);
                    list3.Add(mat.Brand);
                    list3.Add(mat.Quantity);
                    list3.Add(mat.Audit);
                    list3.Add(mat.Price);
                    list3.Add(mat.CostPrice);
                    list3.Add(mat.CenterPrice);
                    list3.Add(mat.TenderPrice);
                    list3.Add(mat.AuditPrice);
                    list3.Add(mat.Remark);
                }


                //用htAuditDataList传送附件列表到word
                Hashtable htAuditDataList = new Hashtable();
                //word里面表格关键字的设置公式(不需要加"$()") :表格关键字+":"+已画好表格线的行数+":"+表格列数
                //例如关键字是"DRAWING",画了一行表格线,从第二行起画表格线,每行有6列,则公式是:"DRAWING:1:6"
                htAuditDataList.Add("DRAWING", list3);

                //attrDataByKeyWord = mShortDoc.GetAttrDataByKeyWord("IFR_NOTE");
                //if ((attrDataByKeyWord != null) && (this.m_doc != null))
                //{
                //    List<Doc> list4 = this.m_doc.WorkFlow.DocList.Distinct<Doc>().ToList<Doc>();
                //    string docids = "";
                //    list4.ForEach((Action<Doc>)(d => docids = docids + d.O_itemno + ","));
                //    docids = docids.TrimEnd(new char[] { ',' });
                //    attrDataByKeyWord.SetCodeDesc(docids);
                //    mShortDoc.AttrDataList.SaveData();
                //}

                string workingPath = m_Project.dBSource.LoginUser.WorkingPath;


                try
                {
                    //上传下载文档
                    string exchangfilename = (proSource == "CWEC") ? "认质认价工程有限" : "认质认价工业股份";


                    //获取网站路径
                    string sPath = System.Web.HttpContext.Current.Server.MapPath("/ISO/HXEPC/");

                    //获取模板文件路径
                    string modelFileName = sPath + exchangfilename + ".docx";

                    //获取即将生成的联系单文件路径
                    string locFileName = docItem.FullPathFile;

                    FileInfo info = new FileInfo(locFileName);

                    if (System.IO.File.Exists(modelFileName))
                    {
                        //如果存储子目录不存在,就创建目录
                        if (!Directory.Exists(info.Directory.FullName))
                        {
                            Directory.CreateDirectory(info.Directory.FullName);
                        }

                        //复制模板文件到存储目录,并覆盖同名文件
                        System.IO.File.Copy(modelFileName, locFileName, true);


                        //线程锁
                        muxConsole.WaitOne();
                        try
                        {
                            //把参数直接写进office
                            CDMSWebOffice office = new CDMSWebOffice
                            {
                                CloseApp   = true,
                                VisibleApp = false
                            };
                            office.Release(true);
                            office.WriteDataToDocument(docItem, locFileName, htUserKeyWord, htAuditDataList);
                        }
                        catch { }
                        finally
                        {
                            //解锁
                            muxConsole.ReleaseMutex();
                        }
                    }


                    int length = (int)info.Length;
                    docItem.O_size = new int?(length);
                    docItem.Modify();


                    if (string.IsNullOrEmpty(strDocList))
                    {
                        strDocList = docItem.KeyWord;
                    }
                    else
                    {
                        strDocList = docItem.KeyWord + "," + strDocList;
                    }

                    //这里刷新数据源,否则创建流程的时候获取不了专业字符串
                    DBSourceController.RefreshDBSource(sid);

                    reJo.success = true;
                    reJo.data    = new JArray(new JObject(new JProperty("ProjectKeyword", docItem.Project.KeyWord),
                                                          new JProperty("DocKeyword", docItem.KeyWord), new JProperty("DocList", strDocList),
                                                          new JProperty("DocCode", docItem.Code)));
                    return(reJo.Value);
                }
                catch { }
                #endregion

                reJo.data    = new JArray(new JObject(new JProperty("projectKeyword", m_Project.KeyWord)));
                reJo.success = true;
                return(reJo.Value);

                //AVEVA.CDMS.WebApi.DBSourceController.RefreshDBSource(sid);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
Пример #2
0
        /// <summary>
        /// 起草会议纪要
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="ProjectKeyword"></param>
        /// <param name="DocAttrJson"></param>
        /// <returns></returns>
        public static JObject DraftMeetMinutesCN(string sid, string ProjectKeyword, string DocAttrJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }
                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(DocAttrJson);

                Project m_Project = dbsource.GetProjectByKeyWord(ProjectKeyword);

                //定位到发文目录
                //m_Project = LocalProject(m_Project);

                if (m_Project == null)
                {
                    reJo.msg = "参数错误!文件夹不存在!";
                    return(reJo.Value);
                }

                #region 获取项目参数项目

                //获取项目参数项目
                string fileCode = "", sendCode = "",//documentCode = "",
                       sendDate = "", totalPages = "",
                       mainFeeder = "", copyParty = "", title = "",
                       meetTime = "", meetPlace = "", hostUnit = "",
                       moderator = "", participants = "", content = "",
                       approvpath = "", nextStateUserList = "";



                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    //获取文件编码
                    if (strName == "fileCode")
                    {
                        fileCode = strValue.Trim();
                    }

                    //获取发文编号
                    else if (strName == "sendCode")
                    {
                        sendCode = strValue.Trim();
                    }

                    //获取发文日期
                    else if (strName == "sendDate")
                    {
                        sendDate = strValue;
                    }
                    //获取页数
                    else if (strName == "totalPages")
                    {
                        totalPages = strValue;
                    }

                    //获取主送
                    if (strName == "mainFeeder")
                    {
                        mainFeeder = strValue.Trim();
                    }
                    //获取抄送
                    else if (strName == "copyParty")
                    {
                        copyParty = strValue;
                    }

                    //获取会议主题
                    else if (strName == "title")
                    {
                        title = strValue;
                    }
                    //获取会议时间
                    else if (strName == "meetTime")
                    {
                        meetTime = strValue;
                    }
                    //获取会议地点
                    else if (strName == "meetPlace")
                    {
                        meetPlace = strValue;
                    }

                    //获取主办单位
                    else if (strName == "hostUnit")
                    {
                        hostUnit = strValue;
                    }
                    //获取主持人
                    else if (strName == "moderator")
                    {
                        moderator = strValue;
                    }
                    //获取参会单位与人员
                    else if (strName == "participants")
                    {
                        participants = strValue;
                    }

                    //获取会议内容
                    else if (strName == "content")
                    {
                        content = strValue;
                    }

                    //获取审批路径
                    else if (strName == "approvpath")
                    {
                        approvpath = strValue;
                    }

                    //获取下一状态人员
                    else if (strName == "nextStateUserList")
                    {
                        nextStateUserList = strValue;
                    }
                }


                if (string.IsNullOrEmpty(fileCode))
                {
                    reJo.msg = "请填写文件编号!";
                    return(reJo.Value);
                }

                else if (string.IsNullOrEmpty(sendCode))
                {
                    reJo.msg = "请填写发文编码!";
                    return(reJo.Value);
                }
                else if (string.IsNullOrEmpty(title))
                {
                    reJo.msg = "请填写函件标题!";
                    return(reJo.Value);
                }
                else if (string.IsNullOrEmpty(nextStateUserList))
                {
                    reJo.msg = "请选择校审人员!";
                    return(reJo.Value);
                }

                #endregion


                #region 根据会议纪要模板,生成会议纪要文档

                //获取立项单文档所在的目录
                //Project m_Project = m_NewProject;

                List <TempDefn> docTempDefnByCode = m_Project.dBSource.GetTempDefnByCode("MEETINGSUMMARY");
                TempDefn        docTempDefn       = (docTempDefnByCode != null && docTempDefnByCode.Count > 0) ? docTempDefnByCode[0] : null;
                if (docTempDefn == null)
                {
                    reJo.msg = "没有与其相关的模板管理,创建无法正常完成";
                    return(reJo.Value);
                }

                IEnumerable <string> source = from docx in m_Project.DocList select docx.Code;
                string filename             = sendCode + " " + title;
                if (source.Contains <string>(filename))
                {
                    for (int i = 1; i < 0x3e8; i++)
                    {
                        filename = sendCode + " " + title + i.ToString();
                        if (!source.Contains <string>(filename))
                        {
                            //reJo.msg = "新建会议纪要出错!";
                            //return reJo.Value;
                            break;
                        }
                    }
                }

                //文档名称
                Doc docItem = m_Project.NewDoc(filename + ".docx", filename, "", docTempDefn);
                if (docItem == null)
                {
                    reJo.msg = "新建会议纪要出错!";
                    return(reJo.Value);
                }

                #endregion

                #region 设置文会议纪要文档附加属性


                AttrData data;


                //函件编号
                if ((data = docItem.GetAttrDataByKeyWord("ME_FILECODE")) != null)
                {
                    data.SetCodeDesc(fileCode);
                }

                //会议主题
                if ((data = docItem.GetAttrDataByKeyWord("ME_TITLE")) != null)
                {
                    data.SetCodeDesc(title);
                }

                //会议时间
                if ((data = docItem.GetAttrDataByKeyWord("ME_TIME")) != null)
                {
                    data.SetCodeDesc(meetTime);
                }

                //函件编号
                if ((data = docItem.GetAttrDataByKeyWord("ME_SENDCODE")) != null)
                {
                    data.SetCodeDesc(sendCode);
                }

                //发文日期
                if ((data = docItem.GetAttrDataByKeyWord("ME_SENDDATE")) != null)
                {
                    data.SetCodeDesc(sendDate);
                }

                //主送
                if ((data = docItem.GetAttrDataByKeyWord("ME_MAINSEND")) != null)
                {
                    data.SetCodeDesc(mainFeeder);
                }

                //页数
                if ((data = docItem.GetAttrDataByKeyWord("ME_PAGE")) != null)
                {
                    data.SetCodeDesc(totalPages);
                }

                //抄送
                if ((data = docItem.GetAttrDataByKeyWord("ME_COPY")) != null)
                {
                    data.SetCodeDesc(copyParty);
                }


                ////保存项目属性,存进数据库
                docItem.AttrDataList.SaveData();

                #endregion

                #region 录入数据进入word表单

                string strDocList = "";//获取附件

                //录入数据进入表单
                Hashtable htUserKeyWord = new Hashtable();


                //格式化日期
                DateTime senddate = Convert.ToDateTime(sendDate);

                string strSenddate = senddate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");


                htUserKeyWord.Add("HEADERCODE", fileCode);   //页眉里面的发文编码

                htUserKeyWord.Add("SENDDATE", strSenddate);  //发送日期
                htUserKeyWord.Add("PAGE", totalPages);       //页数

                htUserKeyWord.Add("MAINFEEDER", mainFeeder); //主送
                //htUserKeyWord.Add("DOCUMENTCODE", documentCode);//发文编码

                htUserKeyWord.Add("COPY", copyParty);            //抄送方

                htUserKeyWord.Add("TITLE", title);               //标题
                htUserKeyWord.Add("MEETTIME", meetTime);         //会议时间
                htUserKeyWord.Add("MEETPLACE", meetPlace);       //会议地点

                htUserKeyWord.Add("HOSTUNIT", hostUnit);         //主办单位
                htUserKeyWord.Add("MODERATOR", moderator);       //主持人
                htUserKeyWord.Add("PARTICIPANTS", participants); //参会单位与人员

                htUserKeyWord.Add("CONTENT", content);           //会议内容


                string workingPath = m_Project.dBSource.LoginUser.WorkingPath;


                try
                {
                    //上传下载文档
                    string exchangfilename = "会议纪要中文模板";

                    //获取网站路径
                    string sPath = System.Web.HttpContext.Current.Server.MapPath("/ISO/HXEPC/");

                    //获取模板文件路径
                    string modelFileName = sPath + exchangfilename + ".docx";

                    //获取即将生成的联系单文件路径
                    string locFileName = docItem.FullPathFile;

                    FileInfo info = new FileInfo(locFileName);

                    if (System.IO.File.Exists(modelFileName))
                    {
                        //如果存储子目录不存在,就创建目录
                        if (!Directory.Exists(info.Directory.FullName))
                        {
                            Directory.CreateDirectory(info.Directory.FullName);
                        }

                        //复制模板文件到存储目录,并覆盖同名文件
                        System.IO.File.Copy(modelFileName, locFileName, true);


                        //线程锁
                        muxConsole.WaitOne();
                        try
                        {
                            //把参数直接写进office
                            CDMSWebOffice office = new CDMSWebOffice
                            {
                                CloseApp   = true,
                                VisibleApp = false
                            };
                            office.Release(true);
                            office.WriteDataToDocument(docItem, locFileName, htUserKeyWord, htUserKeyWord);
                        }
                        catch { }
                        finally
                        {
                            //解锁
                            muxConsole.ReleaseMutex();
                        }
                    }


                    int length = (int)info.Length;
                    docItem.O_size = new int?(length);
                    docItem.Modify();


                    if (string.IsNullOrEmpty(strDocList))
                    {
                        strDocList = docItem.KeyWord;
                    }
                    else
                    {
                        strDocList = docItem.KeyWord + "," + strDocList;
                    }

                    //这里刷新数据源,否则创建流程的时候获取不了专业字符串
                    DBSourceController.RefreshDBSource(sid);

                    reJo.success = true;
                    reJo.data    = new JArray(new JObject(new JProperty("ProjectKeyword", docItem.Project.KeyWord),
                                                          new JProperty("DocKeyword", docItem.KeyWord), new JProperty("DocList", strDocList)));
                    return(reJo.Value);
                }
                catch { }
                #endregion

                reJo.data    = new JArray(new JObject(new JProperty("projectKeyword", m_Project.KeyWord)));
                reJo.success = true;
                return(reJo.Value);

                //AVEVA.CDMS.WebApi.DBSourceController.RefreshDBSource(sid);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
Пример #3
0
        public static JObject DraftTransmittalCN(string sid, string ProjectKeyword, string DocAttrJson, string FileListJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }
                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(DocAttrJson);

                Project m_Project = dbsource.GetProjectByKeyWord(ProjectKeyword);

                //定位到发文目录
                //m_Project = LocalProject(m_Project);

                if (m_Project == null)
                {
                    reJo.msg = "参数错误!文件夹不存在!";
                    return(reJo.Value);
                }

                #region 获取项目参数项目

                //获取项目参数项目
                string fileCode = "", documentCode = "", mainFeeder = "", copyParty = "",
                       sender = "", sendDate = "", totalPages = "",
                       seculevel = "", secrTerm = "", needreply = "",
                       replyDate = "", transmode = "", transmodeSupp = "",
                       purpose = "", purposeSupp = "", title = "",
                       content = "", approvpath = "";



                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    //获取文件编码
                    if (strName == "fileCode")
                    {
                        fileCode = strValue.Trim();
                    }

                    //获取函件编号
                    if (strName == "documentCode")
                    {
                        documentCode = strValue.Trim();
                    }

                    //获取主送
                    if (strName == "mainFeeder")
                    {
                        mainFeeder = strValue.Trim();
                    }
                    //获取发送方
                    else if (strName == "sender")
                    {
                        sender = strValue;
                    }

                    //获取发送日期
                    else if (strName == "sendDate")
                    {
                        sendDate = strValue;
                    }
                    //获取页数
                    else if (strName == "totalPages")
                    {
                        totalPages = strValue;
                    }

                    //获取保密等级
                    else if (strName == "seculevel")
                    {
                        seculevel = strValue;
                    }
                    //获取保密期限
                    else if (strName == "secrTerm")
                    {
                        secrTerm = strValue;
                    }

                    //获取是否需要回复
                    else if (strName == "needreply")
                    {
                        needreply = strValue;
                    }
                    //获取回文日期
                    else if (strName == "replyDate")
                    {
                        replyDate = strValue;
                    }

                    //获取传递方式
                    else if (strName == "transmode")
                    {
                        transmode = strValue;
                    }
                    //获取传递方式补充说明
                    else if (strName == "transmodeSupp")
                    {
                        transmodeSupp = strValue;
                    }

                    //获取提交目的
                    else if (strName == "purpose")
                    {
                        purpose = strValue;
                    }
                    //获取提交目的补充说明
                    else if (strName == "purposeSupp")
                    {
                        purposeSupp = strValue;
                    }

                    //获取标题
                    else if (strName == "title")
                    {
                        title = strValue;
                    }
                    //获取正文内容
                    else if (strName == "content")
                    {
                        content = strValue;
                    }

                    else if (strName == "approvpath")
                    {
                        approvpath = strValue;
                    }
                }


                if (string.IsNullOrEmpty(documentCode))
                {
                    reJo.msg = "请填写函件编号!";
                    return(reJo.Value);
                }
                else if (string.IsNullOrEmpty(title))
                {
                    reJo.msg = "请填写函件标题!";
                    return(reJo.Value);
                }
                else if (string.IsNullOrEmpty(mainFeeder))
                {
                    reJo.msg = "请填写主送单位!";
                    return(reJo.Value);
                }

                #endregion

                #region 获取文件列表
                List <LetterAttaFile> attaFiles   = new List <LetterAttaFile>();
                if (!string.IsNullOrEmpty(FileListJson))
                {
                    int    index   = 0;
                    JArray jaFiles = (JArray)JsonConvert.DeserializeObject(FileListJson);

                    foreach (JObject joAttr in jaFiles)
                    {
                        string strFileName  = joAttr["fn"].ToString(); //文件名
                        string strFileCode  = joAttr["fc"].ToString(); //文件编码
                        string strFileDesc  = joAttr["fd"].ToString(); //文件题名
                        string strFilePage  = joAttr["fp"].ToString(); //页数
                        string strEdition   = joAttr["fe"].ToString(); //版次
                        string strSeculevel = joAttr["sl"].ToString(); //密级
                        string strFileState = joAttr["fs"].ToString(); //状态
                        string strRemark    = joAttr["fr"].ToString(); //状态

                        index++;
                        string         strIndex = index.ToString();
                        LetterAttaFile afItem   = new LetterAttaFile()
                        {
                            No        = strIndex,
                            Name      = strFileName,
                            Code      = strFileCode,
                            Desc      = strFileDesc,
                            Page      = strFilePage,
                            Edition   = strEdition,
                            Seculevel = strSeculevel,
                            Status    = strFileState,
                            Remark    = strRemark
                        };

                        attaFiles.Add(afItem);
                    }
                }
                #endregion

                #region 根据文件传递单模板,生成文件传递单文档

                //获取立项单文档所在的目录
                //Project m_Project = m_NewProject;

                List <TempDefn> docTempDefnByCode = m_Project.dBSource.GetTempDefnByCode("FILETRANSMIT");
                TempDefn        docTempDefn       = (docTempDefnByCode != null && docTempDefnByCode.Count > 0) ? docTempDefnByCode[0] : null;
                if (docTempDefn == null)
                {
                    reJo.msg = "没有与其相关的模板管理,创建无法正常完成";
                    return(reJo.Value);
                }

                IEnumerable <string> source = from docx in m_Project.DocList select docx.Code;
                string filename             = documentCode + " " + title;
                if (source.Contains <string>(filename))
                {
                    for (int i = 1; i < 0x3e8; i++)
                    {
                        filename = documentCode + " " + title + i.ToString();
                        if (!source.Contains <string>(filename))
                        {
                            //reJo.msg = "新建文件传递单出错!";
                            //return reJo.Value;
                            break;
                        }
                    }
                }

                //文档名称
                Doc docItem = m_Project.NewDoc(filename + ".xlsx", filename, "", docTempDefn);
                if (docItem == null)
                {
                    reJo.msg = "新建文件传递单出错!";
                    return(reJo.Value);
                }

                #endregion

                #region 设置文件传递单文档附加属性


                AttrData data;

                //文件编码
                if ((data = docItem.GetAttrDataByKeyWord("FI_FILECODE")) != null)
                {
                    data.SetCodeDesc(fileCode);
                }

                //主送
                if ((data = docItem.GetAttrDataByKeyWord("FI_MAINFEEDER")) != null)
                {
                    data.SetCodeDesc(mainFeeder);
                }
                //发送方
                if ((data = docItem.GetAttrDataByKeyWord("FI_SENDER")) != null)
                {
                    data.SetCodeDesc(sender);
                }

                //发文日期
                if ((data = docItem.GetAttrDataByKeyWord("FI_SENDDATE")) != null)
                {
                    data.SetCodeDesc(sendDate);
                }

                //页数
                if ((data = docItem.GetAttrDataByKeyWord("FI_PAGE")) != null)
                {
                    data.SetCodeDesc(totalPages);
                }

                //保密等级
                if ((data = docItem.GetAttrDataByKeyWord("FI_SECRETGRADE")) != null)
                {
                    data.SetCodeDesc(seculevel);
                }
                //保密期限
                if ((data = docItem.GetAttrDataByKeyWord("FI_SECRETTERM")) != null)
                {
                    data.SetCodeDesc(secrTerm);
                }

                //获取是否需要回复
                if ((data = docItem.GetAttrDataByKeyWord("FI_IFREPLY")) != null)
                {
                    data.SetCodeDesc(needreply);
                }
                //回复日期
                if ((data = docItem.GetAttrDataByKeyWord("FI_REPLYDATE")) != null)
                {
                    data.SetCodeDesc(replyDate);
                }

                //传递方式
                if ((data = docItem.GetAttrDataByKeyWord("FI_TRANSMITMETHOD")) != null)
                {
                    data.SetCodeDesc(transmode);
                }
                //传递方式的补充说明
                if ((data = docItem.GetAttrDataByKeyWord("FI_TRANSMITMETHODSUPP")) != null)
                {
                    data.SetCodeDesc(transmodeSupp);
                }

                //提交目的
                if ((data = docItem.GetAttrDataByKeyWord("FI_SUBMISSIONOBJ")) != null)
                {
                    data.SetCodeDesc(purpose);
                }
                //提交目的补充说明
                if ((data = docItem.GetAttrDataByKeyWord("FI_SUBMISSIONOBJSUPP")) != null)
                {
                    data.SetCodeDesc(purposeSupp);
                }

                //标题
                if ((data = docItem.GetAttrDataByKeyWord("FI_TRANSMITTITLE")) != null)
                {
                    data.SetCodeDesc(title);
                }

                //摘要
                if ((data = docItem.GetAttrDataByKeyWord("FI_ABSTRACT")) != null)
                {
                    data.SetCodeDesc(content);
                }

                //校审级数(审批路径)
                if ((data = docItem.GetAttrDataByKeyWord("CA_SERIES")) != null)
                {
                    data.SetCodeDesc(approvpath);
                }
                ////保存项目属性,存进数据库
                docItem.AttrDataList.SaveData();

                #endregion

                #region 录入数据进入word表单

                string strDocList = "";//获取附件

                //录入数据进入表单
                Hashtable htUserKeyWord = new Hashtable();

                #region 添加勾选项

                #region 初始化勾选选项注释

                ////////////////保密等级////////////////////////
                string SECULEVEL_SECRET = "□";     //商业秘密
                string SECULEVEL_LIMIT  = "□";     //受限
                string SECULEVEL_PUBLIC = "□";     //公开

                string SECULEVEL_SECRET_TERM = ""; //保密期限
                string SECULEVEL_LIMIT_TERM  = ""; //保密期限

                ///////////////是否需要回复/////////////////////
                string NEEDREPLY_YES = "□"; //是
                string NEEDREPLY_NO  = "□"; //否

                ///////////////传递方式/////////////////////
                string TRANSMITMETHOD_POST   = "□"; //邮寄
                string TRANSMITMETHOD_ONFACE = "□"; //当面递交
                string TRANSMITMETHOD_MAIL   = "□"; //邮件
                string TRANSMITMETHOD_OA     = "□"; //OA
                string TRANSMITMETHOD_CDMS   = "□"; //CDMS
                string TRANSMITMETHOD_OTHER  = "□"; //其他

                string TRANSMITMETHOD_SUPP = "";    //传递方式补充说明

                //////////////提交目的/////////////////////
                string SUBMISSIONOBJ_SUBMI    = "□"; //提交
                string SUBMISSIONOBJ_DEMAND   = "□"; //按需求提交
                string SUBMISSIONOBJ_CHECK    = "□"; //审查
                string SUBMISSIONOBJ_RECORD   = "□"; //备案
                string SUBMISSIONOBJ_PURCHASE = "□"; //采购
                string SUBMISSIONOBJ_SUPPLY   = "□"; //供货
                string SUBMISSIONOBJ_CONS     = "□"; //施工
                string SUBMISSIONOBJ_DEBUG    = "□"; //调试
                string SUBMISSIONOBJ_INFORM   = "□"; //告知
                string SUBMISSIONOBJ_HANDOVER = "□"; //交工资料
                string SUBMISSIONOBJ_OTHER    = "□"; //其他

                string SUBMISSIONOBJ_SUPP = "";      //提交目的补充说明

                #endregion

                #region 勾选选项


                //勾选保密等级
                if (seculevel == "商业秘密")
                {
                    SECULEVEL_SECRET      = "☑";
                    SECULEVEL_SECRET_TERM = secrTerm;
                }
                else if (seculevel == "受限")
                {
                    SECULEVEL_LIMIT      = "☑";
                    SECULEVEL_LIMIT_TERM = secrTerm;
                }
                else if (seculevel == "公开")
                {
                    SECULEVEL_PUBLIC = "☑";
                }

                //勾选保密等级
                if (needreply == "是")
                {
                    NEEDREPLY_YES = "☑";
                }
                else if (needreply == "否")
                {
                    NEEDREPLY_NO = "☑";
                }

                //勾选传递方式
                if (transmode == "邮寄")
                {
                    TRANSMITMETHOD_POST = "☑";
                }
                else if (transmode == "当面递交")
                {
                    TRANSMITMETHOD_ONFACE = "☑";
                }
                else if (transmode == "邮件")
                {
                    TRANSMITMETHOD_MAIL = "☑";
                }
                else if (transmode == "OA")
                {
                    TRANSMITMETHOD_OA = "☑";
                }
                else if (transmode == "CDMS")
                {
                    TRANSMITMETHOD_CDMS = "☑";
                }
                else if (transmode == "其他")
                {
                    TRANSMITMETHOD_OTHER = "☑";
                    TRANSMITMETHOD_SUPP  = transmodeSupp;//传递方式补充说明
                }


                //勾选提交目的
                if (purpose == "提交")
                {
                    SUBMISSIONOBJ_SUBMI = "☑";
                }
                else if (purpose == "按需求提交")
                {
                    SUBMISSIONOBJ_DEMAND = "☑";
                }
                else if (purpose == "审查")
                {
                    SUBMISSIONOBJ_CHECK = "☑";
                }
                else if (purpose == "备案")
                {
                    SUBMISSIONOBJ_RECORD = "☑";
                }
                else if (purpose == "采购")
                {
                    SUBMISSIONOBJ_PURCHASE = "☑";
                }
                else if (purpose == "供货")
                {
                    SUBMISSIONOBJ_SUPPLY = "☑";
                }
                else if (purpose == "施工")
                {
                    SUBMISSIONOBJ_CONS = "☑";
                }
                else if (purpose == "调试")
                {
                    SUBMISSIONOBJ_DEBUG = "☑";
                }
                else if (purpose == "告知")
                {
                    SUBMISSIONOBJ_INFORM = "☑";
                }
                else if (purpose == "交工资料")
                {
                    SUBMISSIONOBJ_HANDOVER = "☑";
                }
                else if (purpose == "其他")
                {
                    SUBMISSIONOBJ_OTHER = "☑";
                    SUBMISSIONOBJ_SUPP  = purposeSupp;//提交目的补充说明
                }


                #endregion

                #region 添加勾选项到哈希表

                ////////////////保密等级////////////////////////
                htUserKeyWord.Add("C101", SECULEVEL_SECRET);      //商业秘密
                htUserKeyWord.Add("C102", SECULEVEL_LIMIT);       //受限
                htUserKeyWord.Add("C103", SECULEVEL_PUBLIC);      //公开

                htUserKeyWord.Add("T001", SECULEVEL_SECRET_TERM); //商业秘密保密期限
                htUserKeyWord.Add("T002", SECULEVEL_LIMIT_TERM);  //受限保密期限

                ///////////////是否需要回复/////////////////////
                htUserKeyWord.Add("C201", NEEDREPLY_YES); //是
                htUserKeyWord.Add("C202", NEEDREPLY_NO);  //否

                ///////////////传递方式/////////////////////
                htUserKeyWord.Add("C301", TRANSMITMETHOD_POST);   //邮寄
                htUserKeyWord.Add("C302", TRANSMITMETHOD_ONFACE); //当面递交
                htUserKeyWord.Add("C303", TRANSMITMETHOD_MAIL);   //邮件
                htUserKeyWord.Add("C304", TRANSMITMETHOD_OA);     //OA
                htUserKeyWord.Add("C305", TRANSMITMETHOD_CDMS);   //CDMS
                htUserKeyWord.Add("C306", TRANSMITMETHOD_OTHER);  //其他

                htUserKeyWord.Add("T003", TRANSMITMETHOD_SUPP);   //传递方式补充说明

                //////////////提交目的/////////////////////
                htUserKeyWord.Add("C401", SUBMISSIONOBJ_SUBMI);    //提交
                htUserKeyWord.Add("C402", SUBMISSIONOBJ_DEMAND);   //按需求提交
                htUserKeyWord.Add("C403", SUBMISSIONOBJ_CHECK);    //审查
                htUserKeyWord.Add("C404", SUBMISSIONOBJ_RECORD);   //备案
                htUserKeyWord.Add("C405", SUBMISSIONOBJ_PURCHASE); //采购
                htUserKeyWord.Add("C406", SUBMISSIONOBJ_SUPPLY);   //供货
                htUserKeyWord.Add("C407", SUBMISSIONOBJ_CONS);     //施工
                htUserKeyWord.Add("C408", SUBMISSIONOBJ_DEBUG);    //调试
                htUserKeyWord.Add("C409", SUBMISSIONOBJ_INFORM);   //告知
                htUserKeyWord.Add("C410", SUBMISSIONOBJ_HANDOVER); //交工资料
                htUserKeyWord.Add("C411", SUBMISSIONOBJ_OTHER);    //其他

                htUserKeyWord.Add("T004", SUBMISSIONOBJ_SUPP);     //提交目的补充说明


                #endregion
                #endregion

                //格式化日期
                DateTime senddate     = Convert.ToDateTime(sendDate);
                DateTime replydate    = Convert.ToDateTime(replyDate);
                string   strSenddate  = senddate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");
                string   strReplydate = replydate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");

                //htUserKeyWord.Add("DOCUMENTCODE", documentCode);//函件编号
                //htUserKeyWord.Add("MAINFEEDER", mainFeeder);//主送
                //htUserKeyWord.Add("SENDER", sender);//发送方
                //htUserKeyWord.Add("SENDDATE", strSenddate);//发送日期
                //htUserKeyWord.Add("PAGE", totalPages);//页数

                //htUserKeyWord.Add("REPLYDATE", strReplydate);//回复日期

                //htUserKeyWord.Add("TITLE", title);//标题
                //htUserKeyWord.Add("CONTENT", content);//摘要正文

                //htUserKeyWord.Add("T005", documentCode);//函件编号
                htUserKeyWord.Add("T006", mainFeeder);   //主送
                htUserKeyWord.Add("T007", sender);       //发送方
                htUserKeyWord.Add("T008", strSenddate);  //发送日期
                htUserKeyWord.Add("T009", totalPages);   //页数

                htUserKeyWord.Add("T010", strReplydate); //回复日期

                htUserKeyWord.Add("T011", title);        //标题
                htUserKeyWord.Add("T012", content);      //摘要正文

                //htUserKeyWord.Add("RIGHT__HEADER", "编码:"+ fileCode);//设置右边页眉

                //添加附件
                List <string> list3 = new List <string>();
                foreach (LetterAttaFile file in attaFiles)
                {
                    //string remark = string.IsNullOrEmpty(file.Seculevel) ? "" : (file.Seculevel+",");
                    //remark = remark+(string.IsNullOrEmpty(file.Status) ? "" : (file.Status + ","));
                    //remark = remark + (string.IsNullOrEmpty(file.Remark) ? "" : (file.Remark + ","));

                    //if (remark.Substring(remark.Length - 1, 1) == ","&& (!string.IsNullOrEmpty(remark))) {
                    //    remark=remark.Substring(0, remark.Length-1);
                    //}

                    list3.Add(file.No);
                    list3.Add(file.Code);
                    list3.Add(file.Desc);
                    list3.Add(file.Page);
                    list3.Add(file.Edition);
                    list3.Add(file.Seculevel);
                    list3.Add(file.Status);
                    list3.Add(file.Remark);
                }

                //用htAuditDataList传送附件列表到word
                Hashtable htAuditDataList = new Hashtable();
                //word里面表格关键字的设置公式(不需要加"$()") :表格关键字+":"+已画好表格线的行数+":"+表格列数
                //例如关键字是"DRAWING",画了一行表格线,从第二行起画表格线,每行有6列,则公式是:"DRAWING:1:6"
                htAuditDataList.Add("DRAWING", list3);

                string workingPath = m_Project.dBSource.LoginUser.WorkingPath;


                try
                {
                    //上传下载文档
                    string exchangfilename = "文件传递单中文模板";

                    //获取网站路径
                    string sPath = System.Web.HttpContext.Current.Server.MapPath("/ISO/HXEPC/");

                    //获取模板文件路径
                    string modelFileName = sPath + exchangfilename + ".xlsx";

                    //获取即将生成的联系单文件路径
                    string locFileName = docItem.FullPathFile;

                    FileInfo info = new FileInfo(locFileName);

                    if (System.IO.File.Exists(modelFileName))
                    {
                        //如果存储子目录不存在,就创建目录
                        if (!Directory.Exists(info.Directory.FullName))
                        {
                            Directory.CreateDirectory(info.Directory.FullName);
                        }

                        //复制模板文件到存储目录,并覆盖同名文件
                        System.IO.File.Copy(modelFileName, locFileName, true);


                        //线程锁
                        muxConsole.WaitOne();
                        try
                        {
                            //把参数直接写进office
                            CDMSWebOffice office = new CDMSWebOffice
                            {
                                CloseApp   = true,
                                VisibleApp = false
                            };
                            office.Release(true);
                            office.WriteDataToDocument(docItem, locFileName, htUserKeyWord, htAuditDataList);
                        }
                        catch { }
                        finally
                        {
                            //解锁
                            muxConsole.ReleaseMutex();
                        }
                    }


                    int length = (int)info.Length;
                    docItem.O_size = new int?(length);
                    docItem.Modify();


                    if (string.IsNullOrEmpty(strDocList))
                    {
                        strDocList = docItem.KeyWord;
                    }
                    else
                    {
                        strDocList = docItem.KeyWord + "," + strDocList;
                    }

                    //这里刷新数据源,否则创建流程的时候获取不了专业字符串
                    DBSourceController.RefreshDBSource(sid);

                    reJo.success = true;
                    reJo.data    = new JArray(new JObject(new JProperty("ProjectKeyword", docItem.Project.KeyWord),
                                                          new JProperty("DocKeyword", docItem.KeyWord), new JProperty("DocList", strDocList)));
                    return(reJo.Value);
                }
                catch { }
                #endregion

                reJo.data    = new JArray(new JObject(new JProperty("projectKeyword", m_Project.KeyWord)));
                reJo.success = true;
                return(reJo.Value);

                //AVEVA.CDMS.WebApi.DBSourceController.RefreshDBSource(sid);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
Пример #4
0
        /// <summary>
        /// 处理收文表单
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="DocKeyword"></param>
        /// <returns></returns>
        public static JObject ReceiveDocument(string sid, string DocKeyword, string docAttrJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                Doc m_Doc = dbsource.GetDocByKeyWord(DocKeyword);

                if (m_Doc == null)
                {
                    reJo.msg = "参数错误!文档不存在!";
                    return(reJo.Value);
                }

                #region 获取收文处理表单的属性

                string strProjectCode = "", strProjectDesc = "", strCommUnit = "", strRecDate = "",
                       strRecCode = "", strRecNumber = "", strPages = "",
                       strSendCode = "", strNeedReply = "", strReplyDate = "",
                       strUrgency = "", strRemark = "",
                       strFileCode = "", strTitle = "";

                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(docAttrJson);

                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    //获取项目号
                    if (strName == "ProjectCode")
                    {
                        strProjectCode = strValue;
                    }

                    //获取项目名称
                    if (strName == "ProjectDesc")
                    {
                        strProjectDesc = strValue;
                    }

                    //获取来文单位
                    else if (strName == "CommUnit")
                    {
                        strCommUnit = strValue;
                    }

                    //获取来文单位
                    else if (strName == "RecDate")
                    {
                        strRecDate = strValue;
                    }

                    //获取收文编码
                    else if (strName == "RecCode")
                    {
                        strRecCode = strValue;
                    }

                    //获取收文编码
                    else if (strName == "RecNumber")
                    {
                        strRecNumber = strValue;
                    }

                    //获取文件编码
                    else if (strName == "FileCode")
                    {
                        strFileCode = strValue;
                    }



                    //获取文件题名
                    else if (strName == "Title")
                    {
                        strTitle = strValue;
                    }

                    //获取页数
                    else if (strName == "Pages")
                    {
                        strPages = strValue;
                    }

                    //获取我方发文编码
                    else if (strName == "SendCode")
                    {
                        strSendCode = strValue;
                    }

                    //获取是否要求回文
                    else if (strName == "NeedReply")
                    {
                        strNeedReply = strValue;
                    }

                    //获取回文期限
                    else if (strName == "ReplyDate")
                    {
                        strReplyDate = strValue;
                    }

                    //获取紧急程度
                    else if (strName == "Urgency")
                    {
                        strUrgency = strValue;
                    }

                    //获取备注
                    else if (strName == "Remark")
                    {
                        strRemark = strValue;
                    }
                }
                #endregion

                #region 根据收文单模板,生成收文单文档

                //获取立项单文档所在的目录
                //Project m_Project = m_NewProject;

                List <TempDefn> docTempDefnByCode = dbsource.GetTempDefnByCode("RECEIPT");
                TempDefn        docTempDefn       = (docTempDefnByCode != null && docTempDefnByCode.Count > 0)? docTempDefnByCode[0] : null;
                if (docTempDefn == null)
                {
                    reJo.msg = "没有与其相关的模板管理,创建无法正常完成";
                    return(reJo.Value);
                }

                IEnumerable <string> source = from docx in m_Doc.Project.DocList select docx.Code;
                string filename             = strRecCode + " 收文单";
                if (source.Contains <string>(filename))
                {
                    for (int i = 1; i < 0x3e8; i++)
                    {
                        filename = strRecCode + " 收文单" + i.ToString();
                        if (!source.Contains <string>(filename))
                        {
                            break;
                        }
                    }
                }

                //文档名称
                //Doc docItem = m_Doc.Project.NewDoc(filename + ".docx", filename, "", docTempDefn);
                Doc docItem = m_Doc.Project.NewDoc(filename + ".docx", filename, "");
                if (docItem == null)
                {
                    reJo.msg = "新建信函出错!";
                    return(reJo.Value);
                }

                #endregion

                #region 设置收文文档附加属性
                m_Doc.TempDefn = docTempDefn;

                AttrData data;
                //项目名称
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_PRONAME")) != null)
                {
                    data.SetCodeDesc(strProjectDesc);
                }
                //项目代码
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_PROCODE")) != null)
                {
                    data.SetCodeDesc(strProjectCode);
                }
                //来文单位
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_SENDUNIT")) != null)
                {
                    data.SetCodeDesc(strCommUnit);
                }
                //收文日期
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_RECDATE")) != null)
                {
                    data.SetCodeDesc(strRecDate);
                }
                //收文编码
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_RECCODE")) != null)
                {
                    data.SetCodeDesc(strRecCode);
                }
                //收文编号
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_RECNUMBER")) != null)
                {
                    data.SetCodeDesc(strRecNumber);
                }
                //文件编码
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_FILECODE")) != null)
                {
                    data.SetCodeDesc(strFileCode);
                }
                //文件题名
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_FILETITLE")) != null)
                {
                    data.SetCodeDesc(strTitle);
                }
                //页数
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_PAGE")) != null)
                {
                    data.SetCodeDesc(strPages);
                }
                //发文编码
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_SENDCODE")) != null)
                {
                    data.SetCodeDesc(strSendCode);
                }

                //是否回文
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_IFREPLY")) != null)
                {
                    data.SetCodeDesc(strNeedReply);
                }
                //回文日期
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_REPLYDATE")) != null)
                {
                    data.SetCodeDesc(strReplyDate);
                }
                //紧急程度
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_URGENTDEGREE")) != null)
                {
                    data.SetCodeDesc(strUrgency);
                }

                //备注
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_NOTE")) != null)
                {
                    data.SetCodeDesc(strRemark);
                }
                //著录人
                if ((data = m_Doc.GetAttrDataByKeyWord("RE_DESIGN")) != null)
                {
                    data.SetCodeDesc(curUser.ToString);
                }


                ////保存项目属性,存进数据库
                m_Doc.AttrDataList.SaveData();
                //m_Doc.Modify();
                #endregion

                //修改文档编码
                m_Doc.O_itemname = strRecCode; //strRecNumber;
                //m_Doc.O_itemdesc = strTitle;
                m_Doc.Modify();

                #region 录入数据进入word表单
                Hashtable htUserKeyWord = new Hashtable();

                //格式化日期
                DateTime RecDate   = Convert.ToDateTime(strRecDate);
                DateTime ReplyDate = Convert.ToDateTime(strReplyDate);
                string   recDate   = RecDate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");
                string   replyDate = ReplyDate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");

                htUserKeyWord.Add("PRONAME", strProjectDesc);     //项目名称
                htUserKeyWord.Add("PROCODE", strProjectCode);     //项目代码
                htUserKeyWord.Add("SENDUNIT", strCommUnit);       //来文单位
                htUserKeyWord.Add("RECDATE", recDate);            //收文日期
                htUserKeyWord.Add("RECCODE", strRecCode);         //收文编码
                htUserKeyWord.Add("RECNUMBER", strRecNumber);     //收文编号
                htUserKeyWord.Add("FILECODE", strFileCode);       //文件编码
                htUserKeyWord.Add("FILETITLE", strTitle);         //文件题名
                htUserKeyWord.Add("PAGE", strPages);              //页数
                htUserKeyWord.Add("SENDCODE", strSendCode);       //发文编码
                htUserKeyWord.Add("IFREPLY", strNeedReply);       //是否回文
                htUserKeyWord.Add("REPLYDATE", replyDate);        //回文日期
                htUserKeyWord.Add("URGENTDEGREE", strUrgency);    //紧急程度
                htUserKeyWord.Add("NOTE", strRemark);             //备注
                htUserKeyWord.Add("DESIGN", curUser.Description); //著录人


                string workingPath = dbsource.LoginUser.WorkingPath;


                try
                {
                    //上传下载文档
                    string exchangfilename = "收文单模板";

                    //获取网站路径
                    string sPath = System.Web.HttpContext.Current.Server.MapPath("/ISO/HXEPC/");

                    //获取模板文件路径
                    string modelFileName = sPath + exchangfilename + ".docx";

                    //获取即将生成的联系单文件路径
                    string locFileName = docItem.FullPathFile;

                    FileInfo info = new FileInfo(locFileName);

                    if (System.IO.File.Exists(modelFileName))
                    {
                        //如果存储子目录不存在,就创建目录
                        if (!Directory.Exists(info.Directory.FullName))
                        {
                            Directory.CreateDirectory(info.Directory.FullName);
                        }

                        //复制模板文件到存储目录,并覆盖同名文件
                        System.IO.File.Copy(modelFileName, locFileName, true);


                        //线程锁
                        muxConsole.WaitOne();
                        try
                        {
                            //把参数直接写进office
                            CDMSWebOffice office = new CDMSWebOffice
                            {
                                CloseApp   = true,
                                VisibleApp = false
                            };
                            office.Release(true);
                            office.WriteDataToDocument(docItem, locFileName, htUserKeyWord, htUserKeyWord);
                        }
                        catch { }
                        finally
                        {
                            //解锁
                            muxConsole.ReleaseMutex();
                        }
                    }


                    int length = (int)info.Length;
                    docItem.O_size = new int?(length);
                    docItem.Modify();
                }
                catch { }
                #endregion

                ////启动流程
                WorkFlow flow = dbsource.NewWorkFlow(new List <Doc> {
                    docItem, m_Doc
                }, "RECEIVED");
                if (flow == null)
                {
                    //AssistFun.PopUpPrompt("自动启动流程失败!请手动启动");
                    reJo.msg = "自动启动流程失败!请手动启动";
                    return(reJo.Value);
                }
                else
                {
                    if ((flow != null) && (flow.CuWorkState != null))
                    {
                        //if (((flow.CuWorkState == null) || (flow.CuWorkState.workStateBranchList == null)) || (flow.CuWorkState.workStateBranchList.Count <= 0))
                        //{
                        //    //MessageBox.Show("新建流程不存在下一状态,提交失败!");
                        //    //doc.dBSource.ProgramRun = false;
                        //    flow.Delete();
                        //    reJo.msg = "新建流程不存在下一状态,提交失败!";
                        //    return reJo.Value;
                        //    //return;
                        //}
                        //WorkStateBranch branch = flow.CuWorkState.workStateBranchList[0];
                        //if (branch == null)
                        //{
                        //    reJo.msg = "获取流程分支失败!";
                        //    return reJo.Value;
                        //}

                        Project rootProj = CommonFunction.getParentProjectByTempDefn(m_Doc.Project, "HXNY_DOCUMENTSYSTEM");
                        if (rootProj == null)
                        {
                            reJo.msg = "获取项目根目录失败!";
                            return(reJo.Value);
                        }

                        string   UserList = "";
                        AttrData secData;
                        //rootProj.GetAttrDataByKeyWord("SECRETARILMAN");
                        if ((secData = rootProj.GetAttrDataByKeyWord("SECRETARILMAN")) != null)
                        {
                            UserList = secData.ToString;
                        }

                        if (string.IsNullOrEmpty(UserList))
                        {
                            reJo.msg = "项目文控未设置!";
                            return(reJo.Value);
                        }

                        //ExReJObject wfReJo = WebWorkFlowEvent.GotoNextStateAndSelectUser(flow.CuWorkState.workStateBranchList[0],userlist);
                        ////if (!WorkFlowEvent.GotoNextStateAndSelectUser(flow.CuWorkState.workStateBranchList[0]))
                        //if (!wfReJo.success)
                        //{
                        //    //doc.dBSource.ProgramRun = false;
                        //    flow.Delete();
                        //    flow.Delete();
                        //    reJo.msg = "自动启动收文流程失败,请手动启动流程!";
                        //    return reJo.Value;
                        //}

                        ////刷新数据源
                        //DBSourceController.RefreshDBSource(sid);

                        #region 获取下一状态用户
                        string[] userArray = (string.IsNullOrEmpty(UserList) ? "" : UserList).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        Server.Group group = new Server.Group();
                        //List<User> m_UserList = new List<User>();
                        //启动工作流程
                        //反转列表
                        //m_UserList.Reverse();
                        foreach (string strObj in userArray)
                        {
                            string strUser = strObj.IndexOf("__") >= 0 ? strObj.Substring(0, strObj.IndexOf("__")) : strObj;
                            object obj     = dbsource.GetUserByName(strUser);

                            if (obj is User)
                            {
                                //m_UserList.Add((User)obj);
                                group.AddUser((User)obj);
                            }
                        }
                        if (group.UserList.Count <= 0)
                        {
                            reJo.msg = "获取下一流程状态用户错误,自动启动流程失败!请手动启动流程";
                            return(reJo.Value);
                        }
                        #endregion

                        //获取下一状态

                        WorkState ws = new WorkState();

                        DefWorkState dws = flow.DefWorkFlow.DefWorkStateList.Find(s => s.KeyWord == "SECRETARILMAN");    // CHECK");
                        ws.DefWorkState = dws;


                        ////启动流程
                        WorkStateBranch branch = flow.CuWorkState.workStateBranchList[0];
                        branch.NextStateAddGroup(group);

                        ExReJObject GotoNextReJo = WebWorkFlowEvent.GotoNextStateAndSelectUser(flow.CuWorkState.workStateBranchList[0]);

                        if (!GotoNextReJo.success)
                        {
                            //  doc.dBSource.ProgramRun = false;
                            flow.Delete();
                            flow.Delete();

                            reJo.msg = "自动启动流程失败!请手动启动流程";
                            return(reJo.Value);
                        }

                        DBSourceController.RefreshDBSource(sid);

                        //return GotoNextReJo.Value;

                        reJo.data = new JArray(new JObject(new JProperty("ProjectKeyword", m_Doc.Project.KeyWord),
                                                           new JProperty("DocKeyword", m_Doc.KeyWord)));
                        reJo.success = true;
                        return(reJo.Value);
                    }
                }

                reJo.success = true;
                return(reJo.Value);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }
            return(reJo.Value);
        }
Пример #5
0
        //发文流程盖章
        public static JObject DocumenteSeal(string sid, string DocKeyword, string isSeal)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                Doc doc = dbsource.GetDocByKeyWord(DocKeyword);
                if (doc == null)
                {
                    reJo.msg = "错误的文档操作信息!指定的文档不存在!";
                    return(reJo.Value);
                }

                if (doc.WorkFlow == null)
                {
                    reJo.msg = "错误的文档操作信息!指定的文档流程不存在!";
                    return(reJo.Value);
                }

                //录入数据进入表单
                //格式化日期
                DateTime inscribedate    = Convert.ToDateTime(DateTime.Now);
                string   strInscribedate = inscribedate.ToShortDateString().ToString().Replace("-", ".").Replace("/", ".");

                Hashtable htUserKeyWord = new Hashtable();

                string   inscribe = "", sendercode = "";
                AttrData data;
                //获取发送方
                if ((data = doc.GetAttrDataByKeyWord("CA_SENDER")) != null)
                {
                    inscribe = data.ToString;
                }

                //获取发送方代码
                if ((data = doc.GetAttrDataByKeyWord("CA_SENDERCODE")) != null)
                {
                    sendercode = data.ToString;
                }

                if (isSeal == "true")
                {
                    if (!string.IsNullOrEmpty(sendercode))
                    {
                        //盖章图片名
                        htUserKeyWord["SEAL"] = sendercode + "SEAL";
                    }
                    else
                    {
                        //盖章图片名
                        htUserKeyWord["SEAL"] = "BLANK" + "SEAL";
                    }
                }
                else
                {
                    //盖章图片名
                    htUserKeyWord["SEAL"] = "BLANK" + "SEAL";
                }


                //落款
                htUserKeyWord["INSCRIBE"] = inscribe;
                //落款时间
                htUserKeyWord["INSCRIBEDATE"] = strInscribedate;



                //获取即将生成的联系单文件路径
                string locFileName = doc.FullPathFile;

                FileInfo info = new FileInfo(locFileName);

                if (System.IO.File.Exists(locFileName))
                {
                    //线程锁
                    muxConsole.WaitOne();
                    try
                    {
                        //把参数直接写进office
                        CDMSWebOffice office = new CDMSWebOffice
                        {
                            CloseApp   = true,
                            VisibleApp = false
                        };
                        office.Release(true);
                        office.WriteDataToDocument(doc, locFileName, htUserKeyWord, htUserKeyWord);
                    }
                    catch { }
                    finally
                    {
                        //解锁
                        muxConsole.ReleaseMutex();
                    }
                }

                if (doc.WorkFlow.CuWorkState.Code == "APPROV" &&
                    dbsource.LoginUser.O_userno == doc.WorkFlow.CuWorkState.CuWorkUser.O_userno)
                {
                    doc.WorkFlow.O_suser3 = "approvpass";
                    doc.WorkFlow.Modify();

                    DBSourceController.refreshDBSource(sid);
                }

                reJo.data = new JArray(new JObject(new JProperty("WorkFlowKeyword", doc.WorkFlow.KeyWord)));

                reJo.success = true;
                return(reJo.Value);
            }
            catch (Exception exception)
            {
                //WebApi.CommonController.WebWriteLog(exception.Message + "\r\n" + exception.Source + "\r\n" + exception.StackTrace);
                reJo.msg = "盖章失败!" + exception.Message;
            }
            return(reJo.Value);
        }