Пример #1
0
        /// <summary>
        /// 单击操作列触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvOrder_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            OrderBusinessLogic orderBusinessLogic = new OrderBusinessLogic();

            //单击编辑执行的操作
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                string        orderID       = this.dgvOrder.Rows[e.RowIndex].Cells[3].Value.ToString();
                OrderEditForm orderEditForm = new OrderEditForm(orderID, user);
                orderEditForm.ShowDialog();
                this.dgvOrder.DataSource = orderBusinessLogic.GetOrderByStatus("未提交");
            }
            //单击删除执行的操作
            if (e.ColumnIndex == 1 && e.RowIndex != -1)
            {
                DialogResult result = MessageBox.Show("确定删除此订单?", "提示", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    string orderID = this.dgvOrder.Rows[e.RowIndex].Cells[3].Value.ToString();
                    orderBusinessLogic.DeleteOrderById(orderID);//删除已经做级联
                    MessageBox.Show("删除成功!");
                    this.dgvOrder.DataSource = orderBusinessLogic.GetOrderByStatus("未提交");
                }
                else
                {
                    MessageBox.Show("删除取消!");
                }
            }
            //单击提交执行的操作
            if (e.ColumnIndex == 2 && e.RowIndex != -1)
            {
                //OrderBusinessLogic orderBusinessLogic = new OrderBusinessLogic();
                DialogResult result = MessageBox.Show("确定提交此订单?", "提示", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    string orderID = this.dgvOrder.Rows[e.RowIndex].Cells[3].Value.ToString();
                    Order  order   = orderBusinessLogic.GetOrderByID(orderID);
                    order.Status    = "未审核";
                    order.InputDate = System.DateTime.Now;
                    orderBusinessLogic.UpdataOrder(order);
                    MessageBox.Show("提交成功!");
                    this.dgvOrder.DataSource = orderBusinessLogic.GetOrderByStatus("未提交");
                }
                else
                {
                    MessageBox.Show("提交取消!");
                }
            }
        }