📄 getpriceform.cs
字号:
this.label6.Text = "备注";
//
// label5
//
this.label5.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label5.Location = new System.Drawing.Point(64, 96);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(40, 16);
this.label5.TabIndex = 4;
this.label5.Text = "售价";
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Location = new System.Drawing.Point(64, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 16);
this.label3.TabIndex = 2;
this.label3.Text = "进价";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(336, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 1;
this.label2.Text = "商品名称";
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(56, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "条形码";
//
// GetpriceForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 526);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "GetpriceForm";
this.Text = "GetpriceForm";
this.Load += new System.EventHandler(this.GetpriceForm_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.m_GoodListdataGrid)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
//定价
string saleprice=this.m_SalepriceText.Text.Trim();
string purchaseprice="0.00";
if(saleprice =="")
{
MessageBox.Show("定价不能为空");
return ;
}
int idx = m_GoodListdataGrid.CurrentRowIndex;
if(idx >= 0)
{
purchaseprice = datatable.Rows[idx][3].ToString();
}
double pprice = System.Convert.ToDouble(purchaseprice);
double sprice = System.Convert.ToDouble(saleprice);
if( pprice >= sprice )
{
MessageBox.Show("定价必须比进价高");
return ;
}
SqlCommand m_sqlInsertCommand=new SqlCommand();
m_sqlDataAdapter.InsertCommand=m_sqlInsertCommand;
m_sqlInsertCommand.Connection=m_connection;
m_sqlInsertCommand.CommandText="update Goods set SalePrice=@saleprice where GoodsCode=@goodscode";
m_sqlInsertCommand.Parameters.Add(new SqlParameter("@goodscode", SqlDbType.VarChar, 50));
m_sqlInsertCommand.Parameters["@goodscode"].Value=this.m_GoodscodeText.Text.Trim();
m_sqlInsertCommand.Parameters.Add(new SqlParameter("@saleprice", SqlDbType.SmallMoney, 4));
m_sqlInsertCommand.Parameters["@saleprice"].Value=this.m_SalepriceText.Text.Trim();
try
{
m_sqlInsertCommand.Connection.Open();
m_sqlInsertCommand.ExecuteNonQuery();
m_sqlInsertCommand.Connection.Close();
//MessageBox.Show(this,"已经成功插入一条定价信息!","正确");
reflesh();
}
catch (SqlException e1)
{
MessageBox.Show(this,e1.Message,"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
m_connection.Close();
}
}
private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
private void groupBox2_Enter(object sender, System.EventArgs e)
{
}
private void textBox4_TextChanged(object sender, System.EventArgs e)
{
}
private void GetpriceForm_Load(object sender, System.EventArgs e)
{
reflesh();
}
private void reflesh()
{
try
{
String sql ="select * from Goods where SalePrice is null order by GoodsID desc";
System.Data.DataRow datarow;
m_connection = DBUtil.GetConnection();
m_connection.Open();
SqlCommand cmd = new SqlCommand(sql, m_connection);
SqlDataReader reader = cmd.ExecuteReader();
if (datatable.Rows.Count>0)
{
datatable.Rows.Clear();
}
while (reader.Read())
{
datarow = datatable.NewRow();
datarow[0] = reader["GoodsID"].ToString();
datarow[1] = reader["GoodsCode"].ToString();
datarow[2] = reader["GoodsName"].ToString();
datarow[3] = reader["purchaseprice"].ToString();
datarow[4] = reader["saleprice"].ToString();
//datarow[5] = reader["stocknumber"].ToString();
datarow[5] = reader["unit"].ToString();
datarow[6] = reader["remark"].ToString();
datatable.Rows.Add(datarow);
}
// System.Data.DataView m_dataview = new System.Data.DataView(datatable);
m_dataview.AllowNew = false;
m_dataview.AllowEdit = false;
m_dataview.AllowDelete = false;
m_GoodListdataGrid.DataSource = m_dataview;
m_connection.Close();
if(datatable.Rows.Count> 0)
{
this.m_GoodscodeText.Text = datatable.Rows[0][1].ToString();
this.m_GoodsnameText.Text = datatable.Rows[0][2].ToString();
this.m_PurchasepriceText.Text = datatable.Rows[0][3].ToString();
this.m_SalepriceText.Text = datatable.Rows[0][4].ToString();
// this.m_StockNumber.Text = datatable.Rows[0][5].ToString();
this.m_RemarkText.Text = datatable.Rows[0][6].ToString();
pre_idx = 0;
}
}
catch(SqlException ex)
{
string s = ex.ToString();
m_connection.Close();
MessageBox.Show(s);
}
}
private void m_GoodListdataGrid_CurrentCellChanged(object sender, System.EventArgs e)
{
int idx = m_GoodListdataGrid.CurrentRowIndex;
if(idx != pre_idx)
{
this.m_GoodscodeText.Text = datatable.Rows[idx][1].ToString();
this.m_GoodsnameText.Text = datatable.Rows[idx][2].ToString();
this.m_PurchasepriceText.Text = datatable.Rows[idx][3].ToString();
this.m_SalepriceText.Text = datatable.Rows[idx][4].ToString();
// this.m_StockNumber.Text = datatable.Rows[0][5].ToString();
this.m_RemarkText.Text = datatable.Rows[idx][6].ToString();
pre_idx = idx;
}
}
private void m_SalepriceText_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar != '.' && e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
{
e.Handled = true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -