Ejemplo n.º 1
0
        private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView1.EndEdit();
            // comboBox1.Focus();
            try
            {
                decimal hjzl = 0;
                for (int i = 0; i < dataGridView1.SelectedCells.Count; i++)
                {
                    hjzl += decimal.Parse(dataGridView1.SelectedCells[i].Value.ToString());
                }
                label14.Text = hjzl.ToString();
            }
            catch { }

            try
            {
                if (comboBox1.Text.Trim() != "")
                {
                    if (dataGridView1.CurrentCell.ColumnIndex == 1)
                    {
                        if (!Globals.CheckNumber(dataGridView1.CurrentRow.Cells["zl"].Value.ToString().Trim()))
                        {
                            MessageBox.Show("请输入数字");
                            dataGridView1.CurrentRow.Cells["zl"].Value = null;
                            return;
                        }

                        else if (dataGridView1.CurrentRow.Cells["barcode"].Value == null)
                        {
                            dataGridView1.CurrentRow.Cells["barcode"].Value = comboBox1.SelectedValue.ToString().PadLeft(5, '0') + DateTime.Now.Year.ToString().Substring(2, 2) + Globals.get_tmlsh(conn).PadLeft(5, '0');

                            dataGridView1.CurrentRow.Cells["cd"].Value = decimal.Parse(Math.Floor(decimal.Parse(dataGridView1.CurrentRow.Cells["zl"].Value.ToString()) / decimal.Parse(bl.Text)).ToString()); //计算重量

                            dataGridView1.CurrentRow.Cells["wlmc"].Value = comboBox1.Text;
                        }
                        DataRow[] drArr = dt1.Select("fname = '" + comboBox2.Text + "'");
                        if (dataGridView1.CurrentRow.Cells["fck"].Value == null)
                        {
                            dataGridView1.CurrentRow.Cells["fck"].Value  = comboBox2.Text;
                            dataGridView1.CurrentRow.Cells["fcw"].Value  = comboBox3.Text;
                            dataGridView1.CurrentRow.Cells["cknm"].Value = drArr[0]["FItemID"].ToString();;
                            dataGridView1.CurrentRow.Cells["cwnm"].Value = comboBox3.SelectedValue;

                            dataGridView1.CurrentRow.Cells["frkrq"].Value = dateTimePicker1.Text;
                            dataGridView1.CurrentRow.Cells["fscrq"].Value = dateTimePicker2.Text;

                            dataGridView1.CurrentRow.Cells["gysmc"].Value = gys.Text;
                            dataGridView1.CurrentRow.Cells["gysid"].Value = FSupplyID.Text;
                            dataGridView1.CurrentRow.Cells["rkdh"].Value  = textBox1.Text;
                            dataGridView1.CurrentRow.Cells["Fhjph"].Value = label16.Text;
                            dataGridView1.CurrentRow.Cells["Fxh"].Value   = xh.Text.Trim();
                            dataGridView1.CurrentRow.Cells["wlnm"].Value  = comboBox1.SelectedValue;
                            dataGridView1.CurrentRow.Cells["fpc"].Value   = pici.Text;
                        }
                    }
                }
                else
                {
                    dataGridView1.CurrentCell = dataGridView1[1, dataGridView1.CurrentCell.RowIndex];
                    MessageBox.Show("先选择物料");
                }
            }
            catch {
            }
        }
Ejemplo n.º 2
0
        private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter & dataGridView1.CurrentCell.ColumnIndex == 1)//是否选择的是第6个单元格
                {
                    if (!Globals.CheckNumber(dataGridView1.CurrentRow.Cells["zl"].Value.ToString().Trim()))
                    {
                        MessageBox.Show("请输入数字");
                        dataGridView1.CurrentRow.Cells["zl"].Value = null;
                        return;
                    }

                    else if (dataGridView1.CurrentRow.Cells["barcode"].Value == null)
                    {
                        dataGridView1.CurrentRow.Cells["barcode"].Value = comboBox1.SelectedValue.ToString().PadLeft(5, '0') + DateTime.Now.Year.ToString().Substring(2, 2) + Globals.get_tmlsh(conn).PadLeft(5, '0');

                        //  dataGridView1.CurrentRow.Cells["cd"].Value = int.Parse(Math.Floor(decimal.Parse(dataGridView1.CurrentRow.Cells["zl"].Value.ToString()) / decimal.Parse(bl.Text) * 1000000).ToString());//计算重量

                        dataGridView1.CurrentRow.Cells["cd"].Value = decimal.Parse(Math.Floor(decimal.Parse(dataGridView1.CurrentRow.Cells["zl"].Value.ToString()) / decimal.Parse(bl.Text)).ToString());//计算重量

                        dataGridView1.CurrentRow.Cells["wlmc"].Value = comboBox1.Text;
                    }
                    DataRow[] drArr = dt1.Select("fname = '" + comboBox2.Text + "'");

                    if (dataGridView1.CurrentRow.Cells["fck"].Value == null)
                    {
                        dataGridView1.CurrentRow.Cells["fck"].Value   = comboBox2.Text;
                        dataGridView1.CurrentRow.Cells["fcw"].Value   = comboBox3.Text;
                        dataGridView1.CurrentRow.Cells["cknm"].Value  = drArr[0]["FItemID"].ToString();;
                        dataGridView1.CurrentRow.Cells["cwnm"].Value  = comboBox3.SelectedValue;
                        dataGridView1.CurrentRow.Cells["frkrq"].Value = dateTimePicker1.Text;
                        dataGridView1.CurrentRow.Cells["fscrq"].Value = dateTimePicker2.Text;

                        dataGridView1.CurrentRow.Cells["gysmc"].Value = gys.Text;
                        dataGridView1.CurrentRow.Cells["gysid"].Value = FSupplyID.Text;
                        dataGridView1.CurrentRow.Cells["rkdh"].Value  = textBox1.Text;
                        dataGridView1.CurrentRow.Cells["Fhjph"].Value = label16.Text;
                        dataGridView1.CurrentRow.Cells["Fxh"].Value   = xh.Text.Trim();
                        dataGridView1.CurrentRow.Cells["wlnm"].Value  = comboBox1.SelectedValue;
                        dataGridView1.CurrentRow.Cells["fpc"].Value   = pici.Text;
                    }
                }



                if (e.KeyCode == Keys.Enter & dataGridView1.CurrentCell.ColumnIndex == 2)//是否选择的是第6个单元格
                {
                    if (!Globals.CheckNumber(dataGridView1.CurrentRow.Cells["cd"].Value.ToString().Trim()))
                    {
                        MessageBox.Show("请输入数字");
                        dataGridView1.CurrentRow.Cells["cd"].Value = null;
                        return;
                    }
                }

                // dataGridView1.CurrentCell = dataGridView1[1, dataGridView1.CurrentCell.RowIndex];
            }
            catch {
                MessageBox.Show("请选择料号");
            }
        }