public void UpdateGameInDB(TextBox txt, NumericUpDown up)
        {
            try
            {
                int gameIDs      = 0;
                int gameToUpdate = 0;
                try
                {
                    gameToUpdate = Convert.ToInt32(txt.Text);
                }
                catch (Exception)
                {
                    ErrorForm frm = new ErrorForm();
                    frm.ShowDialog();
                    //MessageBox.Show("That's not a number!","Please Scan Again!", MessageBoxButtons.OK);
                }

                int    valueFromIncrementor = Convert.ToInt32(up.Value);
                string gameOutput;

                SqlConnection con = new SqlConnection();
                con.ConnectionString = @"Data Source=.\SQLExpress;" +
                                       "User Instance=true;" +
                                       "Integrated Security=true;" +
                                       @"AttachDbFilename=|DataDirectory|\Test_Game_DB.mdf;";
                con.Open();
                SqlCommand update = new SqlCommand(
                    "update Games SET InStock = (InStock + @value)  WHERE GameID = @Code and GameName not like '" + "" + "' ;", con);
                update.Parameters.AddWithValue("@Code", gameToUpdate);
                update.Parameters.AddWithValue("@value", valueFromIncrementor);
                update.Parameters.AddWithValue("@idCheck", gameIDs);

                SqlCommand gameName = new SqlCommand(
                    "select gamename from games where gameid = @Code", con);
                gameName.Parameters.AddWithValue("@Code", gameToUpdate);
                gameOutput = gameName.ExecuteScalar().ToString();
                if (gameToUpdate >= 1)
                {
                    update.ExecuteNonQuery();
                    MessageBox.Show(gameOutput + " was Added!", " Success!", MessageBoxButtons.OK);
                    Form.ActiveForm.Close();
                    con.Close();
                }
            }
            catch (Exception)
            {
                Form.ActiveForm.Close();
            }
        }
Example #2
0
 //这个按钮按下时,将触发检查事件,要根据AnswerText和ExeText获取文件路径
 private void skinButton1_Click_1(object sender, EventArgs e)
 {
     try {
         string    ExePath    = ExeText.Text;
         string    AnswerPath = AnswerText.Text;
         Configure con        = new Configure(CoreMode.CheckMode);
         con.Calc(ExePath, AnswerPath);
         DisGradeBox.Text += "成绩已经生成到" + ReadXml("//Path//Grade") + Environment.NewLine;
     }
     catch (MyException.OwnException e1)
     {
         ErrorForm form = new ErrorForm(e1.Message);
         form.ShowDialog();
     }
 }
Example #3
0
 public void Generate()
 {
     try
     {
         Configure con = new Configure(CoreMode.ExerciseMode);
         con.Calc();
     }
     catch (MyException.TooManyException e1)
     {
         ErrorForm form = new ErrorForm(e1.Message);
         form.ShowDialog();
     }
     finally
     {
         InvokeCall a = new InvokeCall(UpdateProgressBar);
         BeginInvoke(a);
     }
 }
Example #4
0
 public void Generate()
 {
     try
     {
         Configure con = new Configure(CoreMode.ExerciseMode);
         con.Calc();
     }
     catch (MyException.TooManyException e1)
     {
         ErrorForm form = new ErrorForm(e1.Message);
         form.ShowDialog();
     }
     finally
     {
         //这里注意一开始的允许跨线程操纵UI
         GenProgressIndicator.Hide();
         ExeAnsTextBox.Text += "已经生成了" + ReadXml("//Count//FactCount") + "道题目与答案到指定的文件中." + Environment.NewLine;
         ExeAnsTextBox.Show();
     }
 }
Example #5
0
 public void Generate()
 {
     try
     {
         Configure con = new Configure(CoreMode.ExerciseMode);
         con.Calc();
     }
     catch (MyException.TooManyException e1)
     {
         ErrorForm form = new ErrorForm(e1.Message);
         form.ShowDialog();
     }
     finally
     {
         //这里注意一开始的允许跨线程操纵UI
         GenProgressIndicator.Hide();
         ExeAnsTextBox.Text += "已经生成了" + ReadXml("//Count//FactCount") + "道题目与答案到指定的文件中."+Environment.NewLine;
         ExeAnsTextBox.Show();
     }
 }
Example #6
0
 //打开答案文件,并且判断文件后缀是否为txt文件,如果不是txt文件,则抛出异常。
 private void AnswerButton_Click(object sender, EventArgs e)
 {
     try
     {
         string         path   = "";
         OpenFileDialog Dialog = new OpenFileDialog();
         DialogResult   result = Dialog.ShowDialog();
         if ((result == DialogResult.OK) || (result == DialogResult.Yes))
         {
             path = Dialog.FileName;
             if (!path.EndsWith(".txt"))
             {
                 throw new FileNotFoundException("文件后缀不正确,请重新打开!");
             }
             AnswerText.Text = path;
         }
     }
     catch (Exception e1)
     {
         ErrorForm error = new ErrorForm(e1.Message);
         error.ShowDialog();//show Dialog指定只能关闭本模块后才可以关闭其他
     }
 }
