using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using System.Data.OleDb;
|
using System.Data.Sql;
|
using System.IO;
|
using NPOI.HSSF.UserModel;
|
using NPOI.SS.UserModel;
|
using NPOI.XSSF.UserModel;
|
|
namespace WorkM
|
{
|
public partial class Gy_DataIn_Order : Form
|
{
|
public long HItemID;//ÏîÄ¿ID
|
DAL.ClsGy_Employee_View oEmp = new DAL.ClsGy_Employee_View();
|
//
|
private string fileName = null; //ÎļþÃû
|
private IWorkbook workbook = null;
|
private FileStream fs = null;
|
private bool disposed;
|
public int HOrderBillNoCol;
|
public int HMaterNumberCol;
|
public int HOrderPlanDateCol;
|
public int HXLiaoDateCol;
|
public int HCYaDateCol;
|
public int HZWanDateCol;
|
public int HQJiaGongDateCol;
|
public int HHJieDateCol;
|
public int HPTuDateCol;
|
public int HWXieDateCol;
|
|
|
public Gy_DataIn_Order()
|
{
|
InitializeComponent();
|
}
|
|
private void initHeadCaption()
|
{
|
|
}
|
|
private void yl_Click(object sender, EventArgs e)
|
{
|
WriteClass();
|
}
|
|
//Êý¾Ýµ¼Èë
|
public void WriteClass()
|
{
|
string HBillNo = "";
|
Int64 HInterID = 0;
|
double HPayMent = 0;
|
HOrderBillNoCol = DBUtility.Gy_BaseFun.Fun_GetCol("¶©µ¥¸ú×ÙºÅ", grdmain);
|
//HMaterNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·´úÂë", grdmain);
|
HOrderPlanDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HXLiaoDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("1NCT¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HCYaDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("2¼ô´²¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HZWanDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("3³åѹ¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HQJiaGongDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("5ÕÛÍ伯»®Í깤ÈÕÆÚ", grdmain);
|
HHJieDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("6º¸½Ó¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HPTuDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("7ÅçÍ¿¼Æ»®Í깤ÈÕÆÚ", grdmain);
|
HWXieDateCol = DBUtility.Gy_BaseFun.Fun_GetCol("4Íâмƻ®Í깤ÈÕÆÚ", grdmain);
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
string HOrderBillNo;
|
string HMaterNumber;
|
DateTime HOrderPlanDate;
|
DateTime HXLiaoDate;
|
DateTime HCYaDate;
|
DateTime HZWanDate;
|
DateTime HQJiaGongDate;
|
DateTime HHJieDate;
|
DateTime HPTuDate;
|
DateTime HWXieDate;
|
try
|
{
|
for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
|
{
|
|
HOrderBillNo = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[HOrderBillNoCol].Value);
|
HMaterNumber ="";
|
HOrderPlanDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HOrderPlanDateCol].Value);
|
HXLiaoDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HXLiaoDateCol].Value);
|
HCYaDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HCYaDateCol].Value);
|
HZWanDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HZWanDateCol].Value);
|
HQJiaGongDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HQJiaGongDateCol].Value);
|
HHJieDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HHJieDateCol].Value);
|
HPTuDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HPTuDateCol].Value);
|
HWXieDate = DBUtility.ClsPub.isDate(grdmain.Rows[i].Cells[HWXieDateCol].Value);
|
//// ÊÇ·ñºÏÀí
|
oCn.RunProc("Delete from Mes_OrderProcFlow Where HOrderBillNo='" + HOrderBillNo + "' ");
|
oCn.RunProc("Insert into Mes_OrderProcFlow (HOrderBillNo,HMaterNumber,HOrderPlanDate,HXLiaoDate " +
|
",HCYaDate,HZWanDate,HQJiaGongDate,HHJieDate,HPTuDate,HWXieDate) values('" + HOrderBillNo + "','" + HMaterNumber + "'" +
|
",'" + HOrderPlanDate + "','" + HXLiaoDate + "','" + HCYaDate + "'" +
|
",'" + HZWanDate + "','" + HQJiaGongDate + "','" + HHJieDate + "','" + HPTuDate + "','" + HWXieDate + "')");
|
|
}
|
MessageBox.Show("µ¼ÈëÍê±Ï£¡");
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("µ¼Èëʧ°Ü£¡" + e.Message);
|
|
}
|
}
|
|
//дÈëÀà ´Ó¿Ø¼þ
|
private bool Mater_WriteClass(int row)
|
{
|
//
|
|
return true;
|
}
|
|
private void tc_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void OutMachFeeDataIn_Load(object sender, EventArgs e)
|
{
|
initHeadCaption();
|
}
|
public string ExcelPath;
|
|
|
/// <summary>
|
/// ½«excelÖеÄÊý¾Ýµ¼Èëµ½DataTableÖÐ
|
/// </summary>
|
/// <param name="fileName">excel·¾¶</param>
|
/// <param name="sheetName">excel¹¤×÷±¡sheetµÄÃû³Æ</param>
|
/// <param name="isFirstRowColumn">µÚÒ»ÐÐÊÇ·ñÊÇDataTableµÄÁÐÃû</param>
|
/// <returns>·µ»ØµÄDataTable</returns>
|
public DataTable ExcelToDataTable(string fileName, string sheetName, bool isFirstRowColumn)
|
{
|
ISheet sheet = null;
|
DataTable data = new DataTable();
|
int startRow = 0;
|
try
|
{
|
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
if (fileName.IndexOf(".xlsx") > 0) // 2007°æ±¾
|
workbook = new XSSFWorkbook(fs);
|
else if (fileName.IndexOf(".xls") > 0) // 2003°æ±¾
|
workbook = new HSSFWorkbook(fs);
|
|
if (sheetName != null)
|
{
|
sheet = workbook.GetSheet(sheetName);
|
if (sheet == null) //Èç¹ûûÓÐÕÒµ½Ö¸¶¨µÄsheetName¶ÔÓ¦µÄsheet£¬Ôò³¢ÊÔ»ñÈ¡µÚÒ»¸ösheet
|
{
|
sheet = workbook.GetSheetAt(0);
|
}
|
}
|
else
|
{
|
sheet = workbook.GetSheetAt(0);
|
}
|
if (sheet != null)
|
{
|
IRow firstRow = sheet.GetRow(0);
|
int cellCount = firstRow.LastCellNum; //Ò»ÐÐ×îºóÒ»¸öcellµÄ±àºÅ ¼´×ܵÄÁÐÊý
|
|
if (isFirstRowColumn)
|
{
|
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
{
|
ICell cell = firstRow.GetCell(i);
|
if (cell != null)
|
{
|
string cellValue = cell.StringCellValue;
|
if (cellValue != null)
|
{
|
DataColumn column = new DataColumn(cellValue);
|
data.Columns.Add(column);
|
}
|
}
|
}
|
startRow = sheet.FirstRowNum + 1;
|
}
|
else
|
{
|
startRow = sheet.FirstRowNum;
|
}
|
|
//×îºóÒ»ÁеıêºÅ
|
int rowCount = sheet.LastRowNum;
|
for (int i = startRow; i <= rowCount; ++i)
|
{
|
IRow row = sheet.GetRow(i);
|
if (row == null) continue; //ûÓÐÊý¾ÝµÄÐÐĬÈÏÊÇnull¡¡¡¡¡¡¡¡¡¡¡¡¡¡
|
|
DataRow dataRow = data.NewRow();
|
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
{
|
if (row.GetCell(j) != null) //ͬÀí£¬Ã»ÓÐÊý¾ÝµÄµ¥Ôª¸ñ¶¼Ä¬ÈÏÊÇnull
|
dataRow[j] = row.GetCell(j).ToString();
|
}
|
data.Rows.Add(dataRow);
|
}
|
}
|
|
return data;
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine("Exception: " + ex.Message);
|
return null;
|
}
|
}
|
|
DataTable d;
|
private void button1_Click_1(object sender, EventArgs e)
|
{
|
if (txtHRemark.Text.Trim() == "")
|
{
|
txtHRemark.Text = "Sheet1";
|
//MessageBox.Show("ÇëÊäÈëÐèÒªµ¼ÈëµÄ¹¤×÷±¡Ãû³Æ£¡");
|
//return;
|
}
|
OpenExcelFile.Title = "Open Excel File ";
|
OpenExcelFile.FileName = "";
|
OpenExcelFile.Filter = "Microsoft Office Excel Files(*.xls)|*.xls";
|
OpenExcelFile.ShowDialog();
|
if (OpenExcelFile.FileName != "")
|
{
|
ExcelPath = OpenExcelFile.FileName;
|
d = ExcelToDataTable(ExcelPath, txtHRemark.Text.Trim(), true);
|
grdmain.DataSource = d.DefaultView;
|
}
|
else
|
{
|
ExcelPath = "";
|
}
|
}
|
|
private Int32 Fun_GetCol(string sCol)
|
{
|
return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdmain);
|
}
|
|
|
}
|
}
|