コード例 #1
0
        private void toolSave_Click(object sender, EventArgs e)
        {
            if (getIntCount() == 1)
            {
                if (intFalg == 1)
                {
                    try
                    {
                        if (StockDAL.add(stock))
                        {
                            LogInfoDAL.add(new LogInfo(0, 1, currentUser.EmpId, 1, stock.Num, stock.AddTime));
                            MessageBox.Show("添加成功", "提示");
                            BinddgvData();
                        }
                        else
                        {
                            MessageBox.Show("添加失败", "提示");
                        }


                        intFalg = 0;

                        ClearControl();
                        ControlStaus();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("添加失败," + ex.Message, "提示");
                    }
                }
                if (intFalg == 2)
                {
                    //修改
                    Stock model = StockDAL.getEntryById <Stock, DateTime>(stock.AddTime);
                    if (model == null)
                    {
                        MessageBox.Show("记录不存在", "提示");
                    }
                    else
                    {
                        stock.AddTime = model.AddTime;
                        StockDAL.EditEntry <Stock>(stock, "AddTime");
                        LogInfoDAL.add(new LogInfo(0, 1, currentUser.EmpId, 2, stock.Num - model.Num, DateTime.Now));
                        MessageBox.Show("修改成功", "提示");
                        BinddgvData();
                    }
                    intFalg = 0;
                    ClearControl();
                    ControlStaus();
                }
                if (intFalg == 3)
                {
                    Stock model = StockDAL.getEntryById <Stock, DateTime>(stock.AddTime);
                    if (model == null)
                    {
                        MessageBox.Show("记录不存在", "提示");
                    }
                    else
                    {
                        if (MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            LogInfoDAL.add(new LogInfo(0, 1, currentUser.EmpId, 3, model.Num, DateTime.Now));
                            StockDAL.DeleteEntry <Stock, DateTime>(model.AddTime);
                            MessageBox.Show("删除成功", "提示");
                            BinddgvData();
                        }
                    }

                    intFalg = 0;
                    ClearControl();
                    ControlStaus();
                }
            }
        }