Exemplo n.º 1
0
        public ActionResult btnOutputWord_Click(int record_id)
        {
            // 关闭本窗体(触发窗体的关闭事件)
            //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            try
            {
                var    record  = db.view_record2word.Find(record_id);
                string dotName = record.bg_dot_name;
                if (dotName.Equals(""))
                {
                    dotName = "xcbl.dot";
                }
                string path = Server.MapPath("~/pbs_data/");
                NameValueCollection val1 = (NameValueCollection)ConfigurationManager.GetSection("myUrl");
                if (System.IO.File.Exists(path + "\\" + record.record_no + ".doc"))
                {
                    return(Redirect(val1["apiUrl"] + "GetWordFile?fileName=" + record.record_no + ".doc"));
                }
                CCWordApp word = new CCWordApp();
                word.OpenFromDot(Server.MapPath("~/App_Data/") + dotName);

                word.GotoBookMark("kyyear");
                word.InsertText(record.ky_date.Value.Year.ToString());

                word.GotoBookMark("ky_no");
                word.InsertText(record.record_no.Substring(record.record_no.Count() - 6));

                word.GotoBookMark("ky_unit");
                word.SetFont("Underlined");
                word.InsertText(record.unit_full_name);
                word.SetFont("Underlined");

                word.GotoBookMark("kyyear2");
                word.InsertText(record.ky_date.Value.Year.ToString());

                word.GotoBookMark("ky_no2");
                word.InsertText(record.record_no.Substring(record.record_no.Count() - 6));

                word.GotoBookMark("ky_unit2");
                word.InsertText(record.ky_unit_name);

                word.GotoBookMark("bg_unit");
                word.InsertText(record.bg_unit_name);


                word.GotoBookMark("ky_date");
                word.InsertText(record.ky_date.Value.ToString("yyyy"));
                word.GotoBookMark("ky_date_month");
                word.InsertText(record.ky_date.Value.ToString("MM"));
                word.GotoBookMark("ky_date_dd");
                word.InsertText(record.ky_date.Value.ToString("dd"));
                word.GotoBookMark("ky_date_hh");
                word.InsertText(record.ky_date.Value.ToString("hh"));
                word.GotoBookMark("ky_date_mm");
                word.InsertText(record.ky_date.Value.ToString("mm"));

                word.GotoBookMark("record_reason");
                string reason = record.record_reason;
                if (reason == null)
                {
                    reason = "";
                }
                reason = reason.PadRight(340 - reason.ToCharArray().Length);

                word.InsertText(reason);

                word.GotoBookMark("kykssj");
                word.InsertText(record.kyks_time.Value.ToString("yyyy"));
                word.GotoBookMark("kykssj_month");
                word.InsertText(record.kyks_time.Value.ToString("MM"));
                word.GotoBookMark("kykssj_dd");
                word.InsertText(record.kyks_time.Value.ToString("dd"));
                word.GotoBookMark("kykssj_hh");
                word.InsertText(record.kyks_time.Value.ToString("hh"));
                word.GotoBookMark("kykssj_mm");
                word.InsertText(record.kyks_time.Value.ToString("mm"));

                word.GotoBookMark("kyjssj");
                word.InsertText(record.kyjs_time.Value.ToString("yyyy"));
                word.GotoBookMark("kyjssj_month");
                word.InsertText(record.kyjs_time.Value.ToString("MM"));
                word.GotoBookMark("kyjssj_dd");
                word.InsertText(record.kyjs_time.Value.ToString("dd"));
                word.GotoBookMark("kyjssj_hh");
                word.InsertText(record.kyjs_time.Value.ToString("hh"));
                word.GotoBookMark("kyjssj_mm");
                word.InsertText(record.kyjs_time.Value.ToString("mm"));


                word.GotoBookMark("xc_loc");
                string loc = "";
                if (record.xc_loc == null)
                {
                    loc = record.fs_loc;
                }
                else
                {
                    loc = record.fs_loc + record.xc_loc;
                }
                loc = loc.PadRight(190 - loc.ToCharArray().Length);

                word.InsertText(loc);

                word.GotoBookMark("bh_flag");
                if (record.bh_flag == null)
                {
                    word.InsertText("无");
                }
                else
                {
                    if (record.bh_flag.Value == 1)
                    {
                        word.InsertText("有");
                    }
                    else
                    {
                        word.InsertText("无");
                    }
                }


                word.GotoBookMark("bhr");
                word.InsertText(record.bhr_name);

                word.GotoBookMark("bhr_unit");
                word.InsertText(record.bhr_unit_name);

                word.GotoBookMark("bhr_pos");
                word.InsertText(record.bhr_pos);

                //保护方式
                if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("专"))
                {
                    word.GotoBookMark("bh_function_flag1");
                    word.replaceText("□", "☑");
                }
                else if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("设"))
                {
                    word.GotoBookMark("bh_function_flag2");
                    word.replaceText("□", "☑");
                }
                else if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("封"))
                {
                    word.GotoBookMark("bh_function_flag3");
                    word.replaceText("□", "☑");
                    word.GotoBookMark("bhr_function");
                    word.InsertText(record.bh_function);
                }
                //现场情况
                if (record.xc_info != null && record.xc_info.Length > 1 && record.xc_info.Substring(0, 2).Equals("原始"))
                {
                    word.GotoBookMark("xc_info_flag1");
                    word.replaceText("□", "☑");
                }
                else if (record.xc_info != null && record.xc_info.Length > 1 && record.xc_info.Substring(0, 2).Equals("变动"))
                {
                    word.GotoBookMark("xc_info_flag2");
                    word.replaceText("□", "☑");
                }
                //变动原因
                if (record.bd_reason != null && record.bd_reason.Length > 1 && record.bd_reason.Substring(0, 2).Equals("事主"))
                {
                    word.GotoBookMark("bd_reason_flag1");
                    word.replaceText("□", "☑");
                }
                else if (record.bd_reason != null && record.bd_reason.Length > 1 && record.bd_reason.Substring(0, 2).Equals("报案"))
                {
                    word.GotoBookMark("bd_reason_flag2");
                    word.replaceText("□", "☑");
                }
                else if (record.bd_reason != null && !record.bd_reason.Equals(""))
                {
                    word.GotoBookMark("bd_reason_flag3");
                    word.replaceText("□", "☑");
                    word.GotoBookMark("bd_reason");
                    word.InsertText(record.bd_reason);
                }

                //天气
                switch (record.weather_info)
                {
                case "阴":
                    word.GotoBookMark("tq_flag1");
                    word.replaceText("□", "☑");
                    break;

                case "晴":
                    word.GotoBookMark("tq_flag2");
                    word.replaceText("□", "☑");
                    break;

                case "雨":
                    word.GotoBookMark("tq_flag3");
                    word.replaceText("□", "☑");
                    break;

                case "雪":
                    word.GotoBookMark("tq_flag4");
                    word.replaceText("□", "☑");
                    break;

                case "雾":
                    word.GotoBookMark("tq_flag5");
                    word.replaceText("□", "☑");
                    break;
                }
                word.GotoBookMark("wd");
                word.InsertText(record.temper_info);

                word.GotoBookMark("sd");
                word.InsertText(record.humidity_info);

                word.GotoBookMark("fx");
                word.InsertText(record.trend_info);

                //光照
                if (record.light_info != null && record.light_info.Contains("自然光"))
                {
                    word.GotoBookMark("light_flag1");
                    word.replaceText("□", "☑");
                }
                if (record.light_info != null && record.light_info.Contains("灯光"))
                {
                    word.GotoBookMark("light_flag2");
                    word.replaceText("□", "☑");
                }
                if (record.light_info != null && record.light_info.Contains("特种光"))
                {
                    word.GotoBookMark("light_flag3");
                    word.replaceText("□", "☑");
                }

                word.GotoBookMark("zhr");
                word.InsertText(record.zhr_name);

                word.GotoBookMark("zhr_unit");
                word.InsertText(record.zhr_unit_name);

                word.GotoBookMark("zhr_pos");
                word.InsertText(record.zhr_pos);

                word.GotoBookMark("xc_disp");
                word.InsertText(record.xc_disp.PadRight(1400));

                word.GotoBookMark("blr");
                string blr = record.blr_name;
                if (blr == null)
                {
                    blr = "";
                }
                word.InsertText(blr.PadRight(70));

                word.GotoBookMark("ztr");
                string ztr = record.ztr_name;
                if (ztr == null)
                {
                    ztr = "";
                }
                word.InsertText(ztr.PadRight(70));

                word.GotoBookMark("zxr");
                string zxr = record.zxr_name;
                if (zxr == null)
                {
                    zxr = "";
                }
                word.InsertText(zxr.PadRight(70));

                word.GotoBookMark("lxr");
                string lxr = record.lxr_name;
                if (lxr == null)
                {
                    lxr = "";
                }
                word.InsertText(lxr.PadRight(70));

                word.GotoBookMark("lyr");
                string lyr = record.lyr_name;
                if (lyr == null)
                {
                    lyr = "";
                }
                word.InsertText(lyr.PadRight(70));

                word.GotoBookMark("jzrsex");
                word.InsertText(record.jzr_sex);

                word.GotoBookMark("jzrbirth");
                word.InsertText(record.jzr_birth);

                word.GotoBookMark("jzraddress");
                word.InsertText(record.jzr_address);

                word.GotoBookMark("jzrqm");
                System.Drawing.Image qmImg = System.Drawing.Image.FromFile(path + record.uuid + "\\" + record.uuid + ".png");
                qmImg = UtilsTool.RotateImg(qmImg, -90);
                string rotatePath = path + "tmp\\" + record.uuid + "_tmp.png";
                qmImg.Save(rotatePath);
                word.InsertPictureStatic(rotatePath, 100, 100);
                word.GotoBookMark("jzrqm2");
                word.InsertPictureStatic(rotatePath, 100, 100);

                word.GotoBookMark("bg_date1_year");
                word.InsertText(UtilsTool.NumtoUpper(DateTime.Now.Year % 10));
                word.GotoBookMark("bg_date1_month");
                word.InsertText(UtilsTool.MonthtoUpper(DateTime.Now.Month));
                word.GotoBookMark("bg_date1_day");
                word.InsertText(UtilsTool.DaytoUpper(DateTime.Now.Day));

                word.GotoBookMark("bg_date2_year");
                word.InsertText(UtilsTool.NumtoUpper(DateTime.Now.Year % 10));
                word.GotoBookMark("bg_date2_month");
                word.InsertText(UtilsTool.MonthtoUpper(DateTime.Now.Month));
                word.GotoBookMark("bg_date2_day");
                word.InsertText(UtilsTool.DaytoUpper(DateTime.Now.Day));

                word.GotoBookMark("photos");

                int i      = 1;
                var pics   = db.sys_upload_file.Where(m => m.rec_uuid.Equals(record.uuid));
                var ztpics = pics.Where(m => m.file_type == 2004);
                int ztnum  = ztpics.Count();
                word.GotoBookMark("zt_num");
                word.InsertText("" + ztnum);

                foreach (sys_upload_file pic in ztpics)
                {
                    if (ValidateFileType(pic.file_url))
                    {
                        word.GotoBookMark("photo" + (i++).ToString());
                        word.InsertLineBreak(14);
                        word.InsertPicture(Server.MapPath("~/App_Data/") + "blank.png", 10, 10);//矫正后续图片位置
                        string   bgFilePath      = Server.MapPath("~/App_Data/") + "xct_bg.jpg";
                        Bitmap   bmp             = new Bitmap(bgFilePath);
                        Graphics g               = Graphics.FromImage(bmp);
                        Font     titlefont       = new Font("宋体", 65);
                        Font     contentfont     = new Font("宋体", 40);
                        Font     minicontentfont = new Font("宋体", 30);

                        SolidBrush sbrush   = new SolidBrush(Color.Black);
                        string     title    = record.af_time.Value.ToString("yyyyMMdd") + " " + record.fs_loc + record.xc_loc + record.xz;
                        string     markHint = "";
                        if (pic.file_url.Substring(pic.file_url.Length - 8).Equals("xct.jpeg"))
                        {
                            title   += "中心现场方位示意图";
                            markHint = "中心现场";
                        }
                        else if (pic.file_url.Substring(pic.file_url.Length - 8).Equals("pmt.jpeg"))
                        {
                            title   += "中心现场方位示意图";
                            markHint = "案发位置";
                        }

                        g.DrawString(title, titlefont, sbrush, new PointF(300, 200));
                        g.DrawString(markHint, titlefont, sbrush, new PointF(2600, 1150));

                        if (record.xc_loc.Length > 12)
                        {
                            g.DrawString(record.xc_loc.Substring(0, 12), minicontentfont, sbrush, new PointF(2600, 1770));
                            g.DrawString(record.xc_loc.Substring(12), minicontentfont, sbrush, new PointF(2600, 1830));
                        }
                        else
                        {
                            g.DrawString(record.xc_loc, contentfont, sbrush, new PointF(2600, 1800));
                        }

                        g.DrawString(record.bj_time.Value.ToString("yyyy年MM月dd日 HH时mm分"), contentfont, sbrush, new PointF(2600, 1900));
                        //g.DrawString(record.unit_full_name, contentfont, sbrush, new PointF(2600, 2030));
                        if (record.unit_full_name.Length > 12)
                        {
                            g.DrawString(record.unit_full_name.Substring(0, 12), minicontentfont, sbrush, new PointF(2600, 2000));
                            g.DrawString(record.unit_full_name.Substring(12), minicontentfont, sbrush, new PointF(2600, 2060));
                        }
                        else
                        {
                            g.DrawString(record.unit_full_name, contentfont, sbrush, new PointF(2600, 2030));
                        }

                        g.DrawString(record.ztr_name, contentfont, sbrush, new PointF(2600, 2150));
                        g.DrawString(DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分"), contentfont, sbrush, new PointF(2600, 2270));

                        System.Drawing.Image mapImg = System.Drawing.Image.FromFile(path + record.uuid + "\\" + pic.file_url);

                        g.DrawImage(mapImg, 100, 400, 2100, 1600);
                        //bmp.Save(path + record.uuid + "\\tmp_" + pic.file_url);

                        System.Drawing.Image img    = UtilsTool.RotateImg(bmp, -90); //旋转90度
                        RectSize             target = UtilsTool.getCTSize(img);
                        img.Save(path + record.uuid + "\\tmp_" + pic.file_url);
                        word.InsertPicture(path + record.uuid + "\\tmp_" + pic.file_url, target.width, target.height);
                        word.InsertLineBreak();
                        //word.SetAlignment("Center");
                        //word.InsertText(pic.file_hint);
                        //word.InsertPagebreak();
                    }
                }

                var fwpics   = pics.Where(m => m.file_type == 2001 || m.file_type == 2002 || m.file_type == 2003).OrderBy(m => m.file_type);
                int photonum = fwpics.Count();
                word.GotoBookMark("photo_num");
                word.InsertText("" + photonum);

                foreach (sys_upload_file pic in fwpics)
                {
                    if (ValidateFileType(pic.file_url))
                    {
                        word.GotoBookMark("photo" + (i++).ToString());
                        word.InsertLineBreak(6);
                        word.InsertPicture(Server.MapPath("~/App_Data/") + "blank.png", 10, 10);//矫正后续图片位置
                        System.Drawing.Image img    = System.Drawing.Image.FromFile(path + record.uuid + "\\" + pic.file_url);
                        RectSize             target = UtilsTool.getConfSize(img);
                        word.InsertPicture(path + record.uuid + "\\" + pic.file_url, target.width, target.height);
                        word.InsertLineBreak();
                        word.SetAlignment("Center");
                        word.InsertText(pic.file_hint);
                    }
                }

                string newFile = path + record.record_no + ".doc";
                word.SaveAs(newFile);
                word.Close();
                word.Quit();

                return(Redirect(val1["apiUrl"] + "GetWordFile?fileName=" + record.record_no + ".doc"));
            }
            catch (Exception exc)
            {
                throw (exc);
            }

            //return UIHelper.Result();
        }
