using StuMgmLib.MyNameSpace;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StuMgmClient
{
    public partial class SelectFrom : Form
    {
        DataRow dr = null;
        short t_job_id;
        int t_token;
        int stateNum;
        public SelectFrom(DataRow drView, short job_id, int toKen)
        {
            InitializeComponent();
            dr=drView;
            t_job_id = job_id;
            t_token = toKen;
        }
        private void SelectFrom_Load(object sender, EventArgs e)
        {
            ShowData(dr);
        }
        //数据回显
        public void ShowData(DataRow dr)
        {
            short idState = Convert.ToInt16((dr["id"]));
            stateNum = (int)dr["Statu"];
            MssionPower(stateNum);
            txtMsg.Text = dr["Content"].ToString();
            label2.Text =dr["name"].ToString();
            lblState.Text = Utility.InitState(stateNum);

            //try
            //{
            //    lblTime.Text = Convert.ToDateTime(dr["Time"]).ToString("yyyy-MM-dd");
            //}
            //catch 
            //{
            //    lblTime.Text = "";
            //}
        }
        //提交事件
        private void btnSumit_Click(object sender, EventArgs e)
        {

            DialogResult result = MessageBox.Show("是否确定提交", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
                short idState = Convert.ToInt16((dr["id"]));
              SystemData.allCourseStatus[idState]=(CourseStatusEnum)2;
                UserCourseInfoOper o = new UserCourseInfoOper();
                o.Job_Id = t_job_id;
                o.Token = t_token;
                Utility.DicParsing(SystemData.allCourseStatus);
                o.Status = Utility.DicParsing(SystemData.allCourseStatus);
                if (SystemCtrl.SendUserCourseInfoOper(o) != ErrCode.Success)
                    MessageBox.Show("提交失败，请联系管理员", "提示");
                MessageBox.Show("提交成功，可预习下一阶段内容", "提示");
                lblState.Text = "待验收";
                btnSumit.Visible = false;
                //this.Dispose();
            }
        }


        //状态值改变控件
        public void MssionPower(int state)
        {
            //任务权限
            switch (stateNum)
            {
                case 0:
                    dr["Content"] = "当前不可查看";
                    lblTime.Text = "未开始";
                    lblState.Text = "未开始";
                    btnSumit.Visible = false;
                    break;
                case 1:
                    btnSumit.Visible = true;
                    break;
                case 2:
                case 3:
                case 4:
                     btnSumit.Visible = false;
                     break;
            }
        } 
    }
}
