如何添加具有相同产品数据的多个连续出版物 [英] How to add multiple serials with same data of a product

查看:62
本文介绍了如何添加具有相同产品数据的多个连续出版物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有产品信息文本框,它从列表视图中获取其价值

带有产品ID现在我希望它将该信息保存到我的MSSQL DB

i有第一个开始序列的文本框和另一个放入设定数量的文本框

i想要如果我将0001添加到串行文本框中,而将20添加到另一个文件框中它必须从0001-0020添加到我的SQL中数据库,当我保存同样的产品信息



我尝试过:



if(txtProductID.Text ==|| txtPSerial.Text ==|| txtCat.Text ==|| txtBin.Text == - || txtManufac.Text ==| | txtLocation.Text ==)

{

MessageBox.Show(填写文本框以继续。,消息,MessageBoxButtons.OK,MessageBoxIcon.Information) ;

返回;

}

其他

{

尝试

{

string sql = @INSERT INTO tblSerials VALUES(@ PID,@ Descrip,@ Serials,@ Catagory,@ Location,@ Bin,@ Manufacturer,@ Date,@ DateOUT,@ DateIN,@ Employee,@ INOUT);

//

cm = new SqlCommand(sql,cn);

cm.Parameters.AddWithValue(@ PID,txtPID3.Text);

cm.Parameters.AddWithValue(@ Descrip,txtProductID.Text);

cm.Parameters.AddWithValue(@ Serials,txtPSerial.Text);

cm.Parameters.AddWithValue(@ Catagory,txtCat.Text);

cm.Parameters.AddWithValue(@ Location,txtLocation.Text);

cm.Parameters.AddWithValue(@ Bin,txtBin.Text);

cm.Parameters.AddWithValue(@ Manufacturer,txtManufac.Text);

cm.Parameters.AddWithValue(@ Date,lblDate.Text);

cm.Parameters.AddWithValue( @DateOUT,txt1.Text);

cm.Parameters.AddWithValue(@ DateIN,txt2.Text);

cm.Parameters.AddWithValue(@ Employee ,txt3.Text);

cm.Parameters.AddWithValue(@ INOUT,txt4.Text);



cm.ExecuteNonQuery ();

MessageBox.Show(Record successfully saved!,OK!,MessageBoxButtons.OK,MessageBoxIcon.Information);

// InsertTrail();

this.Clear();

this.GetSData();

txtPSerial.Text =;







}

catch(SqlException l)

{

MessageBox.Show(再次重新输入。 ID可能已被拍摄!);

MessageBox.Show(l.Message);

}



}

}

i Have PRODUCT info text boxes which gets its values from a listview working
with a product ID now i want it to save that info to my MSSQL DB
i have a textbox for the first "Start" Serial and another textbox to put in a set amount
i want so if i add 0001 into serial textbox and 20 in the other it must Add from 0001-0020 into my SQL DB when i save With The same Product Info

What I have tried:

if (txtProductID.Text == "" || txtPSerial.Text == "" || txtCat.Text == "" || txtBin.Text == "-" || txtManufac.Text == "" || txtLocation.Text == "")
{
MessageBox.Show("Fill textboxes to proceed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
try
{
string sql = @"INSERT INTO tblSerials VALUES(@PID,@Descrip,@Serials,@Catagory,@Location,@Bin,@Manufacturer,@Date,@DateOUT,@DateIN,@Employee,@INOUT)";
//
cm = new SqlCommand(sql, cn);
cm.Parameters.AddWithValue("@PID", txtPID3.Text);
cm.Parameters.AddWithValue("@Descrip", txtProductID.Text);
cm.Parameters.AddWithValue("@Serials", txtPSerial.Text);
cm.Parameters.AddWithValue("@Catagory", txtCat.Text);
cm.Parameters.AddWithValue("@Location", txtLocation.Text);
cm.Parameters.AddWithValue("@Bin", txtBin.Text);
cm.Parameters.AddWithValue("@Manufacturer", txtManufac.Text);
cm.Parameters.AddWithValue("@Date", lblDate.Text);
cm.Parameters.AddWithValue("@DateOUT", txt1.Text);
cm.Parameters.AddWithValue("@DateIN", txt2.Text);
cm.Parameters.AddWithValue("@Employee", txt3.Text);
cm.Parameters.AddWithValue("@INOUT", txt4.Text);

cm.ExecuteNonQuery();
MessageBox.Show("Record successfully saved!", "OK!", MessageBoxButtons.OK, MessageBoxIcon.Information);
//InsertTrail();
this.Clear();
this.GetSData();
txtPSerial.Text = "";



}
catch (SqlException l)
{
MessageBox.Show("Re-input again. ID may already be taken!");
MessageBox.Show(l.Message);
}

}
}

