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.

172 lines
6.3 KiB

3 years ago
using Stone.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Stone.WinModule.Standard
{
public partial class frmPREDN : Form
{
internal DataTable dtData;
private DataSet dsExport = new DataSet();
private DataTable dtExport = new DataTable();
public DateTime dtPickUpTime;
3 years ago
public frmPREDN()
{
InitializeComponent();
dtExport.Columns.Add("Vendor Code", typeof(Int32));
dtExport.Columns.Add("ASN Number");
dtExport.Columns.Add("Kolli No.");
dtExport.Columns.Add("Plant Code");
dtExport.Columns.Add("Required Pick-up Date");
dtExport.Columns.Add("Required Pick-up Time");
dtExport.Columns.Add("Required Swet Date");
dtExport.Columns.Add("Required Swet Time");
dtExport.Columns.Add("Material Number");
dtExport.Columns.Add("Parts Quantity", typeof(Int32));
dsExport.Tables.Add(dtExport);
this.dgrdView.DataSource = dtExport;
this.dgrdView.Columns["Vendor Code"].ReadOnly = true;
this.dgrdView.Columns["ASN Number"].ReadOnly = true;
this.dgrdView.Columns["Kolli No."].ReadOnly = true;
this.dgrdView.Columns["Plant Code"].ReadOnly = true;
this.dgrdView.Columns["Material Number"].ReadOnly = true;
this.dgrdView.Columns["Parts Quantity"].ReadOnly = true;
}
private void frmPREDN_Load(object sender, EventArgs e)
{
foreach(DataRow drData in dtData.Rows)
{
DataRow drNew = dtExport.NewRow();
drNew["Vendor Code"] = "12538410";
drNew["ASN Number"] = drData["ASNNumber"].ToString();
drNew["Kolli No."] = drData["PackageNo"].ToString();
drNew["Plant Code"] = drData["fileType"].ToString();
// drNew["Required Pick-up Date"] = Convert.ToDateTime(drData["Date"]).AddDays(-1).ToString("yyyy-MM-dd");
// drNew["Required Pick-up Time"] = "23:59:59";
drNew["Required Pick-up Date"] = dtPickUpTime.Date.ToString("yyyy-MM-dd");
drNew["Required Pick-up Time"] = dtPickUpTime.Hour.ToString("00") + ":" + dtPickUpTime.Minute.ToString("00") + ":00";
3 years ago
drNew["Required Swet Date"] = Convert.ToDateTime(drData["Date"]).ToString("yyyy-MM-dd");
drNew["Required Swet Time"] = "23:59:59";
drNew["Material Number"] = drData["PartNumber"].ToString();
drNew["Parts Quantity"] = drData["Qty"].ToString();
dtExport.Rows.Add(drNew);
}
this.lblState.Text = $"记录:{dtExport.Rows.Count}";
}
public static void ExportExcelX(string filename, string title, DataSet dsData)
{
try
{
MyExcelX excel = new MyExcelX();
excel.NewExcel(filename);
excel.NewSheet(title);
excel.sheet.SetColumnWidth(0, 4000);
excel.sheet.SetColumnWidth(1, 5000);
excel.sheet.SetColumnWidth(2, 5000);
excel.sheet.SetColumnWidth(3, 3000);
excel.sheet.SetColumnWidth(4, 6000);
excel.sheet.SetColumnWidth(5, 6000);
excel.sheet.SetColumnWidth(6, 6000);
excel.sheet.SetColumnWidth(7, 6000);
excel.sheet.SetColumnWidth(8, 4000);
excel.sheet.SetColumnWidth(9, 4000);
//创建第一行的标题列
int rowindex = 0;
//excel.CreateRow(rowindex);
//excel.CreateCell(rowindex, 0);
//excel.SetCellValue(rowindex, 0, title);
//创建第二行的字段
excel.CreateRow(rowindex);
for (int i = 0; i < dsData.Tables[0].Columns.Count; i++)
{
excel.CreateCell(rowindex, i);
excel.SetCellValue(rowindex, i, dsData.Tables[0].Columns[i].ColumnName);
}
rowindex++;
foreach (DataRow drData in dsData.Tables[0].Rows)
{
excel.CreateRow(rowindex);
for (int k = 0; k < dsData.Tables[0].Columns.Count; k++)
{
excel.CreateCell(rowindex, k);
//excel.SetCellValue(rowindex, k, drData[dsData.Tables[0].Columns[k].ColumnName].ToString());
if (dsData.Tables[0].Columns[k].DataType == typeof(System.Int32))
{
if (drData[dsData.Tables[0].Columns[k].ColumnName] != DBNull.Value)
{
excel.SetCellValue(rowindex, k, Convert.ToDouble(drData[dsData.Tables[0].Columns[k].ColumnName]));
}
}
else
{
excel.SetCellValue(rowindex, k, drData[dsData.Tables[0].Columns[k].ColumnName].ToString());
}
}
rowindex++;
}
excel.Save();
//MyMessageBox.ShowInfoMessage(filename + " 导出成功!");
}
catch (Exception ex)
{
//MyMessageBox.ShowErrorMessage(ex.Message);
throw ex;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
string filename = "Pre-DN-" + dtData.Rows[0]["AsnNumber"].ToString() + ".xlsx";
this.saveFileDialog1.FileName = filename;
if(this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
ExportExcelX(this.saveFileDialog1.FileName, "Upload Pre-DN", dsExport);
MyMessageBox.ShowInfoMessage(this.saveFileDialog1.FileName + " 导出成功");
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
}
}