//开始执行插入
        private void Btn_Click_StartInstall(object sender, RoutedEventArgs e)
        {
            if (getSubject() != "" && getQuestionType() != "" && tbxQuestion.Text != "")
            {
                QuestionClass question = new QuestionClass();
                question.id        = getMaxId();
                question.subject   = getSubject();
                question.type      = getQuestionType();
                question.chapter   = tbxChapter.Text;
                question.name      = tbxQuestion.Text;
                question.answer    = tbxAnswer.Text;
                question.diffculty = getQuestionDiffculty();
                question.anthor    = tbxIssueAnthor.Text;
                //question.datetime = DateTime.Now.ToString();
                question.account = GlobalParams.MyAccount;
                if (isShare.IsChecked == true)
                {
                    question.share = "0";
                }
                else
                {
                    question.share = "1";
                }



                MySqlConnection mycon = new MySqlConnection(con);
                mycon.Open();
                string sqlStr = "INSERT INTO `question`(`id`, `subject`, `type`, `chapter`, `name`, `answer`, `diffculty`, `anthor`, `datatime`, `account`, `share`) VALUES('"
                                + question.id + "', '" + question.subject + "', '" + question.type + "', '" + question.chapter + "', '" + question.name +
                                "', '" + question.answer + "', '" + question.diffculty + "', '" + question.anthor + "', NOW(), '" + question.account + "'," + question.share + ")";
                MySqlCommand myDataAdapter = new MySqlCommand(sqlStr, mycon);
                GlobalParams.DataRefresh = true;
                if (Xtype.Text != "")
                {
                    GlobalParams.TypeRefresh = true;
                }
                if (myDataAdapter.ExecuteNonQuery() == 1)
                {
                    MessageBox.Show("插入成功!");
                }
                else
                {
                    MessageBox.Show("插入失败!出现了未知问题~");
                }
            }
            else
            {
                MessageBox.Show("*标注的信息为必填项,请填写后重试");
            }
        }
示例#2
0
        public Alter(QuestionClass question)
        {
            InitializeComponent();

            //if (question.share == "0")
            //{
            //    isShare.IsChecked = true;
            //}
            //else
            //{
            //    isShare.IsChecked = false;
            //}
            MySqlConnection mycon = new MySqlConnection(con);

            mycon.Open();
            MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(String.Format("select share from question where id={0}", question.id), con);
            DataSet          myda          = new DataSet();

            myDataAdapter.Fill(myda, "question");
            DataTable datab = myda.Tables["question"];

            if (datab.Rows.Count != 0)
            {
                if (datab.Rows[0][0].ToString() == "0")
                {
                    isShare.IsChecked = true;
                }
                else
                {
                    isShare.IsChecked = false;
                }
            }

            this.DataContext = question;
            QC = question;
            if (QC.account == GlobalParams.MyAccount)
            {
                isShare.IsEnabled = true;
                isShare.Opacity   = 1;
                del.IsEnabled     = true;
                save.IsEnabled    = true;
            }
            else
            {
                isShare.IsEnabled = false;
                isShare.Opacity   = 0.5;
                del.IsEnabled     = false;
                save.IsEnabled    = false;
            }
        }
        //修改按钮点击事件
        private void BtnAction_Click(object sender, RoutedEventArgs e)
        {
            Button        btn      = sender as Button;
            int           idx      = int.Parse(System.Text.RegularExpressions.Regex.Split(btn.Content.ToString(), "_", System.Text.RegularExpressions.RegexOptions.IgnoreCase)[1]);
            QuestionClass question = new QuestionClass();

            question.id        = DataTable.Rows[idx][0].ToString();
            question.subject   = DataTable.Rows[idx][1].ToString();
            question.type      = DataTable.Rows[idx][2].ToString();
            question.chapter   = DataTable.Rows[idx][3].ToString();
            question.name      = DataTable.Rows[idx][4].ToString();
            question.answer    = DataTable.Rows[idx][5].ToString();
            question.diffculty = DataTable.Rows[idx][6].ToString();
            question.anthor    = DataTable.Rows[idx][7].ToString();
            question.account   = DataTable.Rows[idx][9].ToString();


            Alter alter = new Alter(question);

            alter.Show();
        }