Beispiel #1
0
        private void dgvOrderCheck_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            cellRowIndex = e.RowIndex;
            MenuBusinessLogic menuBusinessLogic = new MenuBusinessLogic();
            List <string>     menus             = new List <string>();

            if (e.ColumnIndex == 3 && e.RowIndex != -1)
            {
                if (dgvOrderCheck.Rows[e.RowIndex].Cells[3].Value != null)
                {
                    string menuname = dgvOrderCheck.Rows[e.RowIndex].Cells[3].Value.ToString();
                    menus = menuBusinessLogic.GetMenusByMenuName(menuname);
                    this.listBox1.DataSource = menus;
                    listBox1.Visible         = true;
                }
                else
                {
                    return;
                }
            }
            //输入菜品数量后自动求出金额
            if (e.ColumnIndex == 8 && e.RowIndex != -1)
            {
                double count = Convert.ToDouble(dgvOrderCheck.Rows[cellRowIndex].Cells[8].Value);
                double price = Convert.ToDouble(dgvOrderCheck.Rows[cellRowIndex].Cells[7].Value);
                double money = count * price;
                dgvOrderCheck.Rows[cellRowIndex].Cells[9].Value = money;
                computertotalMoney();
            }
        }
        //单元格编辑完成事件,用于输入菜品后同时将菜品各种属性一起填写
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            cellRowIndex = e.RowIndex;
            MenuBusinessLogic menuBusinessLogic = new MenuBusinessLogic();
            List <string>     menus             = new List <string>();

            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                if (dataGridView1.Rows[e.RowIndex].Cells[0].Value != null)
                {
                    string menuname = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    menus = menuBusinessLogic.GetMenusByMenuName(menuname);
                    this.listBox1.DataSource = menus;
                    listBox1.Visible         = true;
                }
                else
                {
                    return;
                }
            }
            //输入菜品数量后自动求出金额
            if (e.ColumnIndex == 3 && e.RowIndex != -1)
            {
                double totalMoney = 0;
                double count      = Convert.ToDouble(dataGridView1.Rows[cellRowIndex].Cells[3].Value);
                double price      = Convert.ToDouble(dataGridView1.Rows[cellRowIndex].Cells[6].Value);
                double money      = count * price;
                dataGridView1.Rows[cellRowIndex].Cells[7].Value = money;
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    if (dataGridView1.Rows[i].Cells[7].Value != null)
                    {
                        money       = Convert.ToDouble(dataGridView1.Rows[i].Cells[7].Value);
                        totalMoney += money;
                    }
                }
                this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Cells[7].Value = totalMoney.ToString();
            }
        }