推荐答案

Quote:

我是一个全新的编码即时学习,但这部分我坚持不知道如何去做它

Im totally new to coding im learning as i go along but this the part im stuck on and not sure how to go about it



但是,你知道如何做一个,你知道 - 我假设 - 循环是什么。

你知道如何从TextBox获取内容,你知道 - 我假设 - 如何将其转换为整数。



结合这些东西并不是一个复杂的过程!



但是......这是一个坏主意,因为SQL Server是一个多用户环境,这意味着数据的预分配是一个坏主意。为什么?因为如果两个用户决定分配相同或重叠的范围,一切都搞砸了,你会遇到重大问题 - 比如同一个串行麻木发给两个物体。

现在,您可能会说不会发生这种情况 - 但您不知道代码将在下周使用什么,明年是下一个飞蛾 - 如果您确实让多个用户进入数据(你会),然后在某些时候它会发生 - 然后它成为一个真正的PITA进行整理,因为数据库不再反映现实,你不知道发生了什么。这些事情只有在停止并采用快速修复确保数据完整性为时已晚时才会被注意到。





看看你在做什么,并考虑使用:几乎可以肯定你需要一个比这更好的方案,或者你需要一个更好的方法来分析哪些数字已经分配了一个简单的二十块方法。


But, you know how to do one, and you know - I assume - what a loop is.
You know how to get the content from a TextBox, and you know - I assume - how to convert that to an integer.

Combining those things is not a complex process!

But ... this is a bad idea, because SQL Server is a multiuser environment, which means that "preallocation" of data is a bad idea. Why? Because if two users decide to allocate the same or overlapping ranges everything gets messed up together and you get major problems - like the same serial number being issued to two objects.
Now, you may say "that won't happen" - but you have no idea what the code will be used for next week, next moth, next year - and if you do get multiple users entering data (and you will), then at some point it will happen - and then it becomes a real PITA to sort out, because the database no longer reflects reality and you have no idea what is going on. And these things are only ever noticed when it's too late to stop things and apply a "quick fix" ensuring your data integrity.


Look at what you are doing, and think about usage: it's almost certain that you need either a much better scheme than this, or you need a much better way to sort out which numbers have been allocated that a simple "block of twenty" approach.


if (txtProductID.Text == "" || txtAmount.Text == "" || txtPSerial.Text == "" || txtCat.Text == "" || txtBin.Text == "-" || txtManufac.Text == "" || txtLocation.Text == "")
            {
                MessageBox.Show("Fill textboxes to proceed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                try
                {
                    long serial = Convert.ToInt64(txtSerialStart.Text);
                    int qty = Convert.ToInt32(txtAmount.Text);
                    for(int i = 0;i < qty;i++)
                    {
                        serial = serial + i;
                        String serialX = serial.ToString();

                        string sql = @"INSERT INTO tblSerials VALUES(@PID,@Descrip,@Serials,@Catagory,@Location,@Bin,@Manufacturer,@Date)";
                        cm = new SqlCommand(sql, cn);
                        cm.Parameters.AddWithValue("@PID", txtPID3.Text);
                        cm.Parameters.AddWithValue("@Descrip", txtProductID.Text);
                        cm.Parameters.AddWithValue("@Serials", serialX);
                        cm.Parameters.AddWithValue("@Catagory", txtCat.Text);
                        cm.Parameters.AddWithValue("@Location", txtLocation.Text);
                        cm.Parameters.AddWithValue("@Bin", txtBin.Text);
                        cm.Parameters.AddWithValue("@Manufacturer", txtManufac.Text);
                        cm.Parameters.AddWithValue("@Date", lblDate.Text);

                        cm.ExecuteNonQuery();
                    }

                    MessageBox.Show("Record successfully saved!", "OK!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //InsertTrail();
                    this.Clear();
                    this.GetSData();
                    txtPSerial.Text = "";



                }
                catch (SqlException l)
                {
                    MessageBox.Show("Re-input again. ID may already be taken!");
                    MessageBox.Show(l.Message);
                }


这篇关于如何添加具有相同产品数据的多个连续出版物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