using BLL;
using System;
namespace FineUIPro.Web.TestRun.DriverRun
{
    public partial class DriverRunView : PageBase
    {
        /// 
        /// 办理类型
        /// 
        public string State
        {
            get
            {
                return (string)ViewState["State"];
            }
            set
            {
                ViewState["State"] = value;
            }
        }
        #region 加载
        /// 
        /// 页面加载
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BLL.UnitService.InitUnitDownList(this.drpUnitId, this.CurrUser.LoginProjectId, true);
                ListItem[] list1 = new ListItem[3];
                list1[0] = new ListItem("未开始", "1");
                list1[1] = new ListItem("进行中", "2");
                list1[2] = new ListItem("已完成", "3");
                this.drpStatus.DataTextField = "Text";
                this.drpStatus.DataValueField = "Value";
                this.drpStatus.DataSource = list1;
                this.drpStatus.DataBind();
                Funs.FineUIPleaseSelect(this.drpStatus);
                ListItem[] list2 = new ListItem[3];
                list2[0] = new ListItem("低", "1");
                list2[1] = new ListItem("中", "2");
                list2[2] = new ListItem("高", "3");
                this.drpPriority.DataTextField = "Text";
                this.drpPriority.DataValueField = "Value";
                this.drpPriority.DataSource = list2;
                this.drpPriority.DataBind();
                Funs.FineUIPleaseSelect(this.drpPriority);
                BLL.UnitWorkService.InitUnitWorkDropDownList(this.drpUnitWorkIds, this.CurrUser.LoginProjectId, true);
                string id = Request.Params["id"];
                if (!string.IsNullOrEmpty(id))
                {
                    Model.DriverRun_DriverRun data = BLL.DriverRunService.GetDriverRunById(id);
                    if (data != null)
                    {
                        var dt = DriverRunApproveService.getListData(id);
                        gvApprove.DataSource = dt;
                        gvApprove.DataBind();
                        this.hdId.Text = id;
                        this.txtCode.Text = data.Code;
                        if (!string.IsNullOrEmpty(data.UnitId))
                        {
                            this.drpUnitId.SelectedValue = data.UnitId;
                        }
                        this.drpUnitWorkIds.SelectedValueArray = data.InstallationId.Split(',');
                        this.txtDescriptions.Text = data.Descriptions;
                        this.txtObjective.Text = data.Objective;
                        if (data.NeedCompletedDate != null)
                        {
                            this.txtNeedCompletedDate.Text = string.Format("{0:yyyy-MM-dd}", data.NeedCompletedDate);
                        }
                        if (data.RealCompletedDate != null)
                        {
                            this.txtRealCompletedDate.Text = string.Format("{0:yyyy-MM-dd}", data.RealCompletedDate);
                        }
                        if (!string.IsNullOrEmpty(data.Status))
                        {
                            this.drpStatus.SelectedValue = data.Status;
                        }
                        if (!string.IsNullOrEmpty(data.Priority))
                        {
                            this.drpPriority.SelectedValue = data.Priority;
                        }
                        if (!string.IsNullOrEmpty(data.State))
                        {
                            State = data.State;
                        }
                        else
                        {
                            State = BLL.Const.DriverRun_Compile;
                        }
                    }
                }
                else
                {
                    State = Const.DriverRun_Compile;
                }
            }
        }
        #endregion
        #region 附件上传
        /// 
        /// 附件上传
        /// 
        /// 
        /// 
        protected void btnAttach_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.hdId.Text))   //新增记录
            {
                this.hdId.Text = SQLHelper.GetNewID(typeof(Model.DriverRun_DriverRun));
            }
            PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/TestRun/DriverRun/DriverRun&menuId={1}", this.hdId.Text, BLL.Const.DriverRunMenuId)));
        }
        #endregion
        /// 
        /// 把状态转换代号为文字形式
        /// 
        /// 
        /// 
        protected string ConvertState(object state)
        {
            if (state != null)
            {
                if (state.ToString() == BLL.Const.DriverRun_Compile)
                {
                    return "编制";
                }
                else if (state.ToString() == BLL.Const.DriverRun_Audit1)
                {
                    return "开车负责人审批";
                }
                else if (state.ToString() == BLL.Const.DriverRun_Audit2)
                {
                    return "保运主任审批";
                }
                else if (state.ToString() == BLL.Const.DriverRun_Audit3)
                {
                    return "保运主任确认完成";
                }
                else if (state.ToString() == BLL.Const.DriverRun_Audit4)
                {
                    return "开车负责人确认完成";
                }
                else if (state.ToString() == BLL.Const.DriverRun_Complete)
                {
                    return "流程闭环";
                }
                else
                {
                    return "";
                }
            }
            return "";
        }
    }
}