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 BaseSet
|
{
|
public partial class Gy_DataInTmp_Customer : Form
|
{
|
DAL.ClsGy_Customer_Ctl oCus = new DAL.ClsGy_Customer_Ctl();
|
DAL.ClsGy_Customer_View oCusHlp = new DAL.ClsGy_Customer_View();
|
DAL.ClsGy_SettleStyle_View oSS = new DAL.ClsGy_SettleStyle_View();
|
DAL.ClsGy_Currency_View oCur = new DAL.ClsGy_Currency_View();
|
//
|
private string fileName = null; //ÎļþÃû
|
private IWorkbook workbook = null;
|
private FileStream fs = null;
|
private bool disposed;
|
|
string sHavSame = "";
|
//
|
int sHNumberCol = 0;
|
int sNameCol = 0;
|
int sHShortNameCol = 0;
|
int sHAddressCol = 0;
|
int sHLinkManCol = 0;
|
int sHLinkPhoneCol = 0;
|
int sHFaxCol = 0;
|
int sHPostalCodeCol = 0;
|
int sHEmailCol = 0;
|
int sHBankCol = 0;
|
int sHBankAccountCol = 0;
|
int sHTaxNumCol = 0;
|
int sHTaxRateCol = 0;
|
int sHCountryCol = 0;
|
int sHCorManCol = 0;
|
int sHCurIDCol = 0;
|
int sHSSIDCol = 0;
|
int sHEmpIDCol = 0;
|
|
public Gy_DataInTmp_Customer()
|
{
|
InitializeComponent();
|
}
|
|
|
private void initHeadCaption()
|
{
|
|
}
|
|
//
|
private void yl_Click(object sender, EventArgs e)
|
{
|
//WriteClass_ParentCode();
|
WriteClass();
|
}
|
|
//Êý¾Ýµ¼Èë
|
public void WriteClass_ParentCode()
|
{
|
//SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
//string sColName;
|
//string sFieldName;
|
//int sNameCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁÏÃû³Æ", grdmain);
|
//for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
|
//{
|
// if (DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sNameCol].Value) != "")
|
// {
|
// if (ParentCode_WriteClass(i))
|
// {
|
// oCus.AddNew();
|
// }
|
// }
|
//}
|
}
|
|
////дÈëÀà ´Ó¿Ø¼þ
|
//private bool ParentCode_WriteClass(int row)
|
//{
|
// //
|
// string sHNumber = "";
|
// long HItemID = 0;
|
// int sLogoCol = DBUtility.Gy_BaseFun.Fun_GetCol("Æ·ÅÆ", grdmain);
|
// int sCurCol = DBUtility.Gy_BaseFun.Fun_GetCol("±Ò±ð", grdmain);
|
// int sCountryCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úµØ", grdmain);
|
// //
|
// sHNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sLogoCol].Value);
|
|
// //ÊÇ·ñÖØ¸´´úÂë
|
// if (oCus.HavSameNumber(HItemID, sHNumber))
|
// {
|
// return false;
|
// }
|
|
// //дÈëÐÅÏ¢
|
// oCus.oModel.HShortNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sLogoCol].Value);
|
// oCus.oModel.HEndFlag = false;
|
// oCus.oModel.HLevel = 1;
|
// oCus.oModel.HNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sLogoCol].Value);
|
// oCus.oModel.HHelpCode = "";
|
// oCus.oModel.HName = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sLogoCol].Value);
|
// oCus.oModel.HModel = "";
|
// oCus.oModel.HStopflag = false;
|
// oCus.oModel.HRemark = "";
|
// //if (oCur.GetInfoByName(DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCurCol].Value)))
|
// //{
|
// // oCus.oModel.HCurID = oCur.omodel.HItemID;
|
// //}
|
// //else
|
// //{
|
// // oCus.oModel.HCurID = 0;
|
// //}
|
// oCus.oModel.HUnitID = 7;
|
// oCus.oModel.HSalePrice = 0;
|
|
// oCus.oModel.HSubjoin = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sLogoCol].Value);
|
// oCus.oModel.HSubjoin2 = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCountryCol].Value);
|
// //oCus.oModel.HCountry = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCountryCol].Value);
|
|
// //
|
// oCus.oModel.HMaterClsID = 0;
|
// oCus.oModel.HMaterTypeID = 0;
|
// oCus.oModel.HUnitGroupID = 0;
|
// oCus.oModel.HRoutingID = 0;
|
// oCus.oModel.HBomID = 0;
|
// oCus.oModel.HSecUnitID = 0;
|
// oCus.oModel.HSecUnitRate = 0;
|
// oCus.oModel.HHighStock = 0;
|
// oCus.oModel.HLowStock = 0;
|
// oCus.oModel.HSafeStock = 0;
|
// oCus.oModel.HOrderPrice = 0;
|
// oCus.oModel.HKeepDays = 0;
|
// oCus.oModel.HPlanPrice = 0;
|
// oCus.oModel.HstdPrice = 0;
|
// oCus.oModel.HQtyMin = 0;
|
// oCus.oModel.HQtyMax = 0;
|
// oCus.oModel.HVersion = "";
|
// oCus.oModel.HEngName = "";
|
// oCus.oModel.HEngModel = "";
|
// oCus.oModel.HPropertyTypeID = 0;
|
// oCus.oModel.HSPGroupID = 0;
|
// oCus.oModel.HSPID = 0;
|
// return true;
|
//}
|
|
//Êý¾Ýµ¼Èë
|
public void WriteClass()
|
{
|
sHNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("¿Í»§´úÂë", grdmain);
|
sNameCol = DBUtility.Gy_BaseFun.Fun_GetCol("¿Í»§Ãû³Æ", grdmain);
|
sHShortNameCol = DBUtility.Gy_BaseFun.Fun_GetCol("¿Í»§¼ò³Æ", grdmain);
|
sHAddressCol = DBUtility.Gy_BaseFun.Fun_GetCol("µØÖ·", grdmain);
|
sHLinkManCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÁªÏµÈË", grdmain);
|
sHLinkPhoneCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÁªÏµµç»°", grdmain);
|
sHFaxCol = DBUtility.Gy_BaseFun.Fun_GetCol("´«Õæ", grdmain);
|
sHPostalCodeCol = DBUtility.Gy_BaseFun.Fun_GetCol("Óʱà", grdmain);
|
sHEmailCol = DBUtility.Gy_BaseFun.Fun_GetCol("µç×ÓÓÊÏä", grdmain);
|
sHBankCol = DBUtility.Gy_BaseFun.Fun_GetCol("¿ª»§ÒøÐÐ", grdmain);
|
sHBankAccountCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÒøÐÐÕ˺Å", grdmain);
|
sHTaxNumCol = DBUtility.Gy_BaseFun.Fun_GetCol("˰ÎñµÇ¼ÇºÅ", grdmain);
|
sHTaxRateCol = DBUtility.Gy_BaseFun.Fun_GetCol("Ôöֵ˰ÂÊ", grdmain);
|
sHCountryCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹ú¼Ò", grdmain);
|
sHCorManCol = DBUtility.Gy_BaseFun.Fun_GetCol("·¨ÈË´ú±í", grdmain);
|
sHCurIDCol = DBUtility.Gy_BaseFun.Fun_GetCol("ĬÈÏ»õ±Ò", grdmain);
|
sHSSIDCol = DBUtility.Gy_BaseFun.Fun_GetCol("½áË㷽ʽ", grdmain);
|
sHEmpIDCol = DBUtility.Gy_BaseFun.Fun_GetCol("ËùÊôÒµÎñÔ±", grdmain);
|
|
//
|
if (sHNumberCol == -1)
|
{
|
MessageBox.Show("ûÓÐÕÒµ½¡¾¿Í»§´úÂë¡¿µÄ±êÌâ", "Ìáʾ");
|
return;
|
}
|
if (sNameCol == -1)
|
{
|
MessageBox.Show("ûÓÐÕÒµ½¡¾¿Í»§Ãû³Æ¡¿µÄ±êÌâ", "Ìáʾ");
|
return;
|
}
|
sHavSame = "";
|
int sNumberCol = DBUtility.Gy_BaseFun.Fun_GetCol("¿Í»§´úÂë", grdmain);
|
for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
|
{
|
if (DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[sNumberCol].Value) != "")
|
{
|
if (Mater_WriteClass(i))
|
{
|
oCus.AddNew();
|
}
|
}
|
}
|
if (sHavSame != "")
|
{
|
MessageBox.Show("´úÂëÖØ¸´£º\r\n" + sHavSame);
|
}
|
MessageBox.Show("µ¼ÈëÍê±Ï");
|
grdmain.DataSource = null;
|
}
|
|
//дÈëÀà ´Ó¿Ø¼þ
|
private bool Mater_WriteClass(int row)
|
{
|
//
|
string sHNumber = "";
|
long HItemID = 0;
|
//
|
sHNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHNumberCol].Value);
|
//ÅжÏÊÇ·ñÔÊÐí ±£´æ
|
//ÉóºË´úÂëÊÇ·ñºÏÀí
|
if (!DBUtility.ClsPub.AllowNumber(sHNumber))
|
{
|
MessageBox.Show("´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
|
return false;
|
}
|
|
//ÊÇ·ñÖØ¸´´úÂë
|
if (oCus.HavSameNumber(HItemID, sHNumber))
|
{
|
sHavSame = sHavSame + sHNumber + "\r\n";
|
return false;
|
}
|
//¼ì²é¸¸¼¶ÊÇ·ñ´æÔÚ
|
string sParent;
|
sParent = DBUtility.ClsPub.GetParentCode(sHNumber);
|
if (sParent.Trim() == "")
|
{
|
oCus.oModel.HParentID = 0;
|
}
|
else
|
{
|
if (oCus.HavParentCode(sParent.Trim(), HItemID))
|
{
|
oCus.oModel.HParentID = oCus.oModel.HItemID;
|
}
|
else
|
{
|
MessageBox.Show("Éϼ¶´úÂë²»´æÔÚ»ò±»½ûÓã¡", "Ìáʾ");
|
return false;
|
}
|
}
|
//µÃµ½¶Ì´úÂë
|
string sShortNumber;
|
sShortNumber = DBUtility.ClsPub.GetShortNumber(sHNumber);
|
if (sShortNumber.Trim() == "")
|
{
|
return false;
|
}
|
//±£´æÔ´úÂë
|
if (oCusHlp.GetInfoByID(HItemID))
|
{
|
oCus.HOldNumber = oCusHlp.omodel.HNumber;
|
//ÊÇ·ñдúÂëÊÇ×Ô¼º×ÓÏîÄ¿µÄ¡¡×ÓÏîÄ¿
|
if (sParent.Length >= oCus.HOldNumber.Length)
|
{
|
if (sParent.Substring(0, oCus.HOldNumber.ToString().Length) == oCus.HOldNumber.Trim())
|
{
|
MessageBox.Show("дúÂë²»ÄÜÊÇ×Ô¼ºµÄϼ¶µÄ×ÓÏîÄ¿£¡", "Ìáʾ");
|
return false;
|
}
|
}
|
}
|
else
|
{
|
oCus.HOldNumber = "";
|
}
|
//дÈëÐÅÏ¢
|
oCus.oModel.HShortNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHShortNameCol].Value);
|
oCus.oModel.HEndFlag = true;
|
oCus.oModel.HLevel = DBUtility.ClsPub.GetLevel(sHNumber);
|
oCus.oModel.HNumber = sHNumber;
|
oCus.oModel.HHelpCode = sShortNumber;
|
oCus.oModel.HName = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sNameCol].Value);
|
oCus.oModel.HStopflag = false;
|
oCus.oModel.HRemark = "";
|
|
oCus.oModel.HAddress = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHAddressCol].Value);
|
oCus.oModel.HLinkMan = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHLinkManCol].Value);
|
oCus.oModel.HLinkPhone = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHLinkPhoneCol].Value);
|
oCus.oModel.HMobilePhone = "";
|
oCus.oModel.HFax = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHFaxCol].Value);
|
oCus.oModel.HPostalCode = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHPostalCodeCol].Value);
|
oCus.oModel.HEmail = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHEmailCol].Value);
|
oCus.oModel.HBank = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHBankCol].Value);
|
oCus.oModel.HBankAccount = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHBankAccountCol].Value);
|
oCus.oModel.HTaxNum = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHTaxNumCol].Value);
|
oCus.oModel.HTaxRate = DBUtility.ClsPub.isSingle(grdmain.Rows[row].Cells[sHTaxRateCol].Value);
|
oCus.oModel.HCountry = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHCountryCol].Value);
|
oCus.oModel.HCorMan = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHCorManCol].Value);
|
oCus.oModel.HEnglishName = "";
|
oCus.oModel.HEnglishAddress = "";
|
if (oSS.GetInfoByName(DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHSSIDCol].Value)))
|
{
|
oCus.oModel.HSSID = oSS.omodel.HItemID;
|
}
|
else
|
{
|
oCus.oModel.HSSID = 0;
|
}
|
if (oCur.GetInfoByName(DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sHCurIDCol].Value)))
|
{
|
oCus.oModel.HCurID = oCur.omodel.HItemID;
|
}
|
else
|
{
|
oCus.oModel.HCurID = 0;
|
}
|
oCus.oModel.HAreaID = 0;
|
oCus.oModel.HCusStatus = "";
|
oCus.oModel.HCusTypeID = 0;
|
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() == "")
|
{
|
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 = "";
|
}
|
}
|
|
}
|
}
|