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;
|
|
namespace BaseSet
|
{
|
public partial class Gy_DataInTmp_Material : Form
|
{
|
ClsGy_DataInTmp_Material oTmp = new ClsGy_DataInTmp_Material();
|
DAL.ClsGy_Material_Ctl oMater = new DAL.ClsGy_Material_Ctl();
|
DAL.ClsGy_Material_View oMaterHlp = new DAL.ClsGy_Material_View();
|
DAL.ClsGy_Unit_View oUnit = new DAL.ClsGy_Unit_View();
|
DAL.ClsGy_Warehouse_View oWh = new DAL.ClsGy_Warehouse_View();
|
//
|
|
public Gy_DataInTmp_Material()
|
{
|
InitializeComponent();
|
}
|
|
|
private void initHeadCaption()
|
{
|
|
}
|
|
//
|
private void yl_Click(object sender, EventArgs e)
|
{
|
WriteClass(cmbHDataInTmp.Text);
|
}
|
|
//Êý¾Ýµ¼Èë
|
public void WriteClass(string sName)
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
string sColName;
|
string sFieldName;
|
if (sName == "ÎïÁϵ¼Èë")
|
{
|
for (int i = 0; i <= grdmain.Rows.Count - 1; i++)
|
{
|
if (DBUtility.ClsPub.isStrNull(grdmain.Rows[i].Cells[0].Value) != "")
|
{
|
if (Mater_WriteClass(i))
|
{
|
oMater.AddNew();
|
}
|
}
|
}
|
}
|
MessageBox.Show("µ¼ÈëÍê±Ï");
|
grdmain.DataSource = null;
|
}
|
|
//дÈëÀà ´Ó¿Ø¼þ
|
private bool Mater_WriteClass(int row)
|
{
|
//
|
string sHNumber = "";
|
long HItemID = 0;
|
int sCol = DBUtility.Gy_BaseFun.Fun_GetCol("ÎïÁÏ´úÂë", grdmain);
|
//
|
sHNumber = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCol].Value);
|
//ÅжÏÊÇ·ñÔÊÐí ±£´æ
|
//ÉóºË´úÂëÊÇ·ñºÏÀí
|
if (!DBUtility.ClsPub.AllowNumber(sHNumber))
|
{
|
MessageBox.Show("´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
|
return false;
|
}
|
|
//ÊÇ·ñÖØ¸´´úÂë
|
if (oMater.HavSameNumber(HItemID, sHNumber))
|
{
|
MessageBox.Show("´úÂëÖØ¸´£¡", "Ìáʾ");
|
return false;
|
}
|
//¼ì²é¸¸¼¶ÊÇ·ñ´æÔÚ
|
string sParent;
|
sParent = DBUtility.ClsPub.GetParentCode(sHNumber);
|
if (sParent.Trim() == "")
|
{
|
oMater.oModel.HParentID = 0;
|
}
|
else
|
{
|
if (oMater.HavParentCode(sParent.Trim(), HItemID))
|
{
|
oMater.oModel.HParentID = oMater.oModel.HItemID;
|
}
|
else
|
{
|
MessageBox.Show("Éϼ¶´úÂë²»´æÔÚ»ò±»½ûÓã¡", "Ìáʾ");
|
return false;
|
}
|
}
|
//µÃµ½¶Ì´úÂë
|
string sShortNumber;
|
sShortNumber = DBUtility.ClsPub.GetShortNumber(sHNumber);
|
if (sShortNumber.Trim() == "")
|
{
|
return false;
|
}
|
//±£´æÔ´úÂë
|
if (oMaterHlp.GetInfoByID(HItemID))
|
{
|
oMater.HOldNumber = oMaterHlp.omodel.HNumber;
|
//ÊÇ·ñдúÂëÊÇ×Ô¼º×ÓÏîÄ¿µÄ¡¡×ÓÏîÄ¿
|
if (sParent.Length >= oMater.HOldNumber.Length)
|
{
|
if (sParent.Substring(0, oMater.HOldNumber.ToString().Length) == oMater.HOldNumber.Trim())
|
{
|
MessageBox.Show("дúÂë²»ÄÜÊÇ×Ô¼ºµÄϼ¶µÄ×ÓÏîÄ¿£¡", "Ìáʾ");
|
return false;
|
}
|
}
|
}
|
else
|
{
|
oMater.HOldNumber = "";
|
}
|
//дÈëÐÅÏ¢
|
oMater.oModel.HShortNumber = sShortNumber;
|
oMater.oModel.HEndFlag = true;
|
oMater.oModel.HLevel = DBUtility.ClsPub.GetLevel(sHNumber);
|
oMater.oModel.HNumber = sHNumber;
|
oMater.oModel.HHelpCode = sShortNumber;
|
oMater.oModel.HName = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCol + 1].Value);
|
oMater.oModel.HStopflag = false;
|
oMater.oModel.HRemark = "";
|
|
oMater.oModel.HModel = DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCol + 2].Value);
|
if (oUnit.GetInfoByName(DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCol + 3].Value)))
|
{
|
oMater.oModel.HUnitID = oUnit.omodel.HItemID;
|
}
|
if (oWh.GetInfoByName(DBUtility.ClsPub.isStrNull(grdmain.Rows[row].Cells[sCol + 4].Value)))
|
{
|
oMater.oModel.HWhID = oWh.omodel.HItemID;
|
}
|
oMater.oModel.HMaterClsID = 0;
|
oMater.oModel.HMaterTypeID = 0;
|
oMater.oModel.HUnitGroupID = 0;
|
oMater.oModel.HRoutingID = 0;
|
oMater.oModel.HBomID = 0;
|
oMater.oModel.HSecUnitID = 0;
|
oMater.oModel.HSecUnitRate = 0;
|
oMater.oModel.HHighStock = 0;
|
oMater.oModel.HLowStock = 0;
|
oMater.oModel.HSafeStock = 0;
|
oMater.oModel.HOrderPrice = 0;
|
oMater.oModel.HSalePrice = 0;
|
oMater.oModel.HKeepDays = 0;
|
oMater.oModel.HPlanPrice = 0;
|
oMater.oModel.HstdPrice = 0;
|
oMater.oModel.HQtyMin = 0;
|
oMater.oModel.HQtyMax = 0;
|
oMater.oModel.HVersion = "";
|
oMater.oModel.HEngName = "";
|
oMater.oModel.HEngModel = "";
|
oMater.oModel.HPropertyTypeID = 0;
|
oMater.oModel.HSPGroupID = 0;
|
oMater.oModel.HSPID = 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;
|
|
private void OpenExcelData(string sPath)
|
{
|
string sName;
|
sName = "Sheet1";
|
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sPath + ";" +
|
"Extended Properties='Excel 8.0;IMEX=1'";
|
DataSet ds = new DataSet();
|
OleDbConnection conn = new OleDbConnection(strConn);
|
conn.Open();
|
try
|
{
|
OleDbDataAdapter Da = new OleDbDataAdapter("select * from [" + sName + "$]", conn);
|
Da.Fill(ds);
|
grdmain.DataSource = ds.Tables[0];
|
}
|
catch(Exception e)
|
{
|
MessageBox.Show("ÒýÈëEXCELÊý¾Ýʧ°Ü£¡ÇëÓë¹ÜÀíÔ±ÁªÏµ£¡" + e.Message);
|
}
|
}
|
|
private void button1_Click_1(object sender, EventArgs e)
|
{
|
OpenExcelFile.Title = "Open Excel File ";
|
OpenExcelFile.FileName = "";
|
OpenExcelFile.Filter = "Microsoft Office Excel Files(*.xls)|*.xls|(*.csv)|*.csv";
|
OpenExcelFile.ShowDialog();
|
if (OpenExcelFile.FileName != "")
|
{
|
ExcelPath = OpenExcelFile.FileName;
|
OpenExcelData(ExcelPath);
|
}
|
else
|
{
|
ExcelPath = "";
|
}
|
|
}
|
|
}
|
}
|