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 Kf_WIPBal_DR : Form
{
//
private string fileName = null; //ÎļþÃû
private IWorkbook workbook = null;
private FileStream fs = null;
private bool disposed;
public Kf_WIPBal_DR()
{
InitializeComponent();
}
private void initHeadCaption()
{
}
private void yl_Click(object sender, EventArgs e)
{
int HYear =DBUtility.ClsPub.isInt(cmbHYear.Text);
int HPeriod =DBUtility.ClsPub.isInt(cmbHPeriod.Text);
if (MessageBox.Show("È·¶¨Òªµ¼Èë" + HYear + "Äê," + HPeriod + "ÔÂµÄÆÚ³õ¼Ç¼£¿", "Ìáʾ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
WriteClass();
}
}
//Êý¾Ýµ¼Èë
public void WriteClass()
{
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
DataSet Ds;
string s = "";
int sYear = DBUtility.ClsPub.isInt(cmbHYear.Text);
int sPeriod = DBUtility.ClsPub.isInt(cmbHPeriod.Text);
int sHICMONoCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÈÎÎñµ¥ºÅ", grdmain);
int sHMaterNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁÏ´úÂë", grdmain);
int sHProcNoCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤ÐòºÅ", grdmain);
int sHProcNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤Ðò´úÂë", grdmain);
int sHQtyCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÆÚ³õÊýÁ¿", grdmain);
if (sHICMONoCol == -1)
{
MessageBox.Show("ûÓÐÕÒµ½ÁУºÈÎÎñµ¥ºÅ","Ìáʾ");
return;
}
if (sHMaterNumberCol == -1)
{
MessageBox.Show("ûÓÐÕÒµ½ÁУºÎïÁÏ´úÂë", "Ìáʾ");
return;
}
if (sHProcNoCol == -1)
{
MessageBox.Show("ûÓÐÕÒµ½ÁУº¹¤ÐòºÅ", "Ìáʾ");
return;
}
if (sHProcNumberCol == -1)
{
MessageBox.Show("ûÓÐÕÒµ½ÁУº¹¤Ðò´úÂë", "Ìáʾ");
return;
}
if (sHQtyCol == -1)
{
MessageBox.Show("ûÓÐÕÒµ½ÁУºÆÚ³õÊýÁ¿", "Ìáʾ");
return;
}
string HICMONo;
string HMaterNumber;
int HProcNo;
string HProcNumber;
double HQty;
oCn.RunProc("delete Kf_WIPBal_DR");
for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
{
HICMONo = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHICMONoCol].Value);
HMaterNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHMaterNumberCol].Value);
HProcNo = DBUtility.ClsPub.isInt(grdmain.Rows[i].Cells[sHProcNoCol].Value);
HProcNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHProcNumberCol].Value);
HQty = DBUtility.ClsPub.isDoule(grdmain.Rows[i].Cells[sHQtyCol].Value);
if (HICMONo == "")
{
MessageBox.Show("µÚ" + (i + 1) + "ÐУ¬ÈÎÎñµ¥ºÅ²»ÄÜΪ¿Õ£¡", "Ìáʾ");
return;
}
if (HMaterNumber == "")
{
MessageBox.Show("µÚ" + (i + 1) + "ÐУ¬²úÆ·´úÂë²»ÄÜΪ¿Õ£¡", "Ìáʾ");
return;
}
if (HProcNo <= 0)
{
MessageBox.Show("µÚ" + (i + 1) + "ÐУ¬¹¤ÐòºÅ²»ÄÜСÓÚ0£¡", "Ìáʾ");
return;
}
if (HProcNumber == "")
{
MessageBox.Show("µÚ" + (i + 1) + "ÐУ¬¹¤Ðò´úÂë²»ÄÜΪ¿Õ£¡", "Ìáʾ");
return;
}
if (HQty == 0)
{
MessageBox.Show("µÚ" + (i + 1) + "ÐУ¬ÆÚ³õÊýÁ¿²»ÄÜΪ0£¡", "Ìáʾ");
return;
}
oCn.RunProc("insert into Kf_WIPBal_DR(HICMOInterID,HICMONo,HMaterID,HMaterNumber" +
",HProcNo,HProcID,HProcNumber,HQty" +
") values (" +
"0,'" + HICMONo + "',0,'" + HMaterNumber + "'" +
"," + HProcNo + ",0,'" + HProcNumber + "'," + HQty +
")");
}
Ds = oCn.RunProcReturn("exec h_p_Kf_WIPBal_DR "+sYear+","+sPeriod+",'"+DBUtility.ClsPub.CurUserName+"'", "h_p_Kf_WIPBal_DR", ref DBUtility.ClsPub.sErrInfo);
if (Ds == null)
{
MessageBox.Show("µ¼Èë´íÎó£¬ÔÒò£º" + DBUtility.ClsPub.sErrInfo, "Ìáʾ");
return;
}
if (DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][0]) == "Err")
{
MessageBox.Show("µ¼Èë´íÎó£¬ÔÒò£º" + DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][1]), "Ìáʾ");
return;
}
MessageBox.Show("µ¼ÈëÍê±Ï£¡");
grdmain.DataSource = null;
}
//дÈëÀà ´Ó¿Ø¼þ
private bool Mater_WriteClass(int row)
{
//
return true;
}
private void tc_Click(object sender, EventArgs e)
{
this.Close();
}
private void K3_OutMachFeeDataIn_Load(object sender, EventArgs e)
{
initHeadCaption();
}
public string ExcelPath;
///
/// ½«excelÖеÄÊý¾Ýµ¼Èëµ½DataTableÖÐ
///
/// excel·¾¶
/// excel¹¤×÷±¡sheetµÄÃû³Æ
/// µÚÒ»ÐÐÊÇ·ñÊÇDataTableµÄÁÐÃû
/// ·µ»ØµÄDataTable
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 = "1";
//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);
}
}
}