Ejemplo n.º 1
0
        ///// <summary>
        ///// 流程里面发邮件
        ///// </summary>
        ///// <param name="wf"></param>
        //public static void SendMail(WorkFlow wf)
        //{
        //    try
        //    {
        //        Doc doc = wf.doc;
        //        string CompCode;
        //        string CompName;
        //        string CompEmail;
        //        string CompRecevier;
        //        string CompFaxNo;
        //        string CompEnclosure;

        //        string mailFrom = "*****@*****.**";
        //        List<string> mailToList = new List<string>();
        //        string mailTitle = doc.O_itemname;
        //        string mailBody = "";
        //        List<string> FileList = null;
        //        string mailServer = "smtp.gedi.com.cn";
        //        string userName = "******";
        //        string userPw = "CDMS_12345";

        //        //查找设计阶段
        //        Project p = wf.doc.Project;
        //        while (p != null && p.ParentProject != null)
        //        {
        //            //找设计阶段
        //            if (p != null && p.TempDefn != null && p.TempDefn.KeyWord == "DESIGNPHASE")
        //            {
        //                break;
        //            }
        //            p = p.ParentProject;
        //        }

        //        //查找收文厂家
        //        Project profession = wf.CuWorkState.O_iuser4 != null ? p.dBSource.GetProjectByID((int)wf.CuWorkState.O_iuser4) : null;
        //        if (profession == null)
        //        {
        //            foreach (Project pp in p.ChildProjectList)
        //            {
        //                if (pp.Code == "收文")
        //                {
        //                    foreach (Project cj in pp.ChildProjectList)
        //                    {
        //                        //查找厂家
        //                        Project Comp = doc.Project.ParentProject;
        //                        if (cj.Code == Comp.Code)
        //                        {
        //                            //查找厂家数据
        //                            CompCode = cj.GetAttrDataByKeyWord("FC_COMPANYCODE").ToString;//厂家编码
        //                            CompName = cj.GetAttrDataByKeyWord("FC_COMPANYCHINESE").ToString;//厂家名称
        //                            CompEmail = cj.GetAttrDataByKeyWord("FC_EMAIL").ToString;//邮箱编号
        //                            CompRecevier = cj.GetAttrDataByKeyWord("FC_RECEIVER").ToString;//厂家收件人
        //                            CompFaxNo = cj.GetAttrDataByKeyWord("FC_FAXNO").ToString;//厂家传真号
        //                            CompEnclosure = doc.GetAttrDataByKeyWord("IF_SENDFILE").ToString;//文件附件

        //                            //分割附件
        //                            foreach (string enclosure in CompEnclosure.Split(new char[] { ';' }))
        //                            {
        //                                if (!string.IsNullOrEmpty(enclosure))
        //                                {
        //                                    mailToList.Add(enclosure);
        //                                }
        //                            }
        //                            if (DialogResult.Yes == MessageBox.Show("请核对邮件接收者地址,确认无误后点击确定进行发送(点取消请自行发送邮件)?\r\n接收方:" + CompName + "\r\n接收人:" + CompRecevier + "\r\n接收地址:" + CompEmail, "发送信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
        //                            {
        //                                try
        //                                {
        //                                    mailToList.Add(CompEmail);
        //                                    SendEmail(mailFrom, mailToList, mailTitle, mailBody, FileList, mailServer, userName, userPw);
        //                                    //MessageBox.Show(mailFrom + "\n\n发往\n\n" + CompEmail + "\n\n邮件发送成功   \r\n接口文件编号是:" + doc.Code);
        //                                    //ErrorLog.WriteErrorLog(mailFrom + "发往" + CompEmail + "邮件成功   接口文件编号是:" + doc.Code);
        //                                    WebApi.CommonController.WebWriteLog(mailFrom + "发往" + CompEmail + "邮件成功   接口文件编号是:" + doc.Code);
        //                                }
        //                                catch (Exception exception)
        //                                {
        //                                    //MessageBox.Show(mailFrom + "发往" + CompEmail + "邮件失败,请联系管理员。");
        //                                    //ErrorLog.WriteErrorLog(mailFrom + "发往" + CompEmail + "邮件失败" + exception.ToString() + "   接口文件编号是:" + doc.Code);
        //                                    WebApi.CommonController.WebWriteLog(mailFrom + "发往" + CompEmail + "邮件失败" + exception.ToString() + "   接口文件编号是:" + doc.Code);
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch { }
        //}


        /// <summary>
        /// 内部提资:专业主设人接收文件签名
        /// </summary>
        /// <param name="workflow"></param>
        public static void ExcSign(WorkFlow wf)
        {
            try
            {
                if (wf != null && wf.DocList != null && wf.DocList.Count > 0 && wf.O_WorkFlowStatus == enWorkFlowStatus.Finish)
                {
                    //取第一个文件
                    Doc doc = wf.DocList[0];

                    //文件全称
                    string str = doc.O_filename.ToUpper();

                    //流程状态不能为空
                    if ((wf.WorkStateList == null) || (wf.WorkStateList.Count <= 1))
                    {
                        return;
                    }

                    ////FTP对象
                    //FTPFactory fTP = null;
                    //if (doc.Storage.FTP != null)
                    //{
                    //    //文档存储位置
                    //    fTP = doc.Storage.FTP;
                    //}
                    //else
                    //{
                    //    fTP = new FTPFactory(doc.Storage);
                    //}
                    //if (fTP == null)
                    //{
                    //    return;
                    //}

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

                    //文件路径不为空
                    if (!string.IsNullOrEmpty(locFileName))
                    {
                        if (System.IO.File.Exists(locFileName))
                        {
                            //文件位置
                            FileInfo info = new FileInfo(locFileName);

                            //文件是否只读
                            if (info.IsReadOnly)
                            {
                                info.IsReadOnly = false;
                                //info.Delete();
                            }
                        }

                        //读取
                        //fTP.download(doc.FullPathFile, doc.dBSource.LoginUser.WorkingPath + doc.O_filename, true);
                    }

                    //创建附加表单属性
                    Hashtable htUserKeyWord = new Hashtable();

                    //查找接收人
                    int indx = 1;
                    foreach (WorkState ws in wf.WorkStateList)
                    {
                        if (ws.DefWorkState.O_Code == "RECEIVE")
                        {
                            htUserKeyWord.Add("RECEIVER" + indx.ToString(), ws.WorkUserList[0].User.Code);            //接收用户
                            htUserKeyWord.Add("RENAME" + indx.ToString(), ws.O_suser3);                               //接收专业
                            htUserKeyWord.Add("RETIME" + indx.ToString(), DateTime.Now.ToString("yyyy-MM-dd"));       //接收时间
                            indx++;
                        }
                    }

                    //写表单
                    if (((htUserKeyWord.Count != 0) && str.EndsWith(".DOC")) || ((str.EndsWith(".DOCX") || str.EndsWith(".XLS")) || str.EndsWith(".XLSX")))
                    {
                        WebApi.CDMSWebOffice office = new WebApi.CDMSWebOffice
                        {
                            CloseApp   = true,
                            VisibleApp = false
                        };

                        //释放文档
                        office.Release(true);
                        if ((doc.WorkFlow != null) && (doc.WorkFlow.O_WorkFlowStatus == enWorkFlowStatus.Finish))
                        {
                            office.IsFinial = true;
                        }

                        //写入文档
                        office.WriteDataToDocument(doc, locFileName, htUserKeyWord, htUserKeyWord);
                    }

                    ////上传文件
                    //if (fTP != null)
                    //{
                    //    fTP.upload(doc.dBSource.LoginUser.WorkingPath + doc.O_filename, doc.FullPathFile);
                    //    fTP.close();
                    //}
                }
            }
            catch (Exception ex)
            {
                //错误提示
                //AssistFun.PopUpPrompt("发生错误:" + ex.ToString());
                WebApi.CommonController.WebWriteLog("发生错误:" + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发文通信校审流程签名
        /// </summary>
        /// <param name="wf"></param>
        /// 签名公式:<AVEVA.CDMS.HXEPC_Plugins.CommonFunction><HXSign>
        public static void HXSign(WorkFlow wf)
        {
            try
            {
                if (((wf != null) && (wf.DocList != null)) && (wf.DocList.Count > 0))
                {
                    foreach (Doc doc in wf.DocList)
                    {
                        string    str           = doc.O_filename.ToUpper();
                        Hashtable htUserKeyWord = new Hashtable();
                        if ((wf.WorkStateList == null) || (wf.WorkStateList.Count <= 1))
                        {
                            continue;
                        }
                        int count = wf.WorkStateList.Count;
                        //FTPFactory fTP = null;
                        //if (doc.Storage.FTP != null)
                        //{
                        //    fTP = doc.Storage.FTP;
                        //}
                        //else
                        //{
                        //    fTP = new FTPFactory(doc.Storage);
                        //}
                        //if (fTP == null)
                        //{
                        //    return;
                        //}

                        //获取即将函件的文件路径
                        string locFileName = doc.FullPathFile;

                        if (string.IsNullOrEmpty(locFileName))
                        {
                            return;
                        }
                        if (!System.IO.File.Exists(locFileName))
                        {
                            return;
                        }

                        //if (!string.IsNullOrEmpty(locFileName))
                        //{
                        //    if (System.IO.File.Exists(locFileName))
                        //    {
                        //        FileInfo info = new FileInfo(locFileName);
                        //        if (info.IsReadOnly)
                        //        {
                        //            info.IsReadOnly = false;
                        //            //info.Delete();
                        //        }
                        //    }
                        //    //fTP.download(doc.FullPathFile, doc.dBSource.LoginUser.WorkingPath + doc.O_filename, true);
                        //}

                        string code = wf.CuWorkState.Code;
                        if ((doc.WorkFlow != null) && (doc.WorkFlow.O_WorkFlowStatus == enWorkFlowStatus.Finish))
                        {
                            code = "END";
                        }
                        switch (code)
                        {
                        //校核人
                        case "CHECK":
                            //htUserKeyWord.Add("PREPAREDSIGN1", doc.dBSource.LoginUser.O_username);
                            htUserKeyWord["CHECKPERSON"] = doc.WorkFlow.CuWorkState.WorkUserList[0].User.O_username;
                            htUserKeyWord["CHECKTIME"]   = DateTime.Now.ToString("yyyy.MM.dd");
                            goto Label_04DA;

                        //审核人
                        case "AUDIT":
                            htUserKeyWord["AUDITPERSON"] = doc.WorkFlow.CuWorkState.WorkUserList[0].User.O_username;
                            htUserKeyWord["AUDITTIME"]   = DateTime.Now.ToString("yyyy.MM.dd");
                            goto Label_04DA;

                        //审定人
                        case "AUDIT2":
                            htUserKeyWord["REVIEWER"]   = doc.WorkFlow.CuWorkState.WorkUserList[0].User.O_username;
                            htUserKeyWord["AUDITTIME2"] = DateTime.Now.ToString("yyyy.MM.dd");
                            goto Label_04DA;

                        //批准人
                        case "APPROV":
                            htUserKeyWord["APPROVER"]    = doc.WorkFlow.CuWorkState.WorkUserList[0].User.O_username;
                            htUserKeyWord["APPROVETIME"] = DateTime.Now.ToString("yyyy.MM.dd");

                            //检查签名,如果没有签名的画斜线
                            //校核人
                            htUserKeyWord["CHECKPERSON"] = "slash";
                            //审核人
                            htUserKeyWord["AUDITPERSON"] = "slash";
                            //审定人
                            htUserKeyWord["REVIEWER"] = "slash";


                            goto Label_04DA;


                        case "INTERFACE":
                        case "END":
                        {
                            string str3 = doc.dBSource.ParseExpression(doc, "$(PROJECTOWNER)");
                            if (wf.DefWorkFlow.O_Code == "HTWORKFLOW")
                            {
                                //  htUserKeyWord["APPROVEPERSON"] = doc.dBSource.LoginUser.O_username;
                            }
                            else if (!string.IsNullOrEmpty(str3))
                            {
                                // htUserKeyWord["APPROVEPERSON"] = str3;
                                // htUserKeyWord["APPROVETIME"] = DateTime.Now.ToString("yyyy.MM.dd");
                            }
                            goto Label_04DA;
                        }

                        default:
                            goto Label_04DA;
                        }
                        if (wf.CuWorkState.PreWorkState.Code == "CHECK")
                        {
                            htUserKeyWord["CHECKPERSON"] = doc.dBSource.LoginUser.O_username;
                        }
                        else
                        {
                            htUserKeyWord["AUDITPERSON"] = doc.dBSource.LoginUser.O_username;
                        }
Label_0385:
                        htUserKeyWord["AUDITTIME"] = DateTime.Now.ToString("yyyy.MM.dd");
Label_04DA:
                        if ((str.EndsWith(".DOC") || str.EndsWith(".DOCX")) || (str.EndsWith(".XLS") || str.EndsWith(".XLSX")))
                        {
                            //线程锁
                            muxConsole.WaitOne();
                            try
                            {
                                WebApi.CDMSWebOffice office = new WebApi.CDMSWebOffice
                                {
                                    CloseApp   = true,
                                    VisibleApp = false
                                };
                                office.Release(true);
                                if (doc.WorkFlow != null)
                                {
                                    enWorkFlowStatus status1 = doc.WorkFlow.O_WorkFlowStatus;
                                }
                                office.WriteDataToDocument(doc, locFileName, htUserKeyWord, htUserKeyWord);
                            }
                            catch (Exception ExOffice) {
                                WebApi.CommonController.WebWriteLog(ExOffice.Message);
                            }
                            finally
                            {
                                //解锁
                                muxConsole.ReleaseMutex();
                            }
                            if (((doc.WorkFlow != null) && (doc.WorkFlow.O_WorkFlowStatus == enWorkFlowStatus.Finish)) && (doc.GetValueByKeyWord("GEDI_INNERIFTYPE") != "提出资料"))
                            {
                                if (wf.DefWorkFlow.O_Code == "INTERFACEWORKFLOW")
                                {
                                    Doc      doc2     = doc;
                                    DateTime minValue = DateTime.MinValue;
                                    if ((doc2.Project.DocList != null) && (doc2.Project.DocList.Count > 0))
                                    {
                                        doc2.Project.DocList.Sort(new Comparison <Doc>(CommonFunction.CompareByCode));
                                        Doc doc3 = doc2.Project.DocList.Last <Doc>(dx => dx.TempDefn != null);
                                        if ((doc3 != null) && ((doc3.TempDefn.Code == "GEDI_TRANSFERINGFORM") || (doc3.TempDefn.Code == "GEDI_VIEWFORM")))
                                        {
                                            if ((doc3.WorkFlow != null) && (doc3.WorkFlow.O_WorkFlowStatus == enWorkFlowStatus.Finish))
                                            {
                                                minValue = doc3.WorkFlow.WorkStateList.Last <WorkState>().O_FinishDate.Value;
                                            }
                                        }
                                        else if ((doc3 != null) && (doc3.TempDefn.Code == "IMPORTINTERFACEFILE"))
                                        {
                                            minValue = doc3.O_credatetime;
                                        }
                                    }
                                }
                            }
                            //if (fTP != null)
                            //{
                            //    fTP.upload(doc.dBSource.LoginUser.WorkingPath + doc.O_filename, doc.FullPathFile);
                            //    fTP.close();
                            //}
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                WebApi.CommonController.WebWriteLog(exception.ToString());
                //ErrorLog.WriteErrorLog(exception.ToString());
            }
        }
Ejemplo n.º 3
0
        public static JObject ResetFileCode(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 doc = dbsource.GetDocByKeyWord(DocKeyword);
                if (doc == null)
                {
                    reJo.msg = "错误的文档操作信息!指定的文档不存在!";
                    return(reJo.Value);
                }

                #region 获取信函参数内容

                //获取信函参数内容
                string mainFeeder = "", copyParty = "", sender = "",
                       sendCode = "", recCode = "", totalPages = "",
                       urgency = "", sendDate = "", seculevel = "",
                       secrTerm = "", needreply = "", replyDate = "",
                       title = "", content = "", approvpath = "",
                       nextStateUserList = "";

                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 == "mainFeeder")
                    {
                        mainFeeder = strValue.Trim();
                    }

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

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

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

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


                if (string.IsNullOrEmpty(sendCode))
                {
                    reJo.msg = "请填写函件编号!";
                    return(reJo.Value);
                }
                //else if (string.IsNullOrEmpty(mainFeeder))
                //{
                //    reJo.msg = "请填写主送!";
                //    return reJo.Value;
                //}
                //else if (string.IsNullOrEmpty(sender))
                //{
                //    reJo.msg = "请选择发送方!";
                //    return reJo.Value;
                //}



                #endregion



                #region 填写发文信息进入word表单

                //获取即将函件的文件路径
                string locFileName = doc.FullPathFile;

                if (string.IsNullOrEmpty(locFileName))
                {
                    reJo.msg = "填写发文信息错误,获取函件文件失败!";
                    return(reJo.Value);
                }
                if (!System.IO.File.Exists(locFileName))
                {
                    reJo.msg = "填写发文信息失败,函件文件不存在!";
                    return(reJo.Value);
                }

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

                Hashtable htUserKeyWord = new Hashtable();
                //htUserKeyWord.Add("MAINFEEDER", mainFeeder);//主送
                //htUserKeyWord.Add("SENDER", sender);//发送方
                htUserKeyWord.Add("SENDCODE", sendCode);//发文编码
                //htUserKeyWord.Add("COPY", copyParty);//抄送
                //htUserKeyWord.Add("SENDDATE", strSenddate);//发送日期

                if ((str.EndsWith(".DOC") || str.EndsWith(".DOCX")) || (str.EndsWith(".XLS") || str.EndsWith(".XLSX")))
                {
                    //线程锁
                    muxConsole.WaitOne();
                    try
                    {
                        WebApi.CDMSWebOffice office = new WebApi.CDMSWebOffice
                        {
                            CloseApp   = true,
                            VisibleApp = false
                        };
                        office.Release(true);
                        if (doc.WorkFlow != null)
                        {
                            enWorkFlowStatus status1 = doc.WorkFlow.O_WorkFlowStatus;
                        }
                        office.WriteDataToDocument(doc, locFileName, htUserKeyWord, htUserKeyWord);
                    }
                    catch (Exception ExOffice)
                    {
                        WebApi.CommonController.WebWriteLog(ExOffice.Message);
                    }
                    finally
                    {
                        //解锁
                        muxConsole.ReleaseMutex();
                    }
                }
                #endregion


                if (doc.WorkFlow != null)
                {
                    AttrData data;
                    string   orgSendCode = "";
                    if ((data = doc.GetAttrDataByKeyWord("CA_SENDCODE")) != null)
                    {
                        orgSendCode = data.ToString;
                        //FileCode = FileCode + data.ToString + "-";
                    }

                    string orgName = doc.O_itemname;
                    foreach (Doc docItem in doc.WorkFlow.DocList)
                    {
                        if (docItem != doc)
                        {
                            docItem.O_itemname = docItem.O_itemname.Replace(orgSendCode, sendCode);
                            docItem.Modify();
                        }
                    }
                    doc.O_itemname = doc.O_itemname.Replace(orgSendCode, sendCode);
                    // doc.O_filename = regex.Replace(doc.O_filename, replacement);

                    string fullPathFile = doc.FullPathFile;
                    fullPathFile = fullPathFile.Replace('/', '\\');
                    string newFileName = doc.FullPathFile.Replace(orgSendCode, sendCode);

                    try
                    {
                        File.Move(fullPathFile, newFileName);
                    }
                    catch { }

                    doc.O_filename = doc.O_filename.Replace(orgSendCode, sendCode);

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



                    ////主送
                    //if ((data = doc.GetAttrDataByKeyWord("CA_MAINFEEDER")) != null)
                    //{
                    //    data.SetCodeDesc(mainFeeder);
                    //}
                    ////发送方
                    //if ((data = doc.GetAttrDataByKeyWord("CA_SENDER")) != null)
                    //{
                    //    data.SetCodeDesc(sender);
                    //}
                    //发文编码
                    if ((data = doc.GetAttrDataByKeyWord("CA_SENDCODE")) != null)
                    {
                        data.SetCodeDesc(sendCode);
                    }

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

                    //////发送日期
                    //if ((data = doc.GetAttrDataByKeyWord("CA_SENDDATE")) != null)
                    //{
                    //    data.SetCodeDesc(sendDate);
                    //}

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

                    #endregion

                    doc.Modify();

                    doc.WorkFlow.O_suser3 = "pass";
                    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);
        }