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 PlanM
|
{
|
public partial class Gy_ICBomBill_K3_DR : Form
|
{
|
DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
|
DAL.ClsK3_Unit_View oUnit = new DAL.ClsK3_Unit_View();
|
DAL.ClsK3_Warehouse_View oWh = new DAL.ClsK3_Warehouse_View();
|
DAL.ClsK3_StockPlace_View oSP = new DAL.ClsK3_StockPlace_View();
|
DAL.ClsGy_Process_View oProc = new DAL.ClsGy_Process_View();
|
DAL.ClsK3_ICBOMGroup_View oICBOMGroup = new DAL.ClsK3_ICBOMGroup_View();
|
DAL.ClsK3_User_View oUser = new DAL.ClsK3_User_View();
|
//
|
private string fileName = null; //ÎļþÃû
|
private IWorkbook workbook = null;
|
private FileStream fs = null;
|
private bool disposed;
|
|
public Gy_ICBomBill_K3_DR()
|
{
|
InitializeComponent();
|
}
|
|
private void initHeadCaption()
|
{
|
|
}
|
|
private void yl_Click(object sender, EventArgs e)
|
{
|
WriteClass();
|
}
|
|
//Êý¾Ýµ¼Èë
|
public void WriteClass()
|
{
|
DAL.ClsGy_ICBomBill_K3 BillNew = new DAL.ClsGy_ICBomBill_K3();
|
|
SQLHelper.ClsCNK3 oK3Cn = new SQLHelper.ClsCNK3();
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn("exec HX_GetICBillNo 1, '50'", "t_billcodeby");
|
|
string s = "";
|
int sYear = 0;
|
int sPeriod = 0;
|
if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
|
{
|
MessageBox.Show(s, "Ìáʾ");
|
return ;
|
}
|
int sHParentNumber = DBUtility.Gy_BaseFun.Fun_GetCol("BOM×é±ð´úÂë", grdmain);
|
int sHVersion = DBUtility.Gy_BaseFun.Fun_GetCol("°æ±¾ºÅ", grdmain);
|
int sHStatus = DBUtility.Gy_BaseFun.Fun_GetCol("״̬", grdmain);
|
int sHPicNo = DBUtility.Gy_BaseFun.Fun_GetCol("ͼºÅ", grdmain);
|
int sHMaterNumber = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁÏ´úÂë", grdmain);
|
int sHUnitNumber = DBUtility.Gy_BaseFun.Fun_GetCol("¼ÆÁ¿µ¥Î»´úÂë", grdmain);
|
int sHQty = DBUtility.Gy_BaseFun.Fun_GetCol("ÊýÁ¿", grdmain);
|
int sHProdRate = DBUtility.Gy_BaseFun.Fun_GetCol("³ÉÆ·ÂÊ", grdmain);
|
int sHJump = DBUtility.Gy_BaseFun.Fun_GetCol("Ìø²ã", grdmain);
|
|
BillNew.omodel.HYear = sYear;
|
BillNew.omodel.HPeriod = sPeriod;
|
BillNew.omodel.HDate = DateTime.Now;
|
BillNew.omodel.HBillNo = Ds.Tables[0].Rows[0][0].ToString().Trim();
|
|
if (oICBOMGroup.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHParentNumber].Value)))
|
{
|
BillNew.omodel.HParentID = oICBOMGroup.omodel.HItemID;
|
}
|
else
|
{
|
BillNew.omodel.HParentID = 0;
|
}
|
//
|
if (oMater.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHMaterNumber].Value)))
|
{
|
BillNew.omodel.HMaterID = oMater.omodel.HItemID;
|
}
|
else
|
{
|
BillNew.omodel.HMaterID = 0;
|
}
|
//
|
if (oUnit.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHUnitNumber].Value)))
|
{
|
BillNew.omodel.HUnitID = oUnit.omodel.HItemID;
|
}
|
else
|
{
|
BillNew.omodel.HUnitID = 0;
|
}
|
//
|
BillNew.omodel.HVersion = DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHVersion].Value);
|
BillNew.omodel.HStatus = DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHStatus].Value);
|
BillNew.omodel.HPicNo = DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHPicNo].Value);
|
BillNew.omodel.HQty = DBUtility.ClsPub.isDoule(grdmain.Rows[0].Cells[sHQty].Value);
|
BillNew.omodel.HProdRate = DBUtility.ClsPub.isSingle(grdmain.Rows[0].Cells[sHProdRate].Value);
|
BillNew.omodel.HJump = DBUtility.ClsPub.isStrNull(grdmain.Rows[0].Cells[sHJump].Value);
|
BillNew.omodel.HRemark = "EXCELµ¼Èë";
|
|
int sHMaterNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁÏ´úÂë", grdmain);
|
int sHUnitNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("¼ÆÁ¿µ¥Î»´úÂë", grdmain);
|
int sHChildTypeCol = DBUtility.Gy_BaseFun.Fun_GetCol("×ÓÏîÄ¿ÀàÐÍ", grdmain);
|
int sHQtyCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÓÃÁ¿", grdmain);
|
int sHRelQtyCol = DBUtility.Gy_BaseFun.Fun_GetCol("³£Óõ¥Î»ÓÃÁ¿", grdmain);
|
int sHWasteRateCol = DBUtility.Gy_BaseFun.Fun_GetCol("ËðºÄÂÊ", grdmain);
|
int sHWhNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("²Ö¿â´úÂë", grdmain);
|
int sHSPNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("²Öλ´úÂë", grdmain);
|
int sHProcNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤Ðò´úÂë", grdmain);
|
int sHRemark2Col = DBUtility.Gy_BaseFun.Fun_GetCol("±¸×¢1", grdmain);
|
int sHRemark3Col = DBUtility.Gy_BaseFun.Fun_GetCol("±¸×¢2", grdmain);
|
int sHRemark4Col = DBUtility.Gy_BaseFun.Fun_GetCol("±¸×¢3", grdmain);
|
|
long HMaterID = 0;
|
long HUnitID = 0;
|
long HWhID = 0;
|
long HSPID = 0;
|
long HProcID = 0;
|
|
BillNew.DetailColl = new List<Model.ClsGy_ICBomBillSub_K3>();
|
for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
|
{
|
Model.ClsGy_ICBomBillSub_K3 oSub = new Model.ClsGy_ICBomBillSub_K3();
|
//¹Ì¶¨¸³Öµ========================================
|
//oSub.HOrgBillEntryID = 0;
|
oSub.HEntryID = i + 1;
|
oSub.HRemark = "EXCELµ¼Èë";
|
oSub.HSourceInterID = 0;
|
oSub.HSourceEntryID = 0;
|
oSub.HSourceBillType = "";
|
oSub.HSourceBillNo = "";
|
oSub.HRelationQty = 0;
|
oSub.HRelationMoney = 0;
|
oSub.HCloseMan = "";
|
oSub.HEntryCloseDate = DBUtility.ClsPub.isDate(""); ;
|
oSub.HCloseType = false;
|
//=============================
|
if (oMater.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHMaterNumberCol].Value)))
|
{
|
HMaterID = oMater.omodel.HItemID;
|
}
|
else
|
{
|
HMaterID = 0;
|
}
|
|
if (oUnit.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHUnitNumberCol].Value)))
|
{
|
HUnitID = oUnit.omodel.HItemID;
|
}
|
else
|
{
|
HUnitID = 0;
|
}
|
|
if (oWh.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHWhNumberCol].Value)))
|
{
|
HWhID = oWh.omodel.HItemID;
|
}
|
else
|
{
|
HWhID = 0;
|
MessageBox.Show("µÚ" + i.ToString() + "ÐУ¬²Ö¿â²»ÄÜΪ¿Õ£¡");
|
return ;
|
}
|
|
if (oSP.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHSPNumberCol].Value)))
|
{
|
HSPID = oSP.omodel.HItemID;
|
}
|
else
|
{
|
HSPID = 0;
|
}
|
|
if (oProc.GetInfoByNumber(DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHProcNumberCol].Value)))
|
{
|
HProcID = oProc.omodel.HItemID;
|
}
|
else
|
{
|
HProcID = 0;
|
}
|
|
if (HMaterID == 0 || HUnitID == 0)
|
{
|
continue;
|
}
|
|
oSub.HMaterID = HMaterID;
|
oSub.HUnitID = HUnitID;
|
oSub.HWhID = HWhID;
|
oSub.HSPID = HSPID;
|
oSub.HProcID = HProcID;
|
oSub.HChildType = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHChildTypeCol].Value);
|
oSub.HQty = DBUtility.ClsPub.isDoule(grdmain.Rows[i].Cells[sHQtyCol].Value);
|
if (oSub.HQty == 0)
|
{
|
MessageBox.Show("µÚ" + i.ToString() + "ÐУ¬ÓÃÁ¿²»ÄÜΪ¿Õ£¡");
|
return ;
|
}
|
oSub.HRelQty = DBUtility.ClsPub.isDoule(grdmain.Rows[i].Cells[sHRelQtyCol].Value);
|
oSub.HWasteRate = DBUtility.ClsPub.isSingle(grdmain.Rows[i].Cells[sHWasteRateCol].Value);
|
oSub.HRemark2 = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHRemark2Col].Value);
|
oSub.HRemark3 = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHRemark3Col].Value);
|
oSub.HRemark4 = DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sHRemark4Col].Value);
|
|
BillNew.DetailColl.Add(oSub);
|
}
|
bool bResult = BillNew.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
|
if (bResult == true)
|
{
|
MessageBox.Show("±£´æÍê±Ï£¡");
|
}
|
}
|
|
//дÈëÀà ´Ó¿Ø¼þ
|
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;
|
|
|
/// <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 = "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);
|
}
|
|
|
}
|
}
|