Exemplo n.º 2
0
        protected void btnCartaOrion_Click(object sender, EventArgs e)
        {
            if (Gravar())
            {
                load();
                DateTime dated;
                dated = DateTime.Now;
                CCWordApp DocWord = new CCWordApp();

                try
                {
                    CultureInfo        culture = new CultureInfo("pt-BR");
                    DateTimeFormatInfo dtfi    = culture.DateTimeFormat;

                    int    dia       = DateTime.Now.Day;
                    int    ano       = DateTime.Now.Year;
                    string mes       = culture.TextInfo.ToTitleCase(dtfi.GetMonthName(DateTime.Now.Month));
                    string diasemana = culture.TextInfo.ToTitleCase(dtfi.GetDayName(DateTime.Now.DayOfWeek));
                    string data      = diasemana + ", " + dia + " de " + mes + " de " + ano;

                    CNumeroPorExtenso ValorExtenso = new CNumeroPorExtenso();
                    ValorExtenso.SetNumero(Convert.ToDecimal(txtValorNota.Text.Replace(".", ",")));

                    #region Numerar documento
                    string cmpconumeracaodocumento = "";
                    tblNumeracaoDocumento tbl      = new tblNumeracaoDocumento();
                    if (string.IsNullOrEmpty(txtNumeroDoc.Text))
                    {
                        tbl.cmpCoNumeracaoDocumento = "0";
                        tbl.cmpCoFuncionario        = "47"; //Departamento Faturamento
                        tbl.cmpCoObra          = "23";      //Escritório GrupoOrion
                        tbl.cmpIdObraFatura    = ViewState["cmpIdObraFatura"].ToString();
                        tbl.cmpCoTipoNumeracao = ViewState["cmpCoTipoNumeracao"].ToString();
                        tbl.cmpTxObservacoes   = "Carta de entrega de NF " + txtNuNotaFiscal.Text.ToString() + " R$ " + txtValorNota.Text.ToString() +
                                                 " referente a " + ViewState["cmpNuMesFatura"].ToString() + "/" + ViewState["cmpNuAnoFatura"].ToString() +
                                                 " " + lblNomeObra.Text.ToString();
                        tbl.cmpDcDocumento = "";
                        tbl.cmpNoUsuario   = ((HzLibGeneral.Util.HzLogin)Session["login"]).cmpNoUsuario.TrimEnd();
                        txtNumeroDoc.Text  = tbl.Save(Global.GetConnection(), ref cmpconumeracaodocumento);
                    }
                    #endregion

                    DocWord.Open(ConfigurationManager.AppSettings["WordMod"] + "Modelo de Carta Orion.dot");

                    DocWord.GotoBookMark("Numero_Doc");
                    DocWord.SetAlignment("Right");
                    DocWord.InsertText(txtNumeroDoc.Text.ToString());
                    DocWord.SetFont("nothing");

                    DocWord.GotoBookMark("Data_Carta");
                    DocWord.SetAlignment("Right");
                    DocWord.InsertText(data);
                    DocWord.SetFont("nothing");

                    string NomeDestinatario = "";
                    if (!string.IsNullOrEmpty(txtNomeDestinatario.Text))
                    {
                        NomeDestinatario = "Ilmo(a). Sr(a). " + txtNomeDestinatario.Text;
                    }

                    DocWord.GotoBookMark("Nome_Destino");
                    DocWord.SetFont("Bold");
                    DocWord.InsertText(NomeDestinatario);
                    DocWord.SetFont("nothing");

                    DocWord.GotoBookMark("Nome_Orgao");
                    DocWord.InsertText(txtNomeOrgao.Text);
                    DocWord.SetFont("nothing");

                    DocWord.GotoBookMark("Data_Inicial");
                    DocWord.InsertText(txtDataInicial.Text);

                    DocWord.GotoBookMark("Data_Final");
                    DocWord.InsertText(txtDataFinal.Text);

                    DocWord.GotoBookMark("Numero_Contrato");
                    DocWord.InsertText(ViewState["cmpNuContrato"].ToString().TrimEnd());

                    DocWord.GotoBookMark("Data_Emissao_Nota");
                    DocWord.InsertText(txtEmissaoNota.Text.ToString());

                    DocWord.GotoBookMark("Tipo_Servico");
                    DocWord.InsertText(txtNomeServico.Text.ToString());

                    DocWord.GotoBookMark("Numero_Nota");
                    DocWord.InsertText(txtNuNotaFiscal.Text);

                    DocWord.GotoBookMark("Valor_Nota");
                    string ValorNota = txtValorNota.Text.Replace(".", "");
                    DocWord.InsertText(Convert.ToDecimal(ValorNota).ToString("#,##0.00"));

                    DocWord.GotoBookMark("Valor_NotaExtenso");
                    DocWord.InsertText(ValorExtenso.ToString());

                    ArrayList list = new ArrayList();
                    list.Add("Anexo1");
                    list.Add("Anexo2");
                    list.Add("Anexo3");
                    list.Add("Anexo4");
                    list.Add("Anexo5");
                    list.Add("Anexo6");
                    list.Add("Anexo7");
                    list.Add("Anexo8");
                    list.Add("Anexo9");
                    list.Add("Anexo10");

                    int i = 0;
                    foreach (ListItem item in lstDocAnexo.Items)
                    {
                        DocWord.GotoBookMark(list[i].ToString());
                        DocWord.InsertText("-" + item.Text);
                        i++;
                    }

                    DocWord.InsertLineBreak();

                    DocWord.SaveAs(ConfigurationManager.AppSettings["WordDoc"] + "CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc");
                    DocWord.Quit();

                    #region Grava nome do arquivo na tabela de documentos
                    if (string.IsNullOrEmpty(txtNumeroDoc.Text))
                    {
                        tbl.cmpCoNumeracaoDocumento = cmpconumeracaodocumento;
                        tbl.cmpDcDocumento          = ConfigurationManager.AppSettings["WordDoc"].ToString() + " CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc";
                        tbl.Save(Global.GetConnection(), ref cmpconumeracaodocumento);
                    }
                    #endregion

                    #region gravar data e número da carta orion
                    tblFaturaObra table = new tblFaturaObra();
                    table.cmpIdFaturaObra  = ViewState["idFaturaObra"].ToString();
                    table.cmpEdCartaoOrion = ConfigurationManager.AppSettings["WordDoc"].ToString() + " CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc";
                    table.cmpNuCartaOrion  = txtNumeroDoc.Text.ToString();
                    table.cmpNoUsuario     = ((HzLibGeneral.Util.HzLogin)Session["login"]).cmpNoUsuario.TrimEnd();
                    table.GravarCartaOrionFatura(Global.GetConnection());
                    load();
                    #endregion

                    Response.Clear();
                    Response.ContentType = "application/msword";
                    Response.AddHeader("Content-disposition", "filename=" + ConfigurationManager.AppSettings["WordDoc"] + "CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc");
                    Response.WriteFile(ConfigurationManager.AppSettings["WordDoc"] + "CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc");
                    Response.End();

                    //Response.Write("<script language='javascript'>"
                    //            + "window.open('" + Global.UrlDocWord + "CO" + txtNumeroDoc.Text.Replace("/", "-") + " " + lblNomeObra.Text.ToString() + ".doc" + "', '_blank', 'width=850, height=600, menubar=no, resizable=yes, scrollbars=yes, top=35, left=105')"
                    //            + "</script>");
                }
                catch (Exception ex)
                {
                    DocWord.Quit();
                    MsgBox.ShowMessage(ex.ToString(), "Erro");
                }
            }
        }