|
 |
|
ใครพอจะมีแนวคิดหรือ ตัวอย่างการทำสต๊อคสินค้าบ้างครับ |
|
 |
|
|
 |
 |
|
การตัดสต็อกของผมคือ เอาจำนวนสต็อกไป ลบ กับจำนวนสินค้าที่ขายไปในขณะนั้น โค้ดที่ผมเขียนคือ แอดข้อมูลลงบิล พร้อมทั้งตัดสต็อกกันไปในทั้งครั้งเดียวเลย การตัดสต็อกคือการ Update ข้อมูล ผมจะให้ตัวอย่างโค้ด คุณเอาไปประยุกต์เอานะครับ การเซฟลงบิลของผมมันอยู่อีก เมธอดนึง คุณคงทำได้ แค่ การ INSERT INTO เท่านั้น แค่จะอยากในการจอยตารางกันเฉยๆ
Code (C#)
private void btnadd_Click(object sender, EventArgs e)
{
if ((txtAmount.Text == "0") || (txtAmount.Text == "") || (txtDiscount.Text == "") || (txtWage.Text == "") || (cmbProName.Text == "เลือกชื่อสินค้า") || (cmbCarID.Text == "เลือกทะเบียนรถ") || (txtRepair.Text == "") || (txtRepair.Text == "เลือกวันที่"))
{
MessageBox.Show("คุณกรอกข้อมูลไม่ครบ", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (Convert.ToDecimal(txtAmount.EditValue) < 0)
{
MessageBox.Show("โปรดระบุเป็นจำนวนเต็มบวก", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (Convert.ToDecimal(txtWage.EditValue) < 0)
{
MessageBox.Show("โปรดระบุค่าแรงเป็นจำนวนเต็มบวก", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (Convert.ToDecimal(txtDiscount.EditValue) > 100)
{
MessageBox.Show("โปรดระบุส่วนลดให้น้อยกว่า 100", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
string sql2; string ProName = ""; string InStock = ""; int unitNumInStock;
int unitOrderBox; int unitsResult;
string constr = Properties.Settings.Default.DatabaseCarserviceConnectionString;
OleDbConnection conn = new OleDbConnection(constr);
sql2 = "Select [Product].Pro_Name_Model ,[Product].InStock From [Product] Where [Product].Pro_ID = '" + txtProID.Text + "'";
OleDbCommand cmd = new OleDbCommand(sql2, conn);
try
{
this.Cursor = Cursors.WaitCursor;
conn.Open();
OleDbDataReader render = cmd.ExecuteReader();
while (render.Read())
{
ProName = render.GetValue(0).ToString();
InStock = render.GetValue(1).ToString();
}
conn.Close();
this.Cursor = Cursors.Default;
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Exception");
this.Cursor = Cursors.Default;
}
unitOrderBox = Convert.ToInt32(txtAmount.Text);
unitNumInStock = Convert.ToInt32(InStock);
if (unitNumInStock == 0)
{
MessageBox.Show("สินค้าที่คุณเลือกหมดสต็อกแล้ว ", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
if (Convert.ToDecimal(txtDiscount.EditValue) < 0)
{
MessageBox.Show("โปรดระบุส่วนลดเป็นจำนวนเต็มบวก", "Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (unitNumInStock > unitOrderBox)
{
unitsResult = unitNumInStock - unitOrderBox;
dbm.SqlCom = "UPDATE Product Set InStock = InStock - '" + unitOrderBox + "' Where Pro_ID = '" + txtProID.Text + "'";
dbm.ExeSql();
Add();
MessageBox.Show("สินค้า " + ProName + " เหลือใน Stock " + unitsResult + " ชิ้น","Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (unitNumInStock < unitOrderBox)
{
unitsResult = unitOrderBox - unitNumInStock;
MessageBox.Show("สินค้า " + ProName + " เหลือใน Stock ไม่พอขาย","Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (unitNumInStock == unitOrderBox)
{
dbm.SqlCom = "UPDATE Product Set InStock = InStock - '" + unitOrderBox + "' Where Pro_ID = '" + txtProID.Text + "'";
dbm.ExeSql();
Add();
MessageBox.Show("สินค้า " + ProName + " ใน Stock หมดพอดี","Check", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
// gridView1.Columns[5].Summary.Add(DevExpress.Data.SummaryItemType.Sum, "");
//}
}
}
#endregion
|
 |
 |
 |
 |
Date :
2012-09-07 22:59:57 |
By :
peteyothin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|