Esempio n. 1
0
 public abstract void AddPicture(CRect rect, string[] sParams, string sTimeStamp, 
     double fLenRatio, double fWidRatio, string sDisplay,
     string sUserID);
Esempio n. 2
0
 public abstract void AddPicture(CRect rect, string[] sParams, string sTimeStamp,
                                 double fLenRatio, double fWidRatio, string sDisplay,
                                 string sUserID);
Esempio n. 3
0
 /// <summary>
 /// 插入图片到WORD打印模板中
 /// </summary>
 /// <param name="rect">待插入图片设置的区域大小</param>
 /// <param name="sParams">待写入参数</param>
 /// <param name="sTimeStamp">生成图片时写入的时间戳</param>
 /// <param name="fLenRatio">图片长比例</param>
 /// <param name="fWidRatio">图片宽比例</param>
 public override void AddPicture(CRect rect, string[] sParams, string sTimeStamp,
     double fLenRatio, double fWidRatio, string sDisplay,
     string sUserID)
 {
     KeyPosition kp = new KeyPosition();
     for (int idx = 0; idx < m_arKeyPosition.Length; idx++)
     {
         if ((ArrayList)m_arKeyPosition.GetValue(idx) != null)
         {
             kp = GetPositionByKey(sParams[0], (ArrayList)m_arKeyPosition.GetValue(idx));
             if (kp.RowIndex != 0)
             {
                 switch (sParams[1].ToLower())
                 {
                     case "down":
                         InsertPicture(m_doc.Tables[kp.TblIndex].Rows[kp.RowIndex + 1].Cells[kp.ColIndex].Range,
                                       rect, sTimeStamp, fLenRatio, fWidRatio, sDisplay, sUserID);
                         return;
                     case "right":
                         InsertPicture(m_doc.Tables[kp.TblIndex].Rows[kp.RowIndex].Cells[kp.ColIndex + 1].Range,
                                       rect, sTimeStamp, fLenRatio, fWidRatio, sDisplay, sUserID);
                         return;
                     case "downs":
                         string[] arrStamp = sTimeStamp.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);
                         string[] arrsUserID = sUserID.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                         for (int i = 1; i <= m_doc.Tables[kp.TblIndex].Rows.Count; i++)
                         {
                             sTimeStamp = arrStamp[i-1]; sUserID = arrsUserID[i-1];
                             InsertPicture(m_doc.Tables[kp.TblIndex].Rows[kp.RowIndex + i].Cells[kp.ColIndex].Range,
                                           rect, sTimeStamp, fLenRatio, fWidRatio, sDisplay, sUserID);
                         }
                         break;
                 }
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 将生成的图片插入到range描述的WORD文档位置
        /// </summary>
        /// <param name="range">WORD文档位置</param>
        /// <param name="rect">待插入图片设置的区域大小</param>
        /// <param name="sTimeStamp">生成图片时写入的时间戳</param>
        /// <param name="fLenRatio">图片长比例</param>
        /// <param name="fWidRatio">图片宽比例</param>
        private void InsertPicture(Range range, CRect rect, string sTimeStamp, 
            double fLenRatio, double fWidRatio, string sDisplay,
            string sUserID)
        {
            int iCur = 0;
            string[] Stamps = null;
            if (sTimeStamp.Contains("\n"))
            {
                Stamps = sTimeStamp.Split(new char[]{'\n'}, StringSplitOptions.RemoveEmptyEntries);
            }
            object Link2File = false;
            object SaveWithDoc = true;

            object Left = null;
            object Top = null;
            object Width = null;
            object Height = null;

            Left = rect.Left;
            Top = rect.Top;
            // 长宽比例若无效则从配置中(Width Height)取得对应长宽值,否则更具长宽比例计算长宽值
            if ((fLenRatio >= -double.Epsilon && fLenRatio <= double.Epsilon) ||
                (fWidRatio >= -double.Epsilon && fWidRatio <= double.Epsilon))
            {

                Width = rect.Width;
                Height = rect.Height;
            }
            else
            {
                // 配置高度无效则根据长宽比例计算处高度
                if (Height == null || rect.Height == 0)
                {
                    Width = rect.Width;
                    Height =(fWidRatio / fLenRatio) * rect.Width;
                }
                // 配置宽度无效则根据高宽比例计算处长度
                if (Width == null || rect.Width == 0)
                {
                    Width = (fLenRatio / fWidRatio) * rect.Height;
                    Height = rect.Height;
                }
            }

            for (int i = 1; i <= range.Paragraphs.Count; i++)
            {
                try
                {
                    string sName = HandleString(range.Paragraphs[i].Range.Text).Trim();
                    if (!string.IsNullOrEmpty(sUserID))
                    {
                        string sdbName = OAUser.GetUserName(sUserID);
                        if (sName != sdbName)
                        {
                            range.Paragraphs[i].Range.Font.Color = WdColor.wdColorWhite;
                            continue;
                        }
                        else
                        {
                            sName = sdbName;
                        }
                    }
                    string sFilePath = HttpContext.Current.Server.MapPath(@"~\template\Singer\" + sName + ".png");
                    if (!File.Exists(sFilePath))
                    {
                        if (Stamps == null)
                        {
                            sFilePath = GenSingerPic(sName, sFilePath, sTimeStamp, sDisplay);
                        }
                        else
                        {
                            if (Stamps.Length > iCur)
                                sFilePath = GenSingerPic(sName, sFilePath, Stamps[iCur], sDisplay);
                        }
                    }

                    if (File.Exists(sFilePath))
                    {
                        object objRange = range.Paragraphs[i].Range;

                        //int iCount = 0;
                        //while (range.Paragraphs[1].Range.Text != "\r\a")
                        //{
                        //    range.Paragraphs[i].Range.Font.Color = WdColor.wdColorWhite;
                        //    //if (iCount++ >= range.Paragraphs.Count) break;
                        //}

                        m_doc.Shapes.AddPicture(sFilePath,
                                                ref Link2File,
                                                ref SaveWithDoc,
                                                ref Left, ref Top,
                                                ref Width, ref Height,
                                                ref objRange);
                        File.Delete(sFilePath);
                        iCur++;
                    }
                    range.Paragraphs[i].Range.Font.Color = WdColor.wdColorWhite;
                }
                catch {
                    range.Paragraphs[i].Range.Font.Color = WdColor.wdColorWhite;
                    continue;
                }
            }
        }
        public void BatchAddPicture(string sProcess, string sTemplate, EntityBase entity)
        {
            if (!ChkSingerFolder()) return;
            XmlDocument doc = new XmlDocument();
            if (sProcess.Equals("程序文件")){
                doc.Load(HttpContext.Current.Server.MapPath(@"~\template\SingerCfgProcess.xml"));
            } else {
                doc.Load(HttpContext.Current.Server.MapPath(@"~\template\SingerCfg.xml"));
            }

            #region 处理签名图片缩放比例
            /**********************处理签名图片缩放比例 START******************************/
            XmlNode rootNode = doc.SelectSingleNode("/Signer");
            double fLenRatio = 0.0;
            double fWidRatio = 0.0;
            if (rootNode.Attributes.Count != 0)
            {
                string sRatio = rootNode.Attributes["Ratio"].Value;
                string[] arrRatio = sRatio.Split(':');

                if (arrRatio != null && arrRatio.Length == 2)
                {
                    if (!Double.TryParse(arrRatio[0], out fLenRatio))
                    {
                        fLenRatio = 0;
                    }
                    if (!Double.TryParse(arrRatio[1], out fWidRatio))
                    {
                        fWidRatio = 0;
                    }
                }
            }
            /**********************处理签名图片缩放比例 END*********************************/
            #endregion

            //XmlNode sNode = doc.SelectSingleNode("/Signer/Process[@Name='" + sProcess + "']/Template[@Name='" + sTemplate + "']");
            //sNode.AppendChild(
            XmlNodeList nodes = doc.SelectNodes("/Signer/Process[@Name='" + sProcess + "']/Template[@Name='" + sTemplate + "']");
            if (nodes == null) return;

            DataTable dtStepComleted = B_FormsData.GetStepInfo(entity.ProcessID, entity.ReceiveDateTime);

            for (int i = 0; i < nodes.Count; i++)
            {
                for (int j = 0; j < nodes[i].ChildNodes.Count; j++)
                {
                    try
                    {
                        XmlNode node = nodes[i].ChildNodes[j];
                        //string skey = node.Attributes["Name"].Value;
                        //string sFileName = HttpContext.Current.Server.MapPath(@"~\template\Singer\" + skey + ".png");
                        CRect rect = new CRect();
                        if (node.Attributes["Left"] != null)
                            rect.Left = Convert.ToInt32((string.IsNullOrEmpty(node.Attributes["Left"].Value) ? "0" : node.Attributes["Left"].Value));
                        if (node.Attributes["Top"] != null)
                            rect.Top = Convert.ToInt32((string.IsNullOrEmpty(node.Attributes["Top"].Value) ? "0" : node.Attributes["Top"].Value));
                        if (node.Attributes["Width"] != null)
                            rect.Width = Convert.ToInt32((string.IsNullOrEmpty(node.Attributes["Width"].Value) ? "0" : node.Attributes["Width"].Value));
                        if (node.Attributes["Height"] != null)
                            rect.Height = Convert.ToInt32((string.IsNullOrEmpty(node.Attributes["Height"].Value) ? "0" : node.Attributes["Height"].Value));
                        string[] sParams = node.InnerText.Split('|');
                        if (sParams.Length != 2) return;

                        #region Display属性处理
                        string sDisplay = "";
                        if (node.Attributes["Display"] != null)
                        {
                            sDisplay = node.Attributes["Display"].Value.ToLower();
                        }
                        #endregion
                        string sTimeStamp = "";
                        string sUserID = "";

                        #region StampName属性处理
                        /*
                        if (node.Attributes["StampName"] != null)
                        {
                            string[] result = node.Attributes[4].Value.Split(new char[] { ';', ',' });

                            //string value = node.Attributes[4].Value;
                            string value = "";
                            try
                            {
                                value = entity.GetVal(result[0]).ToString();
                            }
                            catch
                            {
                                word.AddPicture(rect, sParams, "", fLenRatio, fWidRatio, sDisplay, sUserID);
                                continue;
                            }
                            if (string.IsNullOrEmpty(value))
                            {
                                if (result.Length == 2 &&
                                    (entity.GetVal(result[1]).GetType().Name == "DateTime"
                                    || entity.GetVal(result[1]).GetType().Name == "String")
                                   )
                                {
                                    sTimeStamp = entity.GetVal(result[1]).ToString();
                                    DateTime dt = Convert.ToDateTime(sTimeStamp);
                                    if (dt == DateTime.MinValue)
                                        sTimeStamp = "";
                                }
                            }
                            else
                            {
                                if (entity.GetVal(result[0]).GetType().Name == "DateTime"
                                    || entity.GetVal(result[0]).GetType().Name == "String")
                                {
                                    sTimeStamp = entity.GetVal(result[0]).ToString();
                                    if (result[0] == "niGaoRenDate")
                                    {
                                        string[] res = sTimeStamp.Split(' ');
                                        if (res.Length > 2)
                                            sTimeStamp = res[1] + ' ' + res[2];
                                        else
                                            sTimeStamp = "";
                                    }
                                    //if (result[0] == "huiqianDates")
                                    //{
                                    //    string[] res = sTimeStamp.Split(' ');
                                    //    if (res.Length > 2)
                                    //        sTimeStamp = res[1] + ' ' + res[2];
                                    //    else
                                    //        sTimeStamp = "";
                                    //}
                                    DateTime dt = Convert.ToDateTime(sTimeStamp);
                                    if (dt == DateTime.MinValue)
                                        sTimeStamp = "";
                                }
                            }
                            #region 忽略
                            ////renjinquan+ 针对函件发文时间格式异常做的处理('姓名 日期 时间'),去掉姓名
                            //if (ProcessConstString.TemplateName.LETTER_SEND.Contains(this.UCTemplateName) &&
                            //    (result[0].Equals("niGaoRenDate", StringComparison.CurrentCultureIgnoreCase) ||
                            //    result[0].Equals("huiqianDates", StringComparison.CurrentCultureIgnoreCase)))
                            //{
                            //    //会签时可能有多个人
                            //    foreach (string str in value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                            //    {
                            //        if (str.Split(' ').Length > 2)
                            //        {
                            //            sTimeStamp = str.Substring(str.IndexOf(' ') + 1);
                            //        }
                            //        word.AddPicture(rect, sParams, sTimeStamp);

                            //    }
                            //    continue;
                            //}

                            //}
                            //else if (this.UCTemplateName == ProcessConstString.TemplateName.COMPANY_SEND && node.InnerText.Contains("会签"))
                            //{
                            //    string[] results = FormsMethod.GetSingers4Print(entity.ProcessID, entity.WorkItemID, "部门会签", "公司发文").Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                            //    for (int k = 1; k < results.Length; k += 2)
                            //    {
                            //        word.AddPicture(rect, sParams, results[k]);
                            //    }
                            //    continue;
                            //}
                            #endregion

                        }
                        */
                        #endregion

                        #region Step属性节点处理
                        DataRow[] rowsStamp = null;

                        if (node.Attributes["Step"] != null)
                        {
                            string[] sResult = node.Attributes["Step"].Value.Split(':');
                            string sDateFlag = ""; // 较早 较晚
                            if (sResult != null && sResult.Length == 2) //sResult[0] 步骤 sResult[1] 较早/较晚
                            {
                                #region 多人会签/多人核稿 签名图片处理
                                /********多人会签/多人核稿 签名图片处理 START********/
                                /*
                                    党纪工团发文
                                        党委公文首页纸模板:
                                            会签
                                        工会首页纸
                                            会签
                                        共青团首页纸
                                            会签
                                        纪律检查委员会首页纸
                                            会签
                                    公司发文
                                        公文首页纸
                                            会签、核稿
                                    函件发文
                                        函件发文表单
                                            会签
                                 */
                                if (IsMultiSigners(sProcess, sTemplate, sParams,
                                                    sParams[0], rect, entity,
                                                    fLenRatio, fWidRatio, sDisplay))
                                {
                                    continue;
                                }
                                /*******多人会签/多人核稿 签名图片处理 END***********/
                                #endregion
                                if (sParams[1].ToLower() == "downs")
                                {
                                    if (sResult[1] == "较早")
                                        sDateFlag = "COMPLETED_DATE ASC";
                                    if (sResult[1] == "较晚")
                                        sDateFlag = "COMPLETED_DATE DESC";
                                    rowsStamp = dtStepComleted.Select("NAME='" + sResult[0] + "' and  COMPLETED_DATE IS NOT NULL", sDateFlag);
                                    if (rowsStamp != null && rowsStamp.Length > 0)
                                    {
                                        for (int n = 0; n < rowsStamp.Length; n++)
                                        {
                                            sTimeStamp += rowsStamp[n]["COMPLETED_DATE"].ToString() + "\n";
                                            sUserID += rowsStamp[n]["USER_ID"].ToString() + "\n";
                                        }
                                    }
                                }
                                else
                                {
                                    if (sResult[1] == "较早")
                                        sDateFlag = "COMPLETED_DATE ASC";
                                    if (sResult[1] == "较晚")
                                        sDateFlag = "COMPLETED_DATE DESC";
                                    rowsStamp = dtStepComleted.Select("NAME='" + sResult[0] + "' and  COMPLETED_DATE IS NOT NULL", sDateFlag);
                                    if (rowsStamp != null && rowsStamp.Length > 0)
                                    {
                                        sTimeStamp = rowsStamp[0]["COMPLETED_DATE"].ToString();
                                        sUserID = rowsStamp[0]["USER_ID"].ToString();
                                    }
                                }
                            }
                        }
                        #endregion

                        word.AddPicture(rect, sParams, sTimeStamp, fLenRatio, fWidRatio, sDisplay, sUserID);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            // 清除签名图片所在的临时目录下的文件
            //ClearFileListTmpDirectory(@"~\template\Singer\");
        }
        /// <summary>
        /// 党纪工团发文	
        ///    党委公文首页纸模板:
        ///        会签:
        ///    工会首页纸
        ///        会签:
        ///    共青团首页纸
        ///        会签:
        ///    纪律检查委员会首页纸
        ///        会签:
        /// 公司发文
        ///    公文首页纸
        ///        会签:核稿:
        /// 函件发文
        ///    函件发文表单
        ///        会签:
        /// </summary>
        /// <param name="sProcess"></param>
        /// <param name="sTemplate"></param>
        /// <param name="sNodeName"></param>
        /// <returns>如果待签名图片在如上流程模板的节点中出现则返回TRUE,否则返回FALSE</returns>
        private bool IsMultiSigners(string sProcess, string sTemplate, string[] sParams,
            string sNodeName, CRect rect, EntityBase entity,
            double fLenRatio, double fWidRatio, string sDisplay)
        {
            bool bRet = false;
            DataTable dt = null; //new DataTable();
            Dictionary<string, string> dictSigners = new Dictionary<string, string>();
            switch (sProcess)
            {
                case "党纪工团发文":
                    if ((sTemplate == "党委公文首页纸模板" ||
                        sTemplate == "工会首页纸" ||
                        sTemplate == "共青团首页纸" ||
                        sTemplate == "纪律检查委员会首页纸") && sNodeName == "会签:")
                    {
                        bRet = true;

                        //string DetpSigners = FormsMethod.GetSingers4Print(entity.ProcessID, entity.WorkItemID, "部门会签", "党纪工团发文");
                        //string[] results = DetpSigners.Split(new char[] { '[', ']', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //string Stamp = "";
                        //for (int k = 1; k < results.Length; k += 3)
                        //{
                        //    Stamp += (results[k] + " " + results[k + 1] + "\n");
                        //}
                        dt = B_FormsData.GetStepInfo(entity.ProcessID, entity.ReceiveDateTime);
                        DataRow[] rows = dt.Select("NAME = '部门会签'  and  COMPLETED_DATE IS NOT NULL", "COMPLETED_DATE DESC");
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (!dictSigners.ContainsKey(rows[i]["USER_ID"].ToString()))
                            {
                                dictSigners.Add(rows[i]["USER_ID"].ToString(), rows[i]["COMPLETED_DATE"].ToString());
                                word.AddPicture(rect, sParams, rows[i]["COMPLETED_DATE"].ToString(), fLenRatio, fWidRatio, sDisplay, rows[i]["USER_ID"].ToString());
                            }
                        }
                    }
                    break;
                case "公司发文":
                    if (sTemplate == "公文首页纸")
                    {

                        //string[] results = DetpSigners.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        //string sVerify = (string.IsNullOrEmpty(entity.GetVal("ZhuRenSigner").ToString()) ? "" : entity.GetVal("ZhuRenSigner").ToString() + " " + ucPrint.CheckDateTime(entity.GetVal("ZhuRenSignDate").ToString()) + "\r\n");
                        //string sCVerify = (string.IsNullOrEmpty(entity.GetVal("Verifier").ToString()) ? "" : entity.GetVal("Verifier").ToString() + " " + ucPrint.CheckDateTime(entity.GetVal("VerifyDate").ToString()));
                        if (sNodeName == "会签:")
                        {
                            bRet = true;
                            //string DetpSigners = FormsMethod.GetSingers4Print(entity.ProcessID, entity.WorkItemID, "部门会签", "公司发文");
                            //string[] result = DetpSigners.Split(new char[] { '[', ']', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            //string Stamp = "";
                            //for (int k = 1; k < result.Length; k += 3)
                            //{
                            //    Stamp += result[k] + " " + result[k + 1] + "\n";
                            //}
                            dt = B_FormsData.GetStepInfo(entity.ProcessID, entity.ReceiveDateTime);
                            DataRow[] rows = dt.Select("NAME = '部门会签'  and  COMPLETED_DATE IS NOT NULL", "COMPLETED_DATE DESC");
                            for (int i = 0; i < rows.Length; i++)
                            {
                                if (!dictSigners.ContainsKey(rows[i]["USER_ID"].ToString()))
                                {
                                    dictSigners.Add(rows[i]["USER_ID"].ToString(), rows[i]["COMPLETED_DATE"].ToString());
                                    word.AddPicture(rect, sParams, rows[i]["COMPLETED_DATE"].ToString(), fLenRatio, fWidRatio, sDisplay, rows[i]["USER_ID"].ToString());
                                }
                            }
                        }

                        if (sNodeName == "核稿:")
                        {
                            bRet = true;
                            //string value = "";
                            //if (!(entity.GetVal("ZhuRenSignDate").ToString() == "" || entity.GetVal("ZhuRenSignDate").ToString() == DateTime.MinValue.ToString()))
                            //{
                            //    value = entity.GetVal("ZhuRenSignDate").ToString() + "\n";
                            //}
                            //if (!(entity.GetVal("VerifyDate").ToString() == "" || entity.GetVal("VerifyDate").ToString() == DateTime.MinValue.ToString()))
                            //{
                            //    value += entity.GetVal("VerifyDate").ToString() + "\n";
                            //}
                            //word.AddPicture(rect, sParams, value, fLenRatio, fWidRatio, sDisplay, sUserID);
                            dt = B_FormsData.GetStepInfo(entity.ProcessID, entity.ReceiveDateTime);
                            DataRow[] rows = dt.Select("NAME = '主任核稿'  and  COMPLETED_DATE IS NOT NULL", "COMPLETED_DATE DESC");
                            DataRow[] rows1 = dt.Select("NAME = '核稿'  and  COMPLETED_DATE IS NOT NULL", "COMPLETED_DATE DESC");
                            for (int i = 0; i < rows.Length; i++)
                            {
                                if (!dictSigners.ContainsKey(rows[i]["USER_ID"].ToString()))
                                {
                                    dictSigners.Add(rows[i]["USER_ID"].ToString(), rows[i]["COMPLETED_DATE"].ToString());
                                    word.AddPicture(rect, sParams, rows[i]["COMPLETED_DATE"].ToString(), fLenRatio, fWidRatio, sDisplay, rows[i]["USER_ID"].ToString());
                                }
                            }
                            if (rows1.Length != null && rows1.Length > 0)
                                word.AddPicture(rect, sParams, rows1[0]["COMPLETED_DATE"].ToString(), fLenRatio, fWidRatio, sDisplay, rows1[0]["USER_ID"].ToString());
                        }
                    }
                    break;
                case "函件发文":
                    if (sTemplate == "函件发文表单" && sNodeName == "会签/日期:")
                    {
                        bRet = true;
                        //string sTimeStamp = entity.GetVal("huiqianDates").ToString();

                        //string[] res = sTimeStamp.Split(new char[] { ' ', ';' });
                        //string Stamp = "";
                        //for (int k = 1; k < res.Length; k += 3)
                        //{
                        //    Stamp += res[k] + " " + res[k + 1] + "\n";
                        //}
                        //word.AddPicture(rect, sParams, Stamp, fLenRatio, fWidRatio, sDisplay, sUserID);

                        dt = B_FormsData.GetStepInfo(entity.ProcessID, entity.ReceiveDateTime);
                        DataRow[] rows = dt.Select("NAME = '会签'  and  COMPLETED_DATE IS NOT NULL", "COMPLETED_DATE DESC");
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (!dictSigners.ContainsKey(rows[i]["USER_ID"].ToString()))
                            {
                                dictSigners.Add(rows[i]["USER_ID"].ToString(), rows[i]["COMPLETED_DATE"].ToString());
                                word.AddPicture(rect, sParams, rows[i]["COMPLETED_DATE"].ToString(), fLenRatio, fWidRatio, sDisplay, rows[i]["USER_ID"].ToString());
                            }
                        }
                    }
                    break;
            }
            return bRet;
        }