using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using HySoft.DBUtility;

namespace HySoft.BaseCallCenter.Web.workordermanage.workorder
{
    public partial class woekorderDCLedit : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string workorderid = Request.QueryString["workorderid"];//工单编号
                HDworkorderid.Value = workorderid;
                string state = Request.QueryString["state"];//工单状态
                if (state == "4")
                {
                    iframeDeal.Attributes.Add("src", "orderassign.aspx?workorderid=" + workorderid);//待指派
                }
                else if (state == "13")
                {
                    iframeDeal.Attributes.Add("src", "orderassign.aspx?workorderid=" + workorderid);//处理
                }
                else if (state == "7") 
                {
                    iframeDeal.Attributes.Add("src", "orderchuli.aspx?workorderid=" + workorderid);//处理
                }
                else if (state == "8")
                {
                    iframeDeal.Attributes.Add("src", "orderhuifu.aspx?workorderid=" + workorderid);//回访回复
                }
                else if (state == "6")
                {
                    iframeDeal.Attributes.Add("src", "orderreply.aspx?workorderid=" + workorderid);//接单
                }
                else 
                {
                    iframeDeal.Attributes.Add("src", "orderjieshu.aspx?workorderid=" + workorderid);//结单
                }
                this.GetModelValue(workorderid);
            }
        }
        /// <summary>
        /// 绑定初始值
        /// </summary>
        public void GetModelValue(string workorderid)
        {
            string sql = "select * from V_WorkOrderBase where F_WORKORDERID=" + workorderid + "";
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
            System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> baseModel = new BLL.T_Wo_WorkOrderBase().DataTableToList(dt);
            if (baseModel.Count > 0)
            {
                if (baseModel[0].F_INSTANCEID != null)
                {
                    HDintenseid.Value = baseModel[0].F_INSTANCEID.ToString();
                }
                if (baseModel[0].F_CUSTOMERNAME != null)
                {
                    F_CUSTOMERNAME.Text = baseModel[0].F_CUSTOMERNAME.ToString();
                }
                if (baseModel[0].F_CustomerNature != null)
                {
                    F_CustomerNature.Text = baseModel[0].F_CustomerNature.ToString();
                }
                if (baseModel[0].F_CUSTOMERID != null)
                {
                    F_CUSTOMERID.Text = baseModel[0].F_CUSTOMERID.ToString();
                }
                if (baseModel[0].F_ServiceDept != null)
                {
                    F_ServiceDept.Text = baseModel[0].F_ServiceDept.ToString();
                }
                //if (baseModel[0].F_CustomerClass != null)
                //{
                //    F_CustomerClass.Text = baseModel[0].F_CustomerClass.ToString();
                //}
                if (baseModel[0].F_REPAIRLEVEL != null)
                {
                    F_REPAIRLEVEL.Text = baseModel[0].F_REPAIRLEVEL.ToString();
                }
                if (baseModel[0].F_SystemStartTime != null)
                {
                    F_SystemStartTime.Text = baseModel[0].F_SystemStartTime.ToString();
                }
                if (baseModel[0].F_CREATEDATE != null)
                {
                    F_CREATEDATE.Text = baseModel[0].F_CREATEDATE.ToString();
                }
                if (baseModel[0].F_REPAIRMANNAME != null)
                {
                    F_REPAIRMANNAME.Text = baseModel[0].F_REPAIRMANNAME.ToString();
                }
                if (baseModel[0].F_REPAIRMANPHONE != null)
                {
                    F_REPAIRMANPHONE.Text = baseModel[0].F_REPAIRMANPHONE.ToString();
                }
                if (baseModel[0].F_CONTENT != null)
                {
                    F_CONTENT.Text = baseModel[0].F_CONTENT.ToString();
                }

                //if (baseModel[0].F_SystemType != null)
                //{
                //    F_SystemType.Text = baseModel[0].F_SystemType.ToString();
                //}
                //if (baseModel[0].F_QualityGuaranteeEndTime != null)
                //{
                //    F_QualityGuaranteeEndTime.Text = baseModel[0].F_QualityGuaranteeEndTime.ToString();
                //}
                if (baseModel[0].F_TypeName != null)
                {
                    F_TypeName.Text = baseModel[0].F_TypeName.ToString();
                }
                //if (baseModel[0].F_REPAIRLEVELNAME != null)
                //{
                //    F_REPAIRLEVELNAME.Text = baseModel[0].F_REPAIRLEVELNAME.ToString();
                //}
                if (baseModel[0].F_STANDARDADDRESS != null)
                {
                    F_STANDARDADDRESS.Text = baseModel[0].F_STANDARDADDRESS.ToString();
                }
            }
            string sql2 = @"select (select top 1 F_KNOWLEDGE from T_Wo_WorkOrderHistoryInfo where F_INSTANCEID=" + HDintenseid.Value + " and F_KNOWLEDGE is not null order by ID desc) as F_KNOWLEDGE,(select top 1 F_ALREADYKNOWLEDGE from T_Wo_WorkOrderHistoryInfo where F_INSTANCEID=" + HDintenseid.Value + " and F_ALREADYKNOWLEDGE is not null order by ID desc) as F_ALREADYKNOWLEDGE,(select top 1 F_KNOWLEDGENAME from T_Wo_WorkOrderHistoryInfo where F_INSTANCEID=" + HDintenseid.Value + " and F_KNOWLEDGENAME is not null order by ID desc) as F_KNOWLEDGENAME";
            DataTable dt1 = DbHelperSQL.Query(sql2).Tables[0];
            if (dt1.Rows.Count > 0)
            {
                if (dt1.Rows[0]["F_KNOWLEDGE"] != null)
                {
                    if (dt1.Rows[0]["F_KNOWLEDGE"].ToString() == "0")
                    {
                        F_KNOWLEDGE.Text = "是";
                    }
                    else
                    {
                        F_KNOWLEDGE.Text = "否";
                    }
                }
                if (dt1.Rows[0]["F_ALREADYKNOWLEDGE"] != null)
                {
                    if (dt1.Rows[0]["F_ALREADYKNOWLEDGE"].ToString() == "0")
                    {
                        F_ALREADYKNOWLEDGE.Text = "是";
                    }
                    else
                    {
                        F_ALREADYKNOWLEDGE.Text = "否";
                    }
                }
                if (dt1.Rows[0]["F_KNOWLEDGENAME"] != null)
                {
                    F_KNOWLEDGENAME.Text = dt1.Rows[0]["F_KNOWLEDGENAME"].ToString();
                }
            }
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            try 
            {
                bool bl = false;
                Model.T_Wo_WorkOrderBase model = new Model.T_Wo_WorkOrderBase();
                BLL.T_Wo_WorkOrderBase bll = new BLL.T_Wo_WorkOrderBase();
                model.F_CONTENT = F_CONTENT.Text.Trim();
                model.F_WORKORDERID = Convert.ToInt32(Request.QueryString["workorderid"]);
                bl = bll.Update1(model);
                if (bl)
                {
                    InsertOptLogs(0, 0, "操作成功！woekorderDCLedit.aspx页面，修改来电内容。", 0);
                    MessageBoxToWindow("保存成功", "保存提示！", "success");
                }
                else 
                {
                    InsertOptLogs(0, 0, "操作失败！woekorderDCLedit.aspx页面，修改来电内容。", 1);
                    MessageBoxToWindow("保存失败", "保存提示！", "error");
                }
            }
            catch 
            {
                InsertOptLogs(0, 0, "操作异常！woekorderDCLedit.aspx页面，修改来电内容。", 2);
                MessageBoxToWindow("保存失败", "保存提示！", "error");
            }
        }
        #region 弹出对话框
        /// <summary>
        /// 弹出对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="type"></param>
        public void MessageBoxToWindow(string title, string content, string type)
        {
            string script = "";
            switch (type)
            {
                case "error"://失败
                    type = "error";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                case "success"://成功
                    type = "info";
                    script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "',parent.Close);</script>";
                    break;
                case "catch"://异常
                    type = "warning";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                default:
                    type = "question";
                    break;
            }
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", script);
        }
        #endregion
    }
}