private async Task ContentDialogshow()
        {
            ContentDialog contentDialog = new ContentDialog
            {
                Title               = "确认提交回答?",
                PrimaryButtonText   = "确认提交",
                SecondaryButtonText = "不提交"
            };

            contentDialog.PrimaryButtonClick += async(_s, _e) =>
            {
                Answer answer;
                string answertext = MyAnswer.Text;
                int    Qusitionid = 0;
                if (answerDraft == null)
                {
                    answer = new Model.Answer
                    {
                        Userid        = Userid,
                        Qusitionid    = qusition.Qusitionid,
                        AnswerContent = answertext,
                    };
                    Qusitionid = qusition.Qusitionid;
                }
                else
                {
                    answer = new Answer
                    {
                        Userid        = people.UserId,
                        Qusitionid    = answerDraft.Qid,
                        AnswerContent = answertext,
                    };
                    Qusitionid = answerDraft.Qid;
                }
                answer.UpAnsTime = answer.AnswerTime = DateTime.Now;
                var temp = await GetisAnswer(Userid, Qusitionid);

                if (temp == true)
                {
                    await SubUPAnswer(answer);
                }
                else
                {
                    await SubAnswers(answer);
                }
            };
            contentDialog.SecondaryButtonClick += (_s, _e) =>
            {
            };
            await contentDialog.ShowAsync();
        }
Esempio n. 2
0
        private void edit()
        {
            string ques = this.txtQues.Text;

            if (ques.Trim().Length == 0)
            {
                if (MessageBox.Show("Bạn có chắc câu hỏi sẽ trống?", "Xác Nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    this.txtQues.Focus();
                    this.txtQues.Select();
                    return;
                }
            }

            int num_right = get_num_right_ans();

            if (num_right == 0)
            {
                MessageBox.Show("Các câu trả lời không thể trống và có ít nhất 1 câu đúng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //update question
            Controller.QuestionController.update(this.idques, ques, num_right);

            //delete answer
            if (this.lsIdAnsDelete.Count > 0)
            {
                foreach (var i in lsIdAnsDelete)
                {
                    Controller.AnswerController.delete(i);
                }
            }

            //update old answer, insert new answer
            var data = convert_dgv_to_dt();

            foreach (DataRow row in data.Rows)
            {
                if (Convert.ToInt32(row["id"]) == -1)//insert
                {
                    Controller.AnswerController.insert(row["content"].ToString(), this.idques, Convert.ToInt32(row["true_or_false"]));
                }
                else//update
                {
                    Model.Answer ans = new Model.Answer(Convert.ToInt32(row["id"]), row["content"].ToString(), this.idques, Convert.ToInt32(row["true_or_false"]));
                    Controller.AnswerController.update(ans);
                }
            }
        }
        private async Task SubUPAnswer(Model.Answer answer)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("applocation/json"));
            var content = new StringContent(JsonConvert.SerializeObject(answer), Encoding.UTF8, "application/json");
            HttpResponseMessage httpResponseMessage = await httpClient.PostAsync("http://localhost:60671/api/answer/Updateanswer", content);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                var res = await httpResponseMessage.Content.ReadAsAsync <bool>();

                if (res == true)
                {
                    Frame.Navigate(typeof(AnswerQusition), answer.Qusitionid);
                }
            }
        }
        private async Task SubAnswers(Model.Answer answer)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var content = new StringContent(JsonConvert.SerializeObject(answer), Encoding.UTF8, "application/json");
            HttpResponseMessage httpResponseMessage = await httpClient.PostAsync("http://localhost:60671/api/answer/addanswer", content);

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                var res = await httpResponseMessage.Content.ReadAsAsync <bool>();

                if (res == true)
                {
                    SubAnswer.Content      = "已回答";
                    SubAnswer.IsEnabled    = false;
                    CancelAnswer.IsEnabled = false;
                    AnswerQusition.Current.qusition.Answerednum++;
                    answershow = new Answershow
                    {
                        Qusitionid    = answer.Qusitionid,
                        Userid        = answer.Userid,
                        AnswerContent = answer.AnswerContent,
                        AnswerTime    = answer.AnswerTime,
                        UpAnsTime     = answer.UpAnsTime,
                        UpAnsnum      = answer.UpAnsnum,
                        DownAnsnum    = answer.DownAnsnum,
                        AnsCmtnum     = answer.AnsCmtnum,
                        Name          = people.Name,
                        QName         = qusition.QusitionTitle
                    };
                    AnswerQusition.Current.answers.Add(answershow);
                    Frame.GoBack();
                }
                else
                {
                }
            }
        }
Esempio n. 5
0
 public Model.Question ToModel()
 {
     Model.Answer[] answers = new Model.Answer[Answers.Length + 1];
     answers[0] = new Model.Answer()
     {
         IsCorrect = true,
         Text      = Answer
     };
     for (int i = 0; i < Answers.Length; i++)
     {
         answers[i + 1] = new Model.Answer()
         {
             IsCorrect = false,
             Text      = Answers[i]
         };
     }
     Model.Question question = new Model.Question()
     {
         QuestionStr = Question,
         TopicId     = this.TopicId,
         Answers     = answers,
     };
     return(question);
 }
Esempio n. 6
0
        public static bool update(Model.Answer ans)
        {
            int result = DataProvider.sqlExecuteNonQuery("UPDATE `answers` SET `content`= @content , `id_ques`= @id_ques , `true_or_false`= @tf WHERE `id` = @id ", new object[] { ans.Content, ans.Id_ques, ans.True_or_false, ans.Id });

            return(result > 0);
        }
Esempio n. 7
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (checkConnect)
            {
                return;
            }
            if (validate())
            {
                int size;
                sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                try
                {
                    sck.Connect(IPAddress.Parse(txtIpServer.Text), Convert.ToInt32(txtPort.Text));
                }
                catch (SocketException ex)
                {
                    MessageBox.Show(ex.ToString(), "Có lỗi xảy ra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sck.Close();
                    return;
                }

                this.Width        = 620;
                btnClose.Location = new Point(290, 4);
                PanelTransition.ShowSync(panelProcess);
                checkConnect = true;

                try
                {
                    data = new byte[1024];

                    size = sck.Receive(data);//size server transfer

                    processBar.MaxValue = Convert.ToInt32(Encoding.ASCII.GetString(data, 0, size));

                    sendDone();

                    data = new byte[1024];
                    size = sck.Receive(data);//object para
                    Controller.ParaObject para = new Controller.ParaObject(data);
                    Controller.Constant.time = para.Time * 60;

                    processBar.Value += size;
                    processBar.Update();

                    sendDone();

                    if (para.GetDB > 0)
                    {
                        for (int i = 0; i < para.GetDB; i++)
                        {
                            data = new byte[1024];
                            size = sck.Receive(data);
                            Model.Question ques = new Model.Question(data);
                            lsquesDB.Add(ques);
                            processBar.Value += size;
                            processBar.Update();
                            sendDone();
                        }
                        size = sck.Receive(data);
                        int countAns = Convert.ToInt32(Encoding.ASCII.GetString(data, 0, size));
                        sendDone();

                        for (int i = 0; i < countAns; i++)
                        {
                            data = new byte[1024];
                            size = sck.Receive(data);
                            Model.Answer ans = new Model.Answer(data);
                            lsansDB.Add(ans);
                            processBar.Value += size;
                            processBar.Update();
                            sendDone();
                        }
                    }

                    if (para.GetFile > 0)
                    {
                        for (int i = 0; i < para.GetFile; i++)
                        {
                            data = new byte[1024];
                            size = sck.Receive(data);
                            Model.Question ques = new Model.Question(data);
                            lsquesFile.Add(ques);
                            processBar.Value += size;
                            processBar.Update();
                            sendDone();
                        }
                        size = sck.Receive(data);
                        int countAns = Convert.ToInt32(Encoding.ASCII.GetString(data, 0, size));
                        sendDone();

                        for (int i = 0; i < countAns; i++)
                        {
                            data = new byte[1024];
                            size = sck.Receive(data);
                            Model.Answer ans = new Model.Answer(data);
                            lsansFile.Add(ans);
                            processBar.Value += size;
                            processBar.Update();
                            sendDone();
                        }
                    }
                }
                catch (SocketException ex)
                {
                    MessageBox.Show(ex.ToString(), "Có lỗi xảy ra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sck.Close();
                    return;
                }

                var ls = joinList();
                this.quesList = ls.Item1;
                this.ansList  = ls.Item2;

                btnStartQuiz.Visible = true;

                listen = new Thread(new ThreadStart(threadListen));
                listen.IsBackground = true;
                listen.Start();
            }
            else
            {
                MessageBox.Show("Bạn phải điền đủ thông tin!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 8
0
        /*public static int write(string link, int row, Controller.ObjectClient obj)
         * {
         *  // Khởi động chtr Excell
         *  Excel.Application exApp = new Excel.Application();
         *
         *
         *  // Thêm file hay open
         *  Excel.Workbook exBook = (link == string.Empty) ? exApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet) : exApp.Workbooks.Open(link);
         *
         *  // Lấy sheet 1.
         *  Excel.Worksheet exSheet = (Excel.Worksheet)exBook.Worksheets[1];
         *
         *  //exSheet.Name = "Lập trình mạng";
         *
         *
         *  // Range là ô [1,1] (A1)
         *  Excel.Range code = (Excel.Range)exSheet.Cells[row, 1];
         *  Excel.Range name = (Excel.Range)exSheet.Cells[row, 2];
         *  Excel.Range class_str = (Excel.Range)exSheet.Cells[row, 3];
         *
         *  // Ghi dữ liệu
         *  code.Value2 = obj.Code;
         *  name.Value2 = obj.Name;
         *  class_str.Value2 = obj.Class_str;
         *
         *  // Giãn cột
         *  code.Columns.AutoFit();
         *  name.Columns.AutoFit();
         *  class_str.Columns.AutoFit();
         *
         *
         *  exApp.DisplayAlerts = false;
         *
         *  exBook.SaveAs(link, Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
         *
         *  exBook.Close(false, false, false);
         *  exApp.Quit();
         *  System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook);
         *
         *  return row++;
         * }*/



        private static void addToList(Excel.Worksheet xlWorksheet, object[,] valueArray)
        {
            if (lsIdQuesInListObj.Count > 0)
            {
                ListObj.deleteFile();
                lsIdQuesInListObj.Clear();
            }

            List <Model.Question> lsques = new List <Model.Question>();
            List <Model.Answer>   lsans  = new List <Model.Answer>();

            //id ques of file k ổn lắm
            int idquesfile = QuestionController.get_last_id() + 50;

            for (int row = 1; row <= xlWorksheet.UsedRange.Rows.Count; row++)//đọc row hiện có trong Excel
            {
                string ques_content = "";
                try
                {
                    ques_content = valueArray[row, 1].ToString();
                }
                catch
                {
                    continue;
                }

                int num_ans_right = 0;

                if (checkHasTrue(row, xlWorksheet, valueArray))
                {
                    for (int colum = 2; colum <= xlWorksheet.UsedRange.Columns.Count; colum = colum + 2)//đọc colum trong Excel
                    {
                        string ans_content = "";
                        int    tf          = 0;
                        try
                        {
                            ans_content = valueArray[row, colum].ToString();
                            string str_tf = valueArray[row, colum + 1].ToString();
                            switch (str_tf)
                            {
                            case "True": tf = 1; num_ans_right++; break;

                            case "False": tf = 0; break;

                            default: tf = 0; break;
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }

                        Model.Answer ans = new Model.Answer(ans_content, idquesfile, tf);
                        lsans.Add(ans);
                    }
                }

                if (num_ans_right != 0 && ques_content != "")
                {
                    Model.Question ques = new Model.Question(idquesfile, ques_content, num_ans_right);
                    lsques.Add(ques);
                    lsIdQuesInListObj.Add(idquesfile);
                    idquesfile++;
                }
            }

            Controller.ListObj.addWithFile(lsques, lsans);
        }
Esempio n. 9
0
 public AnswerVM()
 {
     this.answer = new Model.Answer();
 }
Esempio n. 10
0
 public AnswerVM(Model.Answer answer)
 {
     // TODO: Complete member initialization
     this.answer = answer;
 }