我发送我的销售退货模型代码检查它并给我这个代码的解决方案因为当我运行这个代码时有很多逻辑错误例如当我返回两个项目然后这些项目数量应该保存在我的数据库中但它仅在数据库中保存一个项目数量,并且这些项目数量将添加到库存中。
代码:
public partial class SalesReturn : Sample2
{
selection s = new selection();
insertion i = new insertion();
updation u = new updation();
Hashtable ht = new Hashtable();
float amountRefund = 0;
int proQty;
int returedQty;
public SalesReturn()
{
InitializeComponent();
}
Regex rg = new Regex("^[0-9]+$");
private void LoadBtn_Click(object sender, EventArgs e)
{
if (saleIDTxt.Text != "")
{
if(rg.Match(saleIDTxt.Text).Success)
{
try
{
s.showSalesdataViaID(Convert.ToInt64(saleIDTxt.Text), dataGridView1, proIDGV, proGV, salesIDGV, qtyGV, totdisGV, barGV, amtgivenGV, amtreturnGV, dateGV, priceGV, perprodisGV, perprototalGV, userGV, cashtypeGV, totamtGV);
dateTimePicker.Value = Convert.ToDateTime(dataGridView1.Rows[0].Cells["dateGV"].Value.ToString());
userTxt.Text = dataGridView1.Rows[0].Cells["userGV"].Value.ToString();
paymentTxt.Text = dataGridView1.Rows[0].Cells["cashtypeGV"].Value.ToString();
}
catch(Exception ex)
{
MainClass.showMSG(ex.Message, "Error", "Error");
}
}
else
{
saleIDTxt.Text = "";
saleIDTxt.Focus();
dateTimePicker.Value = DateTime.Now;
userTxt.Text = "";
paymentTxt.Text = "";
}
}
else
{
saleIDTxt.Text = "";
saleIDTxt.Focus();
dateTimePicker.Value = DateTime.Now;
userTxt.Text = "";
paymentTxt.Text = "";
}
}
private void SalesReturn_Load(object sender, EventArgs e)
{
base.editBtn.Enabled = false;
base.deleteBtn.Enabled = false;
base.addBtn.Enabled = false;
}
public override void saveBtn_Click(object sender, EventArgs e)
{
if (refundTxt.Text != "" && ht.Count > 0 && saleIDTxt.Text != "")
{
DialogResult dr = MessageBox.Show("Are you sure, you want to proceed?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dr==DialogResult.Yes)
{
using (TransactionScope sr = new TransactionScope())
{
int x=0;
foreach (DictionaryEntry de in ht)
{
x += i.insertSalesRefund(Convert.ToInt64(de.Key), Convert.ToInt64(saleIDTxt.Text), Convert.ToInt16(de.Value), Convert.ToSingle(refundTxt.Text), DateTime.Now, selection.USER_ID);
int currentQty = (int)s.showProductQty(Convert.ToInt64(de.Key));
int finalQty = currentQty + Convert.ToInt16(de.Value);
u.updateStock(Convert.ToInt64(de.Key), finalQty);
}
if (x > 0)
{
DialogResult drr = MainClass.showMSG("Return And Refund Successfull", "Success", "Success");
if(drr==DialogResult.OK)
{
SaleReturnReceipt srr = new SaleReturnReceipt();
srr.Show();
}
x = 0;
ht.Clear();
}
dataGridView1.Rows.Clear();
sr.Complete();
}
}
}
else
{
MainClass.showMSG("Please provide complete details...", "Error", "Error");
}
}
private void barTxt_Validating(object sender, CancelEventArgs e)
{
if(barTxt.Text!="")
{
if (dataGridView1.Rows.Count > 0)
{
using (TransactionScope sr = new TransactionScope())
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (barTxt.Text == row.Cells["barGV"].Value.ToString())
{
DialogResult dr = MessageBox.Show("Are you sure, you want to return "+ row.Cells["proGV"].Value.ToString()+"?","Question....",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(dr==DialogResult.Yes)
{
Int64 proID = Convert.ToInt64(row.Cells["proIDGV"].Value.ToString());
float proPrice = Convert.ToSingle(row.Cells["priceGV"].Value.ToString());
proQty = Convert.ToInt32(row.Cells["qtyGV"].Value.ToString()) -1;
amountRefund += proPrice;
refundTxt.Text = Math.Round(amountRefund,0).ToString();
if(proQty==0)
{
if (ht.ContainsKey(row.Cells["proIDGV"].Value))
{
Int64 proIDht = Convert.ToInt64(row.Cells["proIDGV"].Value.ToString());
ht[proIDht] = Convert.ToInt32(ht[proIDht]) - 1;
}
else
{
ht.Add(row.Cells["proIDGV"].Value.ToString(), 1);
}
dataGridView1.Rows.Remove(row);
}
else
{
ht.Clear();
row.Cells["qtyGV"].Value = proQty;
row.Cells["perprototalGV"].Value = Convert.ToSingle(row.Cells["perprototalGV"].Value.ToString()) - Convert.ToSingle(row.Cells["priceGV"].Value.ToString());
if (ht.ContainsKey(row.Cells["proIDGV"].Value))
{
Int64 proIDht = Convert.ToInt64(row.Cells["proIDGV"].Value.ToString());
ht[proIDht] = Convert.ToInt32(ht[proIDht]) + 1;
}
else
{
ht.Add(row.Cells["proIDGV"].Value.ToString(), 1);
}
}
}
break;
}
}
sr.Complete();
}
}
}
}
}
}