注塑喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

216 lines
7.5 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.Painting;
using grdesLib;
using grproLib;
namespace PaintingView
{
public partial class FrmDetail : Form
{
public FrmDetail()
{
InitializeComponent();
}
private void FrmDetail_Load(object sender, EventArgs e)
{
int a = Program.a;
Control.CheckForIllegalCrossThreadCalls = false;
Thread t = new Thread(new ThreadStart(TimeGo));
t.Start();
initList(a);
}
public void initList(int a)
{
//listView1.Items.Clear();
StockInBLL bll=new StockInBLL();
DataTable dt = null;
try
{
this.listView1.Columns.Clear();
this.listView1.Columns.Add("零件号", 180, HorizontalAlignment.Center);
this.listView1.Columns.Add("配置", 570, HorizontalAlignment.Center);
this.listView1.Columns.Add("颜色", 300, HorizontalAlignment.Center);
this.listView1.Columns.Add("数量", 350, HorizontalAlignment.Center);
this.listView1.Items.Clear();
if (a==1)
{
dt = bll.SearchDetailA();
}
else
{
dt = bll.SearchDetailB();
}
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(dt.Rows[i]["paintCode"].ToString());
lvi.SubItems.Add(dt.Rows[i]["productInfo"].ToString());
lvi.SubItems.Add(dt.Rows[i]["color"].ToString());
lvi.SubItems.Add(dt.Rows[i]["total"].ToString());
this.listView1.Items.Add(lvi);
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
}
}
private void TimeGo()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 10;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
}
private void timer_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Thread.Sleep(500);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (Program.a == 1)
{
GridppReport report = new GridppReport();
report.Register("");
report.LoadFromFile(@"D:\StockA.grf");
report.DesignPaperOrientation = GRPaperOrientation.grpoLandscape;
//report.Printer.PrinterName = "";
report.Print(false);
}
if (Program.a == 2)
{
GridppReport report = new GridppReport();
report.Register("");
if (DateTime.Now > DateTime.Parse(DateTime.Now.ToShortDateString() + " 19:30:00") && DateTime.Now < DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59"))
{
report.LoadFromFile(@"D:\StockB1.grf");
}
if (DateTime.Now > DateTime.Parse(DateTime.Now.ToShortDateString() + " 00:00:00") && DateTime.Now < DateTime.Parse(DateTime.Now.ToShortDateString() + " 07:30:00"))
{
report.LoadFromFile(@"D:\StockB2.grf");
}
report.DesignPaperOrientation = GRPaperOrientation.grpoLandscape;
report.Print(false);
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void label2_Click(object sender, EventArgs e)
{
//Environment.Exit(0);
this.Dispose();
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (!IsHandleCreated)
{
this.Close();
}
}
private const Int32 WM_SYSCOMMAND = 274;
private const UInt32 SC_CLOSE = 61536;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int RegisterWindowMessage(string lpString);
private void button2_Click(object sender, EventArgs e)
{
UWriteListViewToExcel(listView1, "喷涂入库数据");
}
/// <summary>
/// 将ListView的内容写入Excel表中
/// </summary>
/// <param name="LView">ListView控件</param>
/// <param name="strFilter">内容的标题</param>
public void UWriteListViewToExcel(ListView LView, string strTitle)
{
try
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
object m_objOpt = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Workbooks ExcelBooks = (Microsoft.Office.Interop.Excel.Workbooks)ExcelApp.Workbooks;
Microsoft.Office.Interop.Excel._Workbook ExcelBook = (Microsoft.Office.Interop.Excel._Workbook)(ExcelBooks.Add(m_objOpt));
Microsoft.Office.Interop.Excel._Worksheet ExcelSheet = (Microsoft.Office.Interop.Excel._Worksheet)ExcelBook.ActiveSheet;
//设置标题
ExcelApp.Caption = strTitle;
ExcelSheet.Cells[1, 1] = strTitle;
//写入列名
for (int i = 1; i <= LView.Columns.Count; i++)
{
ExcelSheet.Cells[2, i] = LView.Columns[i - 1].Text;
}
//写入内容
for (int i = 3; i < LView.Items.Count + 3; i++)
{
ExcelSheet.Cells[i, 1] = LView.Items[i - 3].Text;
for (int j = 2; j <= LView.Columns.Count; j++)
{
ExcelSheet.Cells[i, j] = LView.Items[i - 3].SubItems[j - 1].Text;
}
}
//显示Excel
ExcelApp.Visible = true;
}
catch (SystemException e)
{
MessageBox.Show(e.ToString());
}
}
}
}