Beispiel #1
0
        private void textBox2_DoubleClick(object sender, EventArgs e)
        {
            OrderSelect OS = new OrderSelect();

            OS.ShowDialog();
            textBox2.Text = order;
        }
Beispiel #2
0
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.ColumnIndex == dataGridView1.Columns["訂單編號"].Index && dataGridView1.CurrentRow.IsNewRow)
            {
                OrderSelect os = new OrderSelect();
                os.ShowDialog();
                if (order == null)
                {
                    return;
                }
                try
                {
                    dataGridView1.AllowUserToAddRows = false;
                    scheduleBs.AddNew();
                    dataGridView1["訂單編號", e.RowIndex].Value = order;
                    dataGridView1.AllowUserToAddRows        = true;
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.Columns["數量"].Index, e.RowIndex];
                    order = null;
                }
                catch
                {
                    dataGridView1.Rows.RemoveAt(e.RowIndex);
                    dataGridView1.AllowUserToAddRows = true;
                }
                if (irow != new int())
                {
                    DataRow dr;
                    dataGridView1["品號", e.RowIndex].Value = irow;
                    dr = myds.Tables["產品資料表"].Rows.Find(dataGridView1["品號", e.RowIndex].Value.ToString());
                    dataGridView1["品名", e.RowIndex].Value     = dr["品名"];
                    dataGridView1["規格", e.RowIndex].Value     = dr["規格"];
                    dataGridView1["單價", e.RowIndex].Value     = dr["單價"];
                    dataGridView1["目前庫存數量", e.RowIndex].Value = dr["庫存量"].ToString();
                    dataGridView1["需求數量", e.RowIndex].Value   = needed;
                    dataGridView1.AllowUserToAddRows          = true;
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.Columns["數量"].Index, e.RowIndex];
                    _irow = new int();
                }
            }

            else if (e.ColumnIndex == dataGridView1.Columns["訂單編號"].Index)
            {
                OrderSelect os = new OrderSelect();
                os.ShowDialog();

                if (order == null)
                {
                    return;
                }
                dataGridView1["訂單編號", e.RowIndex].Value = order;
                if (irow != new int())
                {
                    DataRow dr;
                    dataGridView1["品號", e.RowIndex].Value = irow;
                    dr = myds.Tables["產品資料表"].Rows.Find(dataGridView1["品號", e.RowIndex].Value.ToString());
                    dataGridView1["品名", e.RowIndex].Value     = dr["品名"];
                    dataGridView1["規格", e.RowIndex].Value     = dr["規格"];
                    dataGridView1["單價", e.RowIndex].Value     = dr["單價"];
                    dataGridView1["目前庫存數量", e.RowIndex].Value = dr["庫存量"].ToString();
                    dataGridView1["需求數量", e.RowIndex].Value   = needed;
                    dataGridView1.AllowUserToAddRows          = true;
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.Columns["數量"].Index, e.RowIndex];
                    _irow = new int();
                }
            }
            else if (e.ColumnIndex == dataGridView1.Columns["品號"].Index && dataGridView1.CurrentRow.IsNewRow)
            {
                ProductSelect fm = new ProductSelect();
                DataRow       dr;
                fm.ShowDialog();
                try
                {
                    dataGridView1.AllowUserToAddRows = false;
                    scheduleBs.AddNew();
                    dataGridView1[e.ColumnIndex, e.RowIndex].Value = irow;
                    dr = myds.Tables["產品資料表"].Rows.Find(dataGridView1["品號", e.RowIndex].Value.ToString());
                    dataGridView1["品名", e.RowIndex].Value     = dr["品名"];
                    dataGridView1["規格", e.RowIndex].Value     = dr["規格"];
                    dataGridView1["單價", e.RowIndex].Value     = dr["單價"];
                    dataGridView1["目前庫存數量", e.RowIndex].Value = dr["庫存量"].ToString();
                    dataGridView1.AllowUserToAddRows          = true;
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.Columns["數量"].Index, e.RowIndex];
                    _irow = new int();
                }
                catch
                {
                    dataGridView1.Rows.RemoveAt(e.RowIndex);
                    dataGridView1.AllowUserToAddRows = true;
                }
            }
            else if (e.ColumnIndex == dataGridView1.Columns["品號"].Index)
            {
                ProductSelect fm = new ProductSelect();
                fm.ShowDialog();
                if (!dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString().Equals(_irow.ToString()))
                {
                    DataRow dr = myds.Tables["銷貨單明細資料表"].NewRow();
                    int     old;
                    int     old2;
                    try
                    {
                        old = int.Parse(myds.Tables["銷貨單明細資料表"].Rows[e.RowIndex]["品號"].ToString());
                    }
                    catch
                    {
                        old = 0;
                    }
                    try
                    {
                        old2 = int.Parse(myds.Tables["銷貨單明細資料表"].Rows[e.RowIndex]["數量"].ToString());
                    }
                    catch
                    {
                        old2 = 0;
                    }
                    dr["品號"] = _irow;
                    myds.Tables["銷貨單明細資料表"].Rows.Add(dr);
                    try
                    {
                        dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
                        dr = myds.Tables["產品資料表"].Rows.Find(dataGridView1["品號", e.RowIndex].Value.ToString());
                        dataGridView1["品名", e.RowIndex].Value     = dr["品名"];
                        dataGridView1["規格", e.RowIndex].Value     = dr["規格"];
                        dataGridView1["單價", e.RowIndex].Value     = dr["單價"];
                        dataGridView1["目前庫存數量", e.RowIndex].Value = dr["庫存量"].ToString();
                        _irow = new int();
                    }
                    catch
                    {
                        dr       = myds.Tables["銷貨單明細資料表"].NewRow();
                        dr["品號"] = old;
                        myds.Tables["銷貨單明細資料表"].Rows.Add(dr);
                        dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
                        dr = myds.Tables["產品資料表"].Rows.Find(dataGridView1["品號", e.RowIndex].Value.ToString());
                        if (old2 != 0)
                        {
                            dataGridView1["數量", e.RowIndex].Value = old2;
                        }
                        try
                        {
                            dataGridView1["品名", e.RowIndex].Value     = dr["品名"];
                            dataGridView1["規格", e.RowIndex].Value     = dr["規格"];
                            dataGridView1["單價", e.RowIndex].Value     = dr["單價"];
                            dataGridView1["目前庫存數量", e.RowIndex].Value = dr["庫存量"].ToString();
                        }
                        catch
                        {
                        }
                        _irow = new int();
                    }
                }
            }
        }