Example #7
0
        private void calcButtonResult_Click(object sender, EventArgs e)
        {
            //这里应该调用计算核心中的计算单个表达式的值,并显示在该TextBox中
            /////////////////////////////////////////
            // single calc expression              //
            /////////////////////////////////////////
            string Content = calcTextBox.Text;

            try
            {
                Configure con = new Configure(CoreMode.CalcuateMode);
                Content = con.Calc(calcTextBox.Text + "=");
            }
            catch (MyException.OwnException e1)
            {
                ErrorForm form = new ErrorForm(e1.Message);
                form.ShowDialog();
            }
            finally
            {
                calcTextBox.Text = Content;
            }
        }
Example #8
0
        //这个按钮按下时,将触发检查事件,要根据AnswerText和ExeText获取文件路径
        private void skinButton1_Click_1(object sender, EventArgs e)
        {
            try {
                string ExePath = ExeText.Text;
                string AnswerPath = AnswerText.Text;
                Configure con = new Configure(CoreMode.CheckMode);
                con.Calc(ExePath, AnswerPath);
                DisGradeBox.Text += "成绩已经生成到" + ReadXml("//Path//Grade") + Environment.NewLine;

            }
            catch (MyException.OwnException e1)
            {
                ErrorForm form = new ErrorForm(e1.Message);
                form.ShowDialog();
            }
        }
Example #9
0
 //打开题目文件,并且判断文件后缀是否为txt文件,如果不是txt文件,则抛出异常。
 private void ExeButton_Click(object sender, EventArgs e)
 {
     try
     {
         string path = "";
         OpenFileDialog Dialog = new OpenFileDialog();
         DialogResult result = Dialog.ShowDialog();
         if ((result == DialogResult.OK) || (result == DialogResult.Yes))
         {
             path = Dialog.FileName;
             if (!path.EndsWith(".txt"))
                 throw new FileNotFoundException("文件后缀不正确,请重新打开!");
             ExeText.Text = path;
         }
     }
     catch (Exception e1)
     {
         ErrorForm error = new ErrorForm(e1.Message);
         error.ShowDialog();//show Dialog指定只能关闭本模块后才可以关闭其他
     }
 }
Example #10
0
 private void calcButtonResult_Click(object sender, EventArgs e)
 {
     //这里应该调用计算核心中的计算单个表达式的值,并显示在该TextBox中
     /////////////////////////////////////////
     // single calc expression              //
     /////////////////////////////////////////
     string Content = calcTextBox.Text;
     try
     {
         Configure con = new Configure(CoreMode.CalcuateMode);
         Content = con.Calc(calcTextBox.Text + "=");
     }
     catch(MyException.OwnException e1)
     {
         ErrorForm form = new ErrorForm(e1.Message);
         form.ShowDialog();
     }
     finally
     {
         calcTextBox.Text = Content;
     }
 }
        public void ApplyTrade(TextBox Code, ListView lst)
        {
            try
            {
                float         tradeValueOut;
                SqlConnection con = new SqlConnection();
                con.ConnectionString = @"Data Source=.\SQLExpress;" +
                                       "User Instance=true;" +
                                       "Integrated Security=true;" +
                                       @"AttachDbFilename=|DataDirectory|\Test_Game_DB.mdf;";
                con.Open();

                int gameToUpdate = 0;
                try
                {
                    if (Code.Text != "")
                    {
                        gameToUpdate = Convert.ToInt32(Code.Text);
                    }
                    else
                    {
                        gameToUpdate = 0;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("ktmk");
                }

                SqlCommand customerTrade = new SqlCommand(
                    "select TradeValue from TradeValues where CustomerID like @Code;", con);
                customerTrade.Parameters.AddWithValue("@Code", gameToUpdate);
                if (customerTrade != null)
                {
                    tradeValueOut = (float)Convert.ToDouble(customerTrade.ExecuteScalar());
                    MessageBox.Show(tradeValueOut.ToString());
                }
                else
                {
                    tradeValueOut = 0;
                }

                if (tradeValueOut >= TotalPrice)
                {
                    tradeValueOut -= this.TotalPrice;
                    TotalPrice     = 0;
                    // tradeValueOut -= this.TotalPrice;
                    SqlCommand TradeUpdate = new SqlCommand(
                        "UPDATE TradeValues set TradeValue = @trade where CustomerID = @Code;", con);
                    TradeUpdate.Parameters.AddWithValue("@Code", gameToUpdate);
                    TradeUpdate.Parameters.AddWithValue("@trade", tradeValueOut);
                    TradeUpdate.ExecuteNonQuery();
                }
                else
                {
                    this.TotalPrice -= tradeValueOut;
                    SqlCommand TradeUpdate = new SqlCommand(
                        "UPDATE TradeValues set TradeValue = 0 where CustomerID = @Code;", con);
                    TradeUpdate.Parameters.AddWithValue("@Code", gameToUpdate);
                    TradeUpdate.ExecuteNonQuery();
                }
                con.Close();
                lst.Items.Add("- $" + tradeValueOut.ToString());
                lst.Items.Add("$" + TotalPrice.ToString());
            }
            catch (Exception)
            {
                ErrorForm frm = new ErrorForm();
                frm.ShowDialog();
            }
        }