tijian_tieying/web/dccdc.Selfhelp/Program.cs
2025-02-20 12:14:39 +08:00

158 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Reflection;
namespace dccdc.Selfhelp
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Application.StartupPath + "\\"));
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(DateTime.Now.ToString()+"程序启动成功!");
// return;
// Application.Run(new printSuccess());
//return;
//try
//{
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new frm_ymVideo());
// return;
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message + ex.StackTrace);
//}
if (args.Length > 0)
{
if (args[0] == "-t")
{
Application.Run(new frm_TestPrinter());
}
else if (args[0] == "-q")
{
Application.Run(new frm_CodeReader());
}
else if (args[0] == "-s")
{
Application.Run(new frm_QRSetting());
}
else if (args[0] == "-yy")
{
Application.Run(new frm_SpeakConfig());
}
else if (args[0] == "-p")
{
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printDoc.DefaultPageSettings.PrinterSettings.PrinterName;
printDoc.PrintController = new StandardPrintController();
if (!printDoc.PrinterSettings.IsValid)
{
MessageBox.Show("无法连接到打印机" + printDoc.PrinterSettings.PrinterName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
PageSettings pst = new PageSettings();
printDoc.DocumentName = "测试打印";
pst.PaperSize = new PaperSize("MYA5", 617, 875);
printDoc.DefaultPageSettings = pst;
try
{
printDoc.Print();
//m_streams[m_currentPageIndex].Close();
}
catch (System.Exception ex)
{
//log4net.LogManager.GetLogger(this.GetType()).Error("打印失败:" + ex.Message);
MessageBox.Show("打印失败:" + ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
}
else
{
string banben = System.Configuration.ConfigurationManager.AppSettings["banben"];
if (string.IsNullOrEmpty(banben) || banben == "1")
{
Application.Run(new MainForm());
}
else if (banben == "2")
{
Application.Run(new frm_main3());
}
else if (banben == "3")
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(DateTime.Now.ToString()+"版本=3");
try {
Application.Run(new frm_main_ym());
}
catch(Exception ex)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(DateTime.Now.ToString() + ex.Message+ex.StackTrace);
}
}
else if (banben == "4")
{
Application.Run(new frm_main_xg());
}
else
{
Application.Run(new frm_main3());
//Application.Run(new frm_ymVideo());
}
}
}
static void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
//string basepath = AppDomain.CurrentDomain.BaseDirectory;//应用程序的路径
//basepath = basepath + (basepath.EndsWith("\\") ? "rdlctemp\\" : "\\rdlctemp\\");
//throw new NotImplementedException();
Image img = Image.FromFile(Application.StartupPath + "\\63901.tiff");
Bitmap myBitmap = new Bitmap(img);
myBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
Rectangle adjustedRect = new Rectangle(
e.PageBounds.Left - (int)(e.PageSettings.HardMarginX),
e.PageBounds.Top - (int)(e.PageSettings.HardMarginY),
e.PageBounds.Width,
e.PageBounds.Height);
//log4net.LogManager.GetLogger(this.GetType()).Info("打印机的硬件变局X:" + e.PageSettings.HardMarginX + "Y:" + e.PageSettings.HardMarginY);
//int width_heng = e.PageBounds.Width;
//int height_heng = e.PageBounds.Height;
//if (e.PageSettings.Landscape)
//{
// adjustedRect.Width = height_heng;
// adjustedRect.Height = width_heng;
//}
//pageImage.Save(basepath + DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".Emf", ImageFormat.Emf);
// 为打印图片画一个白色背景
e.Graphics.FillRectangle(Brushes.White, adjustedRect);
// 画打印图片内容
e.Graphics.DrawImage(myBitmap, adjustedRect);
//e.Graphics.DrawRectangle(Pens.Black, adjustedRect);
//pageImage = null;
//m_streams[m_currentPageIndex] = null;
//m_currentPageIndex++;
e.HasMorePages = false;
}
}
}