前几天在report script写展BOM的程序,怎么也没写出来。回上海后,用C#写了一个。但是还不够完善,希望有兴趣的继续写下去。
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void find_Click(object sender, EventArgs e)
{
string connectionstrings = "server=127.0.0.1;UID=sa;PWD=111111;DataBase=ERP";
SqlConnection connection = new SqlConnection(connectionstrings);
string sqltcibd001 = "select * from tcibd001 where tcibd001.item = " + "’" + mpart.Text.Trim() + "’";
SqlDataAdapter tcibd001f = new SqlDataAdapter(sqltcibd001, connection);
DataSet ds = new DataSet();
tcibd001f.Fill(ds, "tcibd001");
DataRow dr = ds.Tables["tcibd001"].Rows[0];
if (dr["kitm"].ToString().Trim() == "p")
{
Response.Write("this is a p part!");
return;
}
///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
string mpartf = mpart.Text.Trim();
int mqana = 1;
DataSet dsend = new DataSet();
DataTable p_part = new DataTable("p_part");
dsend.Tables.Add(p_part);
p_part.Columns.Add("FGpart", typeof(string));
p_part.Columns.Add("Ppart", typeof(string));
p_part.Columns.Add("Type", typeof(string));
p_part.Columns.Add("Qana", typeof(int));
///@@@@@@@@@@@@@@@@@@@@@@@@@@
unbom(mpartf,mqana,p_part);
///@@@@@@@@@@@@@@@@@@@@@@@@@@
unbomview.DataSource = dsend.Tables["p_part"].DefaultView;
unbomview.DataBind();
}
public string unbom(string xpart,int xqana,DataTable xtable)
{
string[] m_part_array = new string[100];
int[] m_qana = new int[100];
int j = 0;
string connectionstrings = "server=127.0.0.1;UID=sa;PWD=111111;DataBase=ERP";
SqlConnection connection = new SqlConnection(connectionstrings);
string sqltcibd001x = "select tcibd001.item,tcibd001.kitm from tcibd001 where tcibd001.item = " + "’" + xpart + "’";
SqlDataAdapter tcibd001fx = new SqlDataAdapter(sqltcibd001x, connection);
DataSet dsx = new DataSet();
tcibd001fx.Fill(dsx, "tcibd001x");
DataRow drx = dsx.Tables["tcibd001x"].Rows[0];
if (drx["kitm"].ToString().Trim() == "p")
{
DataRow drp = xtable.NewRow();
drp["FGpart"] = mpart.Text.Trim();
drp["Ppart"] = drx["item"].ToString().Trim();
drp["Type"] = drx["kitm"].ToString().Trim();
drp["qana"] = xqana;
xtable.Rows.Add(drp);
return mpart.Text.Trim();
}
else
&
nbsp; {
m_part_array[j] = drx["item"].ToString().Trim();
string sqltibom010 = "select * from tibom010 where tibom010.mitm = " + "’" + m_part_array[j] + "’";
SqlDataAdapter tibom010x = new SqlDataAdapter(sqltibom010, connection);
tibom010x.Fill(dsx, "tibom010");
while (j < (dsx.Tables["tibom010"].Rows.Count))
{
m_part_array[j] = dsx.Tables["tibom010"].Rows[j]["sitm"].ToString();
m_qana[j] =xqana * (Convert.ToInt32(dsx.Tables["tibom010"].Rows[j]["qana"]));
unbom(m_part_array[j],m_qana[j],xtable);
j = j + 1;
}
return m_part_array[j];
}
}
}