📄 sellform.cs
字号:
m_txtgoodscode.Text = "";
command.Connection.Close();
}
catch(SqlException ex)
{
string s = ex.ToString();
}
}
private void TotalMoneyCal()
{
double totalmoney = 0.0;
for (int i = 0; i < m_goodsList.Items.Count; i++ )
{
totalmoney = totalmoney + System.Convert.ToDouble(m_goodsList.Items[i].SubItems[6].Text);
}
NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;
nfi.NumberDecimalDigits = 2;
m_txtTotalMoney.Text = totalmoney.ToString("N",nfi);
}
private void m_goodsList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(m_goodsList.SelectedItems.Count > 0)
{
m_txtGoodsInfoCode.Text = m_goodsList.SelectedItems[0].SubItems[1].Text;
m_txtGoodsInfoName.Text = m_goodsList.SelectedItems[0].SubItems[2].Text;
m_txtGoodsInfoPrice.Text = m_goodsList.SelectedItems[0].SubItems[3].Text;
m_txtGoodsInfoRemark.Text = m_goodsList.SelectedItems[0].SubItems[7].Text;
m_txtGoodsInfoNumber.Text =m_goodsList.SelectedItems[0].SubItems[4].Text;
m_labelGoodsUnit.Text = m_goodsList.SelectedItems[0].SubItems[5].Text;
m_txtGoodsInfoStock.Text = m_goodsList.SelectedItems[0].SubItems[8].Text;
}
}
private void m_txtGoodsInfoNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar != 13 && e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
{
e.Handled = true;
}
if (e.KeyChar == 13 )
{
int num = 1;
if(m_txtGoodsInfoNumber.Text !="")
{
num =System.Convert.ToInt32(m_txtGoodsInfoNumber.Text);
}else{
MessageBox.Show("出售商品数量不能为空!");
return;
}
int stocknum = System.Convert.ToInt32( m_txtGoodsInfoStock.Text);
if(num > stocknum)
{
MessageBox.Show("该商品库存不足!");
return ;
}
if(m_goodsList.SelectedItems.Count > 0)
{
NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;
nfi.NumberDecimalDigits = 2;
m_goodsList.SelectedItems[0].SubItems[4].Text = num.ToString();
double total = System.Convert.ToDouble(m_goodsList.SelectedItems[0].SubItems[3].Text)* num;
m_goodsList.SelectedItems[0].SubItems[6].Text = total.ToString("N",nfi);
TotalMoneyCal();
}
}
}
private void m_goodsList_Leave(object sender, System.EventArgs e)
{
this.m_goodsList.SelectedItems[0].BackColor= System.Drawing.Color.FromArgb(48,106,196);
this.m_goodsList.SelectedItems[0].ForeColor= System.Drawing.Color.White;
pre_sel = this.m_goodsList.SelectedItems[0].Index;
}
private void m_goodsList_Enter(object sender, System.EventArgs e)
{
if(this.pre_sel >= 0)
{
this.m_goodsList.Items[pre_sel].BackColor= System.Drawing.Color.White;
this.m_goodsList.Items[pre_sel].ForeColor= System.Drawing.Color.Black;
}
}
private void m_bntCancelGoods_Click(object sender, System.EventArgs e)
{
if(m_goodsList.SelectedItems.Count > 0)
{
if(DialogResult.Yes==MessageBox.Show(this, "确定删除该商品", "警告", MessageBoxButtons.YesNo))
{ m_goodsList.SelectedItems[0].Remove(); }
}
}
private void m_chkIsDebt_CheckedChanged(object sender, System.EventArgs e)
{
if(m_chkIsDebt.Checked)
{
this.m_txtCustomName.Enabled = true;
this.m_txtDebtMoney.Enabled =true;
m_bntBrowse.Enabled =true;
this.m_txtDebtMoney.Text = this.m_txtTotalMoney.Text;
}
else{
this.m_txtCustomName.Enabled = false;
this.m_txtDebtMoney.Enabled =false;
m_bntBrowse.Enabled = false;
this.m_txtDebtMoney.Text = "0.00";
}
}
private void m_bntSell_Click(object sender, System.EventArgs e)
{
int count = this.m_goodsList.Items.Count;
if(count == 0)
{
MessageBox.Show("商品列表中无商品出售!");
return ;
}
string cID ="",Lmoney="";
if(this.m_chkIsDebt.Checked)
{
cID = m_txtCustomName.Text;
Lmoney =m_txtDebtMoney.Text;
if(cID == "")
{
MessageBox.Show("客户名不能为空","警告");
return ;
}
if(Lmoney == "")
{
MessageBox.Show("欠款额不能为空","警告");
return ;
}
}
System.DateTime currentTime=new System.DateTime();
currentTime=System.DateTime.Now;
string saleno = currentTime.ToString("s");
saleno = saleno.Replace(":","");
saleno = saleno.Replace("-","");
saleno = saleno.Replace("T","");
SqlConnection conn = DBUtil.GetConnection();
SqlCommand command = new SqlCommand ("",conn);
command.Connection.Open();
for (int i = 0; i<count; i++)
{
ListViewItem curitem = this.m_goodsList.Items[i];
string goodsId = curitem.SubItems[10].Text;
string salePrice = curitem.SubItems[3].Text;
string saleNumber = curitem.SubItems[4].Text;
string purchasePrice = curitem.SubItems[9].Text;
string stockNum = curitem.SubItems[8].Text;
string sql = "insert into SaleRecord (GoodsID,SaleNumber,SalePrice,EmployeeID,PurchasePrice,SaleNo) values ("+
goodsId +","+ saleNumber + "," + salePrice + "," + employeeId.ToString() + "," + purchasePrice + ",'" + saleno + "')";
command.CommandText = sql;
int rows = command.ExecuteNonQuery();
if(rows > 0)
{
int stocknum=0;
string sql1 = "select StockNumber from Goods where GoodsID="+ goodsId;
command.CommandText = sql1;
SqlDataReader readerset = command.ExecuteReader();
if(readerset.Read())
{
stocknum = System.Convert.ToInt32(readerset["StockNumber"]);
}
int left = stocknum - System.Convert.ToInt32(saleNumber);
if(left < 0)
{
//to do
}
readerset.Close();
string sql2 = "update Goods set StockNumber="+ left.ToString() +" where GoodsID="+goodsId;
command.CommandText = sql2;
int row2 = command.ExecuteNonQuery();
}
}
if(this.m_chkIsDebt.Checked)
{
string sql3 ="insert into DebtBill (GuestID,ClearFlag,OperatorID,SaleNo,LackMoney) values ("+
cID + "," + "'0'," +employeeId.ToString()+ "," + saleno +","+ Lmoney +")";
command.CommandText = sql3;
int row3 = command.ExecuteNonQuery();
}
m_goodsList.Items.Clear();
infoclear();
nextGoodsID=1;
m_txtgoodscode.Text="";
m_txtTotalMoney.Text ="0.00";
m_txtgoodscode.Focus();
command.Connection.Close();
MessageBox.Show("成功出售!");
}
private void infoclear()
{
this.m_txtGoodsInfoPrice.Text = "";
this.m_txtGoodsInfoStock.Text = "";
this.m_txtGoodsInfoRemark.Text= "";
this.m_txtGoodsInfoNumber.Text = "";
this.m_txtGoodsInfoName.Text ="";
this.m_txtGoodsInfoCode.Text = "";
}
private void m_bntBrowse_Click(object sender, System.EventArgs e)
{
try
{
SqlConnection conn = DBUtil.GetConnection();
SqlCommand command = new SqlCommand ("",conn);
command.Connection.Open();
string cID = m_txtCustomName.Text;
if(cID =="")
{
MessageBox.Show("请输入客户号","警告");
return ;
}
string sql = "select * from Guest where GuestID="+cID;
command.CommandText = sql;
SqlDataReader readerset = command.ExecuteReader();
if(!readerset.Read())
{
MessageBox.Show("无效客户号,不允许赊欠!","警告");
return ;
}
else
{
string msg = "尊敬的" + readerset["GuestName"].ToString() + ",您好!";
MessageBox.Show(msg,"欢迎");
return ;
}
readerset.Close();
}
catch(SqlException ex){
MessageBox.Show("无效客户号,不允许赊欠!");
return ;
}
}
private void SellForm_Load(object sender, System.EventArgs e)
{
}
private void m_bntClearAll_Click(object sender, System.EventArgs e)
{
if(nextGoodsID > 1)
{
m_goodsList.Items.Clear();
infoclear();
nextGoodsID=1;
m_txtgoodscode.Text="";
m_txtTotalMoney.Text ="0.00";
m_txtgoodscode.Focus();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -