📄 formjhyw.cs
字号:
this.textBox7.Text = this.dataGridView2.CurrentRow.Cells[5].Value.ToString();
}
}
//*********退出************
private void toolStripButton5_Click(object sender, EventArgs e)
{
DialogResult dlg = MessageBox.Show("您确实要退出当前应用程序吗?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlg == DialogResult.Yes)
{
this.Close();
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
idx = this.tabControl1.SelectedIndex;
if (idx == 1)
{
this.txtJHBH_1.Text = this.txtJHBH.Text;
this.txtJHBH_1.Enabled = false;
this.textBox4.Text = m.ToString();
this.textBox4.Enabled = false;
}
}
//****************************提交****************************
//提交进货总表
private void button1_Click(object sender, EventArgs e)
{
this.toolStripButton6.Enabled = true;
this.toolStripButton7.Enabled = true;
ds.Clear();
if (idx == 0)
{
if (this.txtJHBH.Text != "" && this.textBox2.Text != "" && this.textBox3.Text != "")
{
if (this.dataGridView1.Rows.Count == 0)
{
ds.Tables[0].Rows.Add(0, 0, 0, 0, 0);
this.dataGridView1.Rows[0].Cells[0].Value = this.txtJHBH.Text;
this.dataGridView1.Rows[0].Cells[1].Value = this.textBox2.Text;
this.dataGridView1.Rows[0].Cells[2].Value = this.textBox3.Text;
this.dataGridView1.Rows[0].Cells[3].Value = this.dtp1.Text;
this.dataGridView1.Rows[0].Cells[4].Value = this.cboJsr.Text;
}
//在保存到数据库之前,只能在总表中增加一条记录;点保存后,可以再次提交
this.button1.Enabled = false;
i++;
MessageBox.Show("提交成功,请录入进货单详情!", "请增加详情", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.btn.Enabled = true;
this.button6.Enabled = true;
this.tabControl1.SelectedTab = this.tabPage2; //跳转到tabPage2
this.txtJHBH_1.Text = this.txtJHBH.Text;
for (int j = 0; j < this.dataGridView2.Rows.Count; j++)
{
this.dataGridView2.Rows[j].Cells[1].Value = this.txtJHBH.Text;
}
}
else
{
MessageBox.Show("数据不完整,请检查!", "数据为空", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
//提交进货详情表
private void button3_Click(object sender, EventArgs e)
{
this.toolStripButton6.Enabled = true;
this.toolStripButton7.Enabled = true;
if (this.txtJHBH_1.Text != "" && this.comboBox1.Text != "" && this.comboBox2.Text != "" && this.textBox6.Text != "" && this.textBox7.Text != "")
{
for (int j = 0; j < this.dataGridView2.Rows.Count; j++)
{
//如果 供应商编号、商品编号和进价 都相同,则不允许提交,只能修改该商品
if (this.dataGridView2.Rows[j].Cells[3].Value.ToString() == comboBox2.Text && this.dataGridView2.Rows[j].Cells[2].Value.ToString() == this.comboBox1.Text && this.dataGridView2.Rows[j].Cells[5].Value.ToString() == this.textBox7.Text)
{
if (MessageBox.Show("进货的商品<来自同一个供应商> 在网格中已存在,本程序将*自动修改*网格中的该商品,确定?", "商品已存在", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
//修改进货数量
this.dataGridView2.Rows[j].Cells[4].Value = Convert.ToInt32(this.dataGridView2.Rows[j].Cells[4].Value) + Convert.ToInt32(this.textBox6.Text);
//修改进货金额
this.dataGridView2.Rows[j].Cells[6].Value = Convert.ToInt32(this.dataGridView2.Rows[j].Cells[6].Value) + Convert.ToInt32(this.textBox6.Text) * Convert.ToDecimal(this.textBox7.Text);
this.dataGridView2.Rows[j].Cells[7].Value = "累加: 因为增加的商品<相同进价 且 来自同一供应商> 在网格中存在,所以本系统自动做了累加!";
MessageBox.Show("进货详情修改成功!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Information);
i++;
this.textBox4.Text = m.ToString();
this.textBox6.Text = "";
this.textBox7.Text = "";
this.textBox8.Text = "";
this.comboBox1.Text = "";
this.comboBox2.Text = "";
}
return;
}
}
ds1.Tables[0].Rows.Add(this.textBox4.Text, this.txtJHBH_1.Text, this.comboBox1.Text, this.comboBox2.Text, this.textBox6.Text, this.textBox7.Text, Convert.ToInt32(this.textBox6.Text) * Convert.ToDecimal(this.textBox7.Text), this.textBox8.Text);
m++;
this.textBox4.Text = m.ToString();
this.textBox6.Text = "";
this.textBox7.Text = "";
this.textBox8.Text = "";
this.comboBox1.Text = "";
this.comboBox2.Text = "";
}
else
{
MessageBox.Show("数据不完整,请检查!", "数据为空", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//***********显示进货总表**********
private void button2_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("select jhDjID '进货单据编号',jhSpZsl '进货商品总数量', jhZje '进货总金额', jhRq '进货日期',jhJsr '经手人' from jhzBiao ", con);
ds.Clear();
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
this.toolStripButton6.Enabled = false;
this.toolStripButton7.Enabled = false;
}
//********************时间的设置********************//
private void timer1_Tick(object sender, EventArgs e)
{
this.statusStrip1.Items[0].Text = "当前时间:" + DateTime.Now.ToString();
}
//*********核对功能**************//
private void button5_Click(object sender, EventArgs e)
{
int sum1 = 0;
decimal sum2 = 0;
foreach (DataGridViewRow row in this.dataGridView2.Rows)
{
sum1 += Convert.ToInt32(row.Cells[4].Value.ToString());
sum2 += Convert.ToDecimal(row.Cells[6].Value.ToString());
}
if (Convert.ToInt32(this.dataGridView1.Rows[0].Cells[1].Value.ToString()) == sum1 && Convert.ToInt32(this.dataGridView1.Rows[0].Cells[2].Value.ToString()) == sum2)
{
MessageBox.Show("进货总表和详表的数据一致,请保存到数据库!", "数据一致", MessageBoxButtons.OK, MessageBoxIcon.Information);
toolStripButton1.Enabled = true;
toolStripButton6.Enabled = false; //禁止删除
toolStripButton7.Enabled = false; //禁止修改
toolStripButton9.Enabled = false; //禁止刷新
}
else
{
MessageBox.Show("进货总表和详表的数据不一致,请检查!", "数据不一致", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//************显示总表的信息**********//
private void button6_Click(object sender, EventArgs e)
{
if (this.txtJHBH.Text != "" && this.textBox2.Text != "" && this.textBox3.Text != "")
{
ds.Clear();
ds.Tables[0].Rows.Add(0, 0, 0, 0, 0);
this.dataGridView1.Rows[0].Cells[0].Value = this.txtJHBH.Text;
this.dataGridView1.Rows[0].Cells[1].Value = this.textBox2.Text;
this.dataGridView1.Rows[0].Cells[2].Value = this.textBox3.Text;
this.dataGridView1.Rows[0].Cells[3].Value = this.dtp1.Text;
this.dataGridView1.Rows[0].Cells[4].Value = this.cboJsr.Text;
this.toolStripButton6.Enabled = true;
this.toolStripButton7.Enabled = true;
}
}
//定义一个限制字符和小数点的方法
public void inputNO(object sender, KeyPressEventArgs e)
{
TextBox ka = (TextBox)sender;//将文本框对象付给了当前的文本
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8 && e.KeyChar != '.')
{
e.Handled = true;
}
else if (e.KeyChar == '.')
{
if (ka.Text.IndexOf('.') >= 0)//如果已有小数点存在,则不能再输入小数点
e.Handled = true;//禁止文本框的第一个字符为'.'
else if (ka.Text.Length == 0)
e.Handled = true;
}
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox kk = new TextBox();
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8 && e.KeyChar != '.')
{
e.Handled = true;
}
else if (e.KeyChar == '.')
{
if (kk.Text.IndexOf('.') >= 0) //如果已经有小数点存在,则不能再输入小数点
e.Handled = true;
//如果小数点不存在,但是文本框没有任何字符,则也禁用'.'
//禁止文本框的第一个字符为'.'
else if (kk.Text.Length == 0)
e.Handled = true;
}
if (kk.Text.Contains("."))
{
if (kk.Text.Substring(kk.Text.IndexOf('.')).Length > 2 && (int)e.KeyChar != 8)
{
e.Handled = true;
}
}
}
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
{
inputNO(sender, e);
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8)
{
e.Handled = true;
}
}
private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8)
{
e.Handled = true;
}
}
private void comboBox1_Leave(object sender, EventArgs e)
{
com.Connection = con;
com.CommandText = "select gysID from ghsBiao where gysID='" + comboBox1.Text + "'";
dr = com.ExecuteReader();
if (dr.Read())
{
dr.Close();
}
else
{
dr.Close();
MessageBox.Show("对不起您输入的供应商编号不存在。");
ds.Clear();
this.comboBox1.Text = "";
comboBox1.Focus();
}
}
private void comboBox2_Leave(object sender, EventArgs e)
{
com.Connection = con;
com.CommandText = "select spID from spxqBiao where spID='" + comboBox2.Text + "'";
dr = com.ExecuteReader();
if (dr.Read())
{
dr.Close();
}
else
{
dr.Close();
MessageBox.Show("对不起您输入的商品编号不存在。");
ds.Clear();
this.comboBox2.Text = "";
comboBox2.Focus();
}
}
private void textBox3_Leave(object sender, EventArgs e)
{
if (this.textBox3.Text.Contains(".")!=true)
{
this.textBox3.Text += @".00";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -