FrmUploadServerXD.cs 14.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
/*-------------------------------------------------------------------------------------------
 * 信德服务器Http协议Post提交界面
 * 创建:杨斌 2014-07-03
 * 修改:杨斌 2014-07-04
 * ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;
using DataTable = System.Data.DataTable;

namespace SunVoteARSPPT
{
    public partial class FrmUploadServerXD : Form
    {
        public FrmUploadServerXD()
        {
            InitializeComponent();
        }

        private void FrmUploadServerXD_Load(object sender, EventArgs e)
        {
            GlobalInfo.SysLanguage.SetLanguage(this.Name, this);

            LoadSlide();

            string showMem = "text";
            cboSchool.DisplayMember = showMem;
            cboTeacher.DisplayMember = showMem;
            cboGrade.DisplayMember = showMem;
            cboClass.DisplayMember = showMem;
            cboCourse.DisplayMember = showMem;
            string valueMem = "id";
            cboSchool.ValueMember = valueMem;
            cboTeacher.ValueMember = valueMem;
            cboGrade.ValueMember = valueMem;
            cboClass.ValueMember = valueMem;
            cboCourse.ValueMember = valueMem;

            cboSchool.Enabled = false;
            cboTeacher.Enabled = false;
            cboGrade.Enabled = false;
            cboClass.Enabled = false;
            cboCourse.Enabled = false;

            btnSubmit.Enabled = false;

            LoadCourse();
            LoadSchool();

            this.Height = txtData.Top + this.Height - this.ClientSize.Height;
            txtData.Visible = false;
            btnLoad.Visible = false;

        }

        //public string PostUrl = "http://jxt.hnxind.com/interactive_teaching_interface.php";//益阳
        public string PostUrl = "http://111.22.15.70:16080/xjgl/interactive_teaching_interface.php";//望城

        public class ComboData
        {
            public string text { get; set; }
            public string id { get; set; }
        }

        private void LoadSchool()
        {
            cboSchool.Items.Clear();
            cboTeacher.Items.Clear();
            cboGrade.Items.Clear();
            cboClass.Items.Clear();
            btnSubmit.Enabled = false;

            string postData = XDHttpPost.GetXDPostData("01", "", "", "", "", "", null);
            string retData = XDHttpPost.GetPage(PostUrl, postData);

            txtData.Text = Regex.Unescape(retData);

            XDResDataSchool obj = XDHttpPost.GetXDRetObject<XDResDataSchool>(retData);

            if (obj != null)
            {
                if ((obj.retCode != null) && (obj.retCode == "00"))
                {
                    if (obj.retData != null)
                    {
                        foreach (XDData d in obj.retData)
                        {
                            cboSchool.Items.Add(new ComboData() { id = d.id, text = d.text + " " + d.id });
                        }
                    }
                }
            }

            cboSchool.Enabled = true;
        }

        private void LoadGradeTeacher()
        {
            cboTeacher.Items.Clear();
            cboGrade.Items.Clear();
            cboClass.Items.Clear();
            btnSubmit.Enabled = false;

            if (cboSchool.SelectedIndex < 0) return;
            string school = (cboSchool.SelectedItem as ComboData).id;

            string postData = XDHttpPost.GetXDPostData("02", school, "", "", "", "", null);
            string retData = XDHttpPost.GetPage(PostUrl, postData);

            txtData.Text = Regex.Unescape(retData);

            XDResDataGradeTeacher obj = XDHttpPost.GetXDRetObject<XDResDataGradeTeacher>(retData);

            if (obj != null)
            {
                if ((obj.retCode != null) && (obj.retCode == "00"))
                {
                    if (obj.retData.grades != null)
                    {
                        foreach (XDData d in obj.retData.grades)
                        {
                            cboGrade.Items.Add(new ComboData() { id = d.id, text = d.text + " " + d.id });
                        }
                    }
                    if (obj.retData.teachers != null)
                    {
                        foreach (XDDataTe d in obj.retData.teachers)
                        {
                            cboTeacher.Items.Add(new ComboData() { id = d.teachers_id, text = d.teachers_name + " " + d.teachers_id });
                        }
                    }
                }
            }

            cboTeacher.Enabled = true;
            cboGrade.Enabled = true;
        }

        private void LoadClass()
        {
            cboClass.Items.Clear();
            btnSubmit.Enabled = false;

            if (cboSchool.SelectedIndex < 0) return;
            string school = (cboSchool.SelectedItem as ComboData).id;

            if (cboGrade.SelectedIndex < 0) return;
            string grade = (cboGrade.SelectedItem as ComboData).id;

            string postData = XDHttpPost.GetXDPostData("03", school, "", grade, "", "", null);
            string retData = XDHttpPost.GetPage(PostUrl, postData);

            txtData.Text = Regex.Unescape(retData);

            XDResDataClass obj = XDHttpPost.GetXDRetObject<XDResDataClass>(retData);

            if (obj != null)
            {
                if ((obj.retCode != null) && (obj.retCode == "00"))
                {
                    if (obj.retData.classes != null)
                    {
                        foreach (XDData d in obj.retData.classes)
                        {
                            cboClass.Items.Add(new ComboData() { id = d.id, text = d.text + " " + d.id });
                        }
                    }
                }
            }

            cboClass.Enabled = true;
        }

        private void UploadData()
        {
            if (cboSchool.SelectedIndex < 0) return;
            string school = (cboSchool.SelectedItem as ComboData).id;

            if (cboClass.SelectedIndex < 0) return;
            string aClass = (cboClass.SelectedItem as ComboData).id;

            string teacher = "";
            if (cboTeacher.SelectedIndex >= 0)
                teacher = (cboTeacher.SelectedItem as ComboData).id;

            string course = cboCourse.Text;

            Dictionary<string, string> dicPoint = new Dictionary<string, string>();
            foreach (DataGridViewRow row in dgvQuestionPoint.Rows)
            {
                string point = "";
                if (row.Cells[2].Value != null)
                    point = row.Cells[2].Value.ToString();
                dicPoint.Add(row.Tag.ToString(), point);
            }

            TimerCount t = new TimerCount(); t.StartCount();
            string postData = XDHttpPost.GetXDPostData("04", school, teacher, "", aClass, course, dicPoint);
            txtData.Text = postData;
            string retData = XDHttpPost.GetPage(PostUrl, postData);
            txtData.Text += "\r\n" + t.GetCountMS() + " ms";

            XDResDataUpload obj = XDHttpPost.GetXDRetObject<XDResDataUpload>(retData);

            if (obj != null)
            {
                if (obj.retCode != null)
                    txtData.Text += "\r\n\r\n" + "retCode=" + obj.retCode + "\r\n" + obj.retMessage;
                if ((obj.retCode != null) && (obj.retCode == "00"))
                    MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "msgSubmitOK", "提交成功!"));
                else
                    MessageBox.Show(obj.retMessage);
            }
        }

        private void LoadCourse()
        {
            cboCourse.Items.Clear();
            cboCourse.Items.Add("语文");
            cboCourse.Items.Add("数学");
            cboCourse.Items.Add("英语");
            cboCourse.Items.Add("物理");
            cboCourse.Items.Add("化学");
            cboCourse.Items.Add("地理");
            cboCourse.Items.Add("生物");
            cboCourse.Items.Add("历史");
            cboCourse.Items.Add("政治");
            cboCourse.Enabled = true;
        }

        private void EnabledSubmit()
        {
            btnSubmit.Enabled = false;
            if (cboSchool.SelectedIndex < 0) return;
            //if (cboTeacher.SelectedIndex < 0) return;
            if (cboGrade.SelectedIndex < 0) return;
            if (cboClass.SelectedIndex < 0) return;
            if (cboCourse.Text.TrimEnd().Length < 1) return;
            if (dgvQuestionPoint.Rows.Count < 1) return;
            btnSubmit.Enabled = true;
        }

        /// <summary>
        /// 查询的反馈题目类型
        /// </summary>
        private const string cResponseType = "'Choice','Order','Judge','Number','Text'";

        private void LoadSlide()
        {
            Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;
            dgvQuestionPoint.Rows.Clear();
            //int i = 0;
            //foreach (Slide sld in pres.Slides)
            //{
            //    TagSet tag = new TagSet(sld.Tags);
            //    dgvQuestionPoint.Rows.Add();
            //    DataGridViewRow row = dgvQuestionPoint.Rows[i];
            //    row.Tag = sld.SlideID;
            //    row.Cells[0].Value = sld.SlideIndex;
            //    row.Cells[1].Value = PPTOper.GetSlideTitle(sld);
            //    row.Cells[2].Value = tag.GetValue(TagKey.Slide_KnowledgePoint).Value;
            //    i++;
            //}

            //加载数据
            string sql = "Select ST_Topic.*, ST_TopicPar.TP_Value" +
                        " FROM ST_Topic INNER JOIN ST_TopicPar ON ST_Topic.T_ID = ST_TopicPar.T_ID" +
                        " WHERE (((ST_Topic.TT_ID) In (" + cResponseType + ")) AND ((ST_TopicPar.TP_Name)='CorrectAnswer') AND ((ST_TopicPar.TP_Value)<>'') AND (Len(ST_Topic.T_ID)<12))" +
                        " Order By ST_Topic.T_Index Asc";

            GlobalInfo.DBOperation.OpenDataSet(sql);
            DataTable tb = GlobalInfo.DBOperation.DataSet.Tables[0];
            int i = 0;
            for (int iRow = 0; iRow < tb.Rows.Count; iRow++)
            {
                DataRow row = tb.Rows[iRow];

                int id = ConvertOper.Convert(row["T_ID"].ToString()).ToInt;

                Slide sld = null;
                try
                {
                    sld = pres.Slides.FindBySlideID(id);
                }
                catch { }
                if (sld != null)
                {
                    TagSet tag = new TagSet(sld.Tags);

                    dgvQuestionPoint.Rows.Add();
                    DataGridViewRow gridRow = dgvQuestionPoint.Rows[i];

                    gridRow.Tag = sld.SlideID;
                    gridRow.Cells[0].Value = sld.SlideIndex;
                    gridRow.Cells[1].Value = PPTOper.GetSlideTitle(sld);//row["T_Title"].ToString();
                    gridRow.Cells[2].Value = tag.GetValue(TagKey.Slide_KnowledgePoint).Value;

                    i++;
                }
            }
            GlobalInfo.DBOperation.CloseDataSet();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            bool b = btnSubmit.Enabled;
            btnSubmit.Enabled = false;
            this.Cursor = Cursors.WaitCursor;
            UploadData();
            this.Cursor = Cursors.Default;
            btnSubmit.Enabled = b;
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            LoadSchool();
        }

        private void cboSchool_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadGradeTeacher();
            //LoadClass();
            EnabledSubmit();
        }

        private void cboGrade_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadClass();
            EnabledSubmit();
        }

        private void cboTeacher_SelectedIndexChanged(object sender, EventArgs e)
        {
            EnabledSubmit();
        }

        private void cboClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            EnabledSubmit();
        }

        private void cboCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            EnabledSubmit();
        }

        private void cboCourse_TextChanged(object sender, EventArgs e)
        {
            EnabledSubmit();
        }

        private void FrmUploadServerXD_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.D:
                    if (e.Shift)
                    {
                        txtData.Visible = true;
                        btnLoad.Visible = true;
                        this.Height = txtData.Bottom + 10 + this.Height - this.ClientSize.Height;
                    }
                    break;
            }
        }

        private void dgvQuestionPoint_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 2) && (e.RowIndex >= 0))
            {
                Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;
                DataGridViewRow row = dgvQuestionPoint.Rows[e.RowIndex];

                if (row.Cells[e.ColumnIndex].Value == null) return;
                if (row.Tag == null) return;
                int id = ConvertOper.Convert(row.Tag.ToString()).ToInt;
                Slide sld = null;
                try
                {
                    sld = pres.Slides.FindBySlideID(id);
                }
                catch { }
                if (sld == null) return;
                TagSet tag = new TagSet(sld.Tags);
                tag.SetValue(TagKey.Slide_KnowledgePoint, row.Cells[e.ColumnIndex].Value);
            }
        }

        private void dgvQuestionPoint_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 2) && (e.RowIndex >= 0))
            {
                dgvQuestionPoint.BeginEdit(true);
            }
        }
    }
}