using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZXDT.DBUtility;//Please add references
using ZXDT.Common;

namespace ZXDT.CallCenter.DAL
{
    /// <summary>
    /// 数据访问类:T_Wo_WorkOrderBase
    /// </summary>
    public partial class T_Wo_WorkOrderBase
    {
        DAL.T_Sys_UserAccount userBll = new DAL.T_Sys_UserAccount();
        DAL.T_Sys_Department depBll = new DAL.T_Sys_Department();
        DAL.T_Wo_WorkOrderNotice NoticeBll = new DAL.T_Wo_WorkOrderNotice();
        
        public T_Wo_WorkOrderBase()
        { }
        #region  Method
        #region
        //public bool UpdateWorkOrderInfoModel(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        //{
        //    //历史工单id
        //    int historyId = 0;

        //    //转办
        //    if (model.F_WORKORDERTYPEID == 1)
        //    {
        //        Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
        //        historyModel.F_INSTANCEID = model.F_WORKORDERID;
        //        historyModel.F_OPTBTNID = model.F_DEPTID;//部门
        //        historyModel.F_NEXTOWNERARRID = model.F_DEPTCODE;//部门
        //        historyModel.F_OPTUSERID = model.F_CREATEBY;//人员
        //        historyModel.F_UserName = model.F_USERNAME;//人员
        //        historyModel.F_OPTDATE = DateTime.Now;
        //        historyModel.F_WORKORDERSTATEID = 0;
        //        historyModel.F_StateName = "未处理";
        //        historyModel.NeedReplayTime = model.F_REQUESTSERVICETIME;

        //        historyId = InsertWorkOrderHistoryModel(historyModel);

        //    }



        //    StringBuilder strSql = new StringBuilder();

        //    strSql.Append("update T_Wo_WorkOrderBase set ");
        //    strSql.Append("F_CUSTOMERID=@F_CUSTOMERID,");
        //    strSql.Append("F_CUSTOMERNAME=@F_CUSTOMERNAME,");
        //    strSql.Append("F_CUSTOMERTELEPHONE=@F_CUSTOMERTELEPHONE,");
        //    strSql.Append("F_WORKORDERFROM=@F_WORKORDERFROM,");
        //    strSql.Append("F_RETURNVISITPROBLEM=@F_RETURNVISITPROBLEM,");
        //    strSql.Append("F_REPAIRLEVEL=@F_REPAIRLEVEL,");
        //    strSql.Append("F_ADSLACCOUNT=@F_ADSLACCOUNT,");
        //    strSql.Append("F_WORKORDERLEVELID=@F_WORKORDERLEVELID,");
        //    strSql.Append("F_WORKORDERNAME=@F_WORKORDERNAME,");
        //    strSql.Append("F_CONTENT=@F_CONTENT,");
        //    strSql.Append("F_WORKORDERTYPEID=@F_WORKORDERTYPEID,");
        //    strSql.Append("F_USERID=@F_USERID,");
        //    strSql.Append("F_REPAIRMANNAME=@F_REPAIRMANNAME,");
        //    strSql.Append("F_CREATEDATE=@F_CREATEDATE,");
        //    strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
        //    strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST,");
        //    strSql.Append("F_INSTALLADDRESS=@F_INSTALLADDRESS,");
        //    strSql.Append("F_DEPTID=@F_DEPTID,");
        //    strSql.Append("F_DEPTCODE=@F_DEPTCODE,");
        //    strSql.Append("F_CREATEBY=@F_CREATEBY,");
        //    strSql.Append("F_USERNAME=@F_USERNAME,");
        //    strSql.Append("F_REQUESTSERVICETIME=@F_REQUESTSERVICETIME,");
        //    strSql.Append("F_RETURNVISITCONTENT=@F_RETURNVISITCONTENT,");
        //    strSql.Append("F_RETURNVISITFLAG=@F_RETURNVISITFLAG,");
        //    strSql.Append("F_RETURNVISITTIME =@F_RETURNVISITTIME,");
        //    strSql.Append("F_LINKMAN =@F_LINKMAN,");
        //    strSql.Append("F_REPAIRMANID =@F_REPAIRMANID,");
        //    strSql.Append("F_FORMID =@F_FORMID");
        //    strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");


        //    SqlParameter[] parameters = {
        //            new SqlParameter("@F_CUSTOMERID", SqlDbType.Int,4),
        //            new SqlParameter("@F_CUSTOMERNAME", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_CUSTOMERTELEPHONE", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_WORKORDERFROM", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_RETURNVISITPROBLEM", SqlDbType.NVarChar,2000),
        //            new SqlParameter("@F_REPAIRLEVEL",SqlDbType.Int,4),
        //            new SqlParameter("@F_ADSLACCOUNT", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_WORKORDERLEVELID", SqlDbType.Int,4),
        //            new SqlParameter("@F_WORKORDERNAME", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_CONTENT", SqlDbType.Text),
        //            new SqlParameter("@F_WORKORDERTYPEID",SqlDbType.Int,4),
        //            new SqlParameter("@F_USERID", SqlDbType.Int,4),
        //            new SqlParameter("@F_REPAIRMANNAME", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
        //            new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
        //            new SqlParameter("@F_REPAIRREQUEST", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_INSTALLADDRESS", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_DEPTID", SqlDbType.Int,4),
        //            new SqlParameter("@F_DEPTCODE", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_CREATEBY", SqlDbType.Int,4),
        //            new SqlParameter("@F_USERNAME", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_REQUESTSERVICETIME",SqlDbType.DateTime),
        //            new SqlParameter("@F_RETURNVISITCONTENT", SqlDbType.VarChar,800),
        //            new SqlParameter("@F_RETURNVISITFLAG", SqlDbType.Int,4),
        //            new SqlParameter("@F_RETURNVISITTIME ", SqlDbType.DateTime),
        //            new SqlParameter("@F_LINKMAN", SqlDbType.NVarChar,200),
        //            new SqlParameter("@F_REPAIRMANID", SqlDbType.Int,4),
        //               new SqlParameter("@F_FORMID", SqlDbType.Int,4),
        //            new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
        //    parameters[0].Value = model.F_CUSTOMERID;
        //    parameters[1].Value = model.F_CUSTOMERNAME;
        //    parameters[2].Value = model.F_CUSTOMERTELEPHONE;
        //    parameters[3].Value = model.F_WORKORDERFROM;
        //    parameters[4].Value = model.F_RETURNVISITPROBLEM;
        //    parameters[5].Value = model.F_REPAIRLEVEL;
        //    parameters[6].Value = model.F_ADSLACCOUNT;
        //    parameters[7].Value = model.F_WORKORDERLEVELID;
        //    parameters[8].Value = model.F_WORKORDERNAME;
        //    parameters[9].Value = model.F_CONTENT;
        //    parameters[10].Value = model.F_WORKORDERTYPEID;
        //    parameters[11].Value = model.F_USERID;
        //    parameters[12].Value = model.F_REPAIRMANNAME;
        //    parameters[13].Value = DateTime.Now;
        //    parameters[14].Value = model.F_WORKORDERSTATEID;
        //    parameters[15].Value = model.F_REPAIRREQUEST;
        //    parameters[16].Value = model.F_INSTALLADDRESS;
        //    parameters[17].Value = model.F_DEPTID;
        //    parameters[18].Value = model.F_DEPTCODE;
        //    parameters[19].Value = model.F_CREATEBY;
        //    parameters[20].Value = model.F_USERNAME;
        //    parameters[21].Value = model.F_REQUESTSERVICETIME;
        //    parameters[22].Value = model.F_RETURNVISITCONTENT;
        //    parameters[23].Value = model.F_RETURNVISITFLAG;
        //    parameters[24].Value = model.F_RETURNVISITTIME;
        //    parameters[25].Value = model.F_LINKMAN;
        //    parameters[26].Value = model.F_REPAIRMANID;
        //    parameters[27].Value = historyId;
        //    parameters[28].Value = model.F_WORKORDERID;


        //    int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }


        //}
        #endregion

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wo_WorkOrderBase(");
            strSql.Append(@"F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_CODE,F_WORKORDERNAME,F_NUMBER,
F_CUSTOMERNAME,F_CUSTOMERTELEPHONE,F_LINKMAN,F_LINKMANTELEPHONE,F_ADSLACCOUNT,F_BANDWIDTH,F_STANDARDADDRESS,
F_INSTALLADDRESS,F_KSHADDRESSCODE,F_PROVINCE,F_CITY,F_AREA,F_ROAD,F_HOUSING,F_WORKORDERFROM,F_WORKORDERLEVELID,
F_FILEFLAG,F_CONTENT,F_CREATEBY,F_CREATEDATE,F_DEPTCODE,F_EMPCODE,F_DEPTID,F_USERID,F_USERNAME,F_RETURNVISITFLAG,
F_RETURNVISITSTATE,F_RETURNVISITRESULT,F_RETURNVISITCONTENT,F_DELETEFLAG,F_ALLUSETIMES,F_STARTTIME,F_ENDTIME,F_REMAINDERTIME,
F_REMAINDERENDTIME,F_SUBSCRIBETIME1,F_SUBSCRIBETIME2,F_ACCEPTTIMELIMIT,F_ASKFINISHTIME,F_OVERTIMES,F_FORMID,F_HASTENCOUNTS,F_RANGEID,
F_RANGEX,F_RANGEY,F_INSTANCEID,F_CUSTOMERID,F_REPAIRMANID,F_REPAIRMANNAME,F_REPAIRMANPHONE,F_REPAIRREQUEST,F_REPAIRCLOSEMANID,
F_REPAIRCLOSEMANNAME,F_REPAIRCLOSEREASONS,F_REPAIRCLOSEREPTID,F_REPAIRCLOSEREPT,F_REPAIRLEVEL,F_REPAIRLEVELNAME,F_SENTORDERTIME,
F_USERPHONE,F_RETURNVISITTIME,F_REQUESTSERVICETIME,F_SERVICETYPE,F_DECLARATIONTIME,F_SERVICENATURE,F_SERVICEWAY,F_RETURNVISITMAN,
F_RETURNVISITID,F_RETURNVISITOPINION,F_RETURNVISITPROBLEM,F_CallId,F_CREATEBYids)");
            strSql.Append(" values (");
            strSql.Append(@"@F_WORKORDERTYPEID,@F_WORKORDERSTATEID,@F_CODE,@F_WORKORDERNAME,@F_NUMBER,@F_CUSTOMERNAME,
@F_CUSTOMERTELEPHONE,@F_LINKMAN,@F_LINKMANTELEPHONE,@F_ADSLACCOUNT,@F_BANDWIDTH,@F_STANDARDADDRESS,@F_INSTALLADDRESS,
@F_KSHADDRESSCODE,@F_PROVINCE,@F_CITY,@F_AREA,@F_ROAD,@F_HOUSING,@F_WORKORDERFROM,@F_WORKORDERLEVELID,@F_FILEFLAG,@F_CONTENT,
@F_CREATEBY,@F_CREATEDATE,@F_DEPTCODE,@F_EMPCODE,@F_DEPTID,@F_USERID,@F_USERNAME,@F_RETURNVISITFLAG,@F_RETURNVISITSTATE,
@F_RETURNVISITRESULT,@F_RETURNVISITCONTENT,@F_DELETEFLAG,@F_ALLUSETIMES,@F_STARTTIME,@F_ENDTIME,@F_REMAINDERTIME,@F_REMAINDERENDTIME,
@F_SUBSCRIBETIME1,@F_SUBSCRIBETIME2,@F_ACCEPTTIMELIMIT,@F_ASKFINISHTIME,@F_OVERTIMES,@F_FORMID,@F_HASTENCOUNTS,@F_RANGEID,@F_RANGEX,
@F_RANGEY,@F_INSTANCEID,@F_CUSTOMERID,@F_REPAIRMANID,@F_REPAIRMANNAME,@F_REPAIRMANPHONE,@F_REPAIRREQUEST,@F_REPAIRCLOSEMANID,
@F_REPAIRCLOSEMANNAME,@F_REPAIRCLOSEREASONS,@F_REPAIRCLOSEREPTID,@F_REPAIRCLOSEREPT,@F_REPAIRLEVEL,@F_REPAIRLEVELNAME,@F_SENTORDERTIME,
@F_USERPHONE,@F_RETURNVISITTIME,@F_REQUESTSERVICETIME,@F_SERVICETYPE,@F_DECLARATIONTIME,@F_SERVICENATURE,@F_SERVICEWAY,@F_RETURNVISITMAN,
@F_RETURNVISITID,@F_RETURNVISITOPINION,@F_RETURNVISITPROBLEM,@F_CallId,@F_CREATEBYids)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERTYPEID", SqlDbType.Int,4),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERNAME", SqlDbType.VarChar,100),
                    new SqlParameter("@F_NUMBER", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERNAME", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMAN", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMANTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ADSLACCOUNT", SqlDbType.VarChar,50),
                    new SqlParameter("@F_BANDWIDTH", SqlDbType.VarChar,50),
                    new SqlParameter("@F_STANDARDADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_INSTALLADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_KSHADDRESSCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_PROVINCE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CITY", SqlDbType.VarChar,50),
                    new SqlParameter("@F_AREA", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ROAD", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HOUSING", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERFROM", SqlDbType.VarChar,500),
                    new SqlParameter("@F_WORKORDERLEVELID", SqlDbType.Int,4),
                    new SqlParameter("@F_FILEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_CONTENT", SqlDbType.Text),
                    new SqlParameter("@F_CREATEBY", SqlDbType.Int,4),
                    new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
                    new SqlParameter("@F_DEPTCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EMPCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DEPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERNAME", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITSTATE", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITCONTENT", SqlDbType.VarChar,800),
                    new SqlParameter("@F_DELETEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_ALLUSETIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_STARTTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_ENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME1", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME2", SqlDbType.DateTime),
                    new SqlParameter("@F_ACCEPTTIMELIMIT", SqlDbType.DateTime),
                    new SqlParameter("@F_ASKFINISHTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_OVERTIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_FORMID", SqlDbType.Int,4),
                    new SqlParameter("@F_HASTENCOUNTS", SqlDbType.Int,4),
                    new SqlParameter("@F_RANGEID", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEX", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEY", SqlDbType.Decimal,9),
                    new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CUSTOMERID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRMANPHONE", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRREQUEST", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_REPAIRCLOSEMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRCLOSEREASONS", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_REPAIRCLOSEREPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEREPT", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_REPAIRLEVEL", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRLEVELNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_SENTORDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_USERPHONE", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REQUESTSERVICETIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SERVICETYPE", SqlDbType.NVarChar,1000),
                    new SqlParameter("@F_DECLARATIONTIME", SqlDbType.Decimal,9),
                    new SqlParameter("@F_SERVICENATURE", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_SERVICEWAY", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITMAN", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITID", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NChar,10),
                    new SqlParameter("@F_RETURNVISITPROBLEM", SqlDbType.NVarChar,2000),
                        new SqlParameter("@F_CallId", SqlDbType.Int,4),
                        new SqlParameter("@F_CREATEBYids", SqlDbType.NVarChar,100)


            };
            parameters[0].Value = model.F_WORKORDERTYPEID;
            parameters[1].Value = model.F_WORKORDERSTATEID;
            parameters[2].Value = model.F_CODE;
            parameters[3].Value = model.F_WORKORDERNAME;
            parameters[4].Value = model.F_NUMBER;
            parameters[5].Value = model.F_CUSTOMERNAME;
            parameters[6].Value = model.F_CUSTOMERTELEPHONE;
            parameters[7].Value = model.F_LINKMAN;
            parameters[8].Value = model.F_LINKMANTELEPHONE;
            parameters[9].Value = model.F_ADSLACCOUNT;
            parameters[10].Value = model.F_BANDWIDTH;
            parameters[11].Value = model.F_STANDARDADDRESS;
            parameters[12].Value = model.F_INSTALLADDRESS;
            parameters[13].Value = model.F_KSHADDRESSCODE;
            parameters[14].Value = model.F_PROVINCE;
            parameters[15].Value = model.F_CITY;
            parameters[16].Value = model.F_AREA;
            parameters[17].Value = model.F_ROAD;
            parameters[18].Value = model.F_HOUSING;
            parameters[19].Value = model.F_WORKORDERFROM;
            parameters[20].Value = model.F_WORKORDERLEVELID;
            parameters[21].Value = model.F_FILEFLAG;
            parameters[22].Value = model.F_CONTENT;
            parameters[23].Value = model.F_CREATEBY;
            parameters[24].Value = model.F_CREATEDATE;
            parameters[25].Value = model.F_DEPTCODE;
            parameters[26].Value = model.F_EMPCODE;
            parameters[27].Value = model.F_DEPTID;
            parameters[28].Value = model.F_USERID;
            parameters[29].Value = model.F_USERNAME;
            parameters[30].Value = model.F_RETURNVISITFLAG;
            parameters[31].Value = model.F_RETURNVISITSTATE;
            parameters[32].Value = model.F_RETURNVISITRESULT;
            parameters[33].Value = model.F_RETURNVISITCONTENT;
            parameters[34].Value = model.F_DELETEFLAG;
            parameters[35].Value = model.F_ALLUSETIMES;
            parameters[36].Value = model.F_STARTTIME;
            parameters[37].Value = model.F_ENDTIME;
            parameters[38].Value = model.F_REMAINDERTIME;
            parameters[39].Value = model.F_REMAINDERENDTIME;
            parameters[40].Value = model.F_SUBSCRIBETIME1;
            parameters[41].Value = model.F_SUBSCRIBETIME2;
            parameters[42].Value = model.F_ACCEPTTIMELIMIT;
            parameters[43].Value = model.F_ASKFINISHTIME;
            parameters[44].Value = model.F_OVERTIMES;
            parameters[45].Value = model.F_FORMID;
            parameters[46].Value = model.F_HASTENCOUNTS;
            parameters[47].Value = model.F_RANGEID;
            parameters[48].Value = model.F_RANGEX;
            parameters[49].Value = model.F_RANGEY;
            parameters[50].Value = model.F_INSTANCEID;
            parameters[51].Value = model.F_CUSTOMERID;
            parameters[52].Value = model.F_REPAIRMANID;
            parameters[53].Value = model.F_REPAIRMANNAME;
            parameters[54].Value = model.F_REPAIRMANPHONE;
            parameters[55].Value = model.F_REPAIRREQUEST;
            parameters[56].Value = model.F_REPAIRCLOSEMANID;
            parameters[57].Value = model.F_REPAIRCLOSEMANNAME;
            parameters[58].Value = model.F_REPAIRCLOSEREASONS;
            parameters[59].Value = model.F_REPAIRCLOSEREPTID;
            parameters[60].Value = model.F_REPAIRCLOSEREPT;
            parameters[61].Value = model.F_REPAIRLEVEL;
            parameters[62].Value = model.F_REPAIRLEVELNAME;
            parameters[63].Value = model.F_SENTORDERTIME;
            parameters[64].Value = model.F_USERPHONE;
            parameters[65].Value = model.F_RETURNVISITTIME;
            parameters[66].Value = model.F_REQUESTSERVICETIME;
            parameters[67].Value = model.F_SERVICETYPE;
            parameters[68].Value = model.F_DECLARATIONTIME;
            parameters[69].Value = model.F_SERVICENATURE;
            parameters[70].Value = model.F_SERVICEWAY;
            parameters[71].Value = model.F_RETURNVISITMAN;
            parameters[72].Value = model.F_RETURNVISITID;
            parameters[73].Value = model.F_RETURNVISITOPINION;
            parameters[74].Value = model.F_RETURNVISITPROBLEM;
            parameters[75].Value = model.F_CallId;
            parameters[76].Value = model.F_CREATEBYids;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 增加一条手工微博工单数据
        /// </summary>
        public int AddWbgd(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wo_WorkOrderBase(");
            strSql.Append(@"F_WORKORDERTYPEID,F_WORKORDERSTATEID,F_CODE,F_WORKORDERNAME,F_NUMBER,F_CUSTOMERNAME,F_CUSTOMERTELEPHONE,
F_LINKMAN,F_LINKMANTELEPHONE,F_ADSLACCOUNT,F_BANDWIDTH,F_STANDARDADDRESS,F_INSTALLADDRESS,F_KSHADDRESSCODE,F_PROVINCE,F_CITY,F_AREA,
F_ROAD,F_HOUSING,F_WORKORDERFROM,F_WORKORDERLEVELID,F_FILEFLAG,F_CONTENT,F_CREATEBY,F_CREATEDATE,F_DEPTCODE,F_EMPCODE,F_DEPTID,F_USERID
,F_USERNAME,F_RETURNVISITFLAG,F_RETURNVISITSTATE,F_RETURNVISITRESULT,F_RETURNVISITCONTENT,F_DELETEFLAG,F_ALLUSETIMES,F_STARTTIME,F_ENDTIME,
F_REMAINDERTIME,F_REMAINDERENDTIME,F_SUBSCRIBETIME1,F_SUBSCRIBETIME2,F_ACCEPTTIMELIMIT,F_ASKFINISHTIME,F_OVERTIMES,F_FORMID,F_HASTENCOUNTS,
F_RANGEID,F_RANGEX,F_RANGEY,F_INSTANCEID,F_CUSTOMERID,F_REPAIRMANID,F_REPAIRMANNAME,F_REPAIRMANPHONE,F_REPAIRREQUEST,F_REPAIRCLOSEMANID,
F_REPAIRCLOSEMANNAME,F_REPAIRCLOSEREASONS,F_REPAIRCLOSEREPTID,F_REPAIRCLOSEREPT,F_REPAIRLEVEL,F_REPAIRLEVELNAME,F_SENTORDERTIME,F_USERPHONE,
F_RETURNVISITTIME,F_REQUESTSERVICETIME,F_SERVICETYPE,F_DECLARATIONTIME,F_SERVICENATURE,F_SERVICEWAY,F_RETURNVISITMAN,F_RETURNVISITID,
F_RETURNVISITOPINION,F_RETURNVISITPROBLEM,F_CallId,F_CREATEBYids)");
            strSql.Append(" values (");
            strSql.Append(@"@F_WORKORDERTYPEID,@F_WORKORDERSTATEID,@F_CODE,@F_WORKORDERNAME,@F_NUMBER,@F_CUSTOMERNAME,@F_CUSTOMERTELEPHONE,
@F_LINKMAN,@F_LINKMANTELEPHONE,@F_ADSLACCOUNT,@F_BANDWIDTH,@F_STANDARDADDRESS,@F_INSTALLADDRESS,@F_KSHADDRESSCODE,@F_PROVINCE,@F_CITY,@F_AREA,
@F_ROAD,@F_HOUSING,@F_WORKORDERFROM,@F_WORKORDERLEVELID,@F_FILEFLAG,@F_CONTENT,@F_CREATEBY,@F_CREATEDATE,@F_DEPTCODE,@F_EMPCODE,@F_DEPTID,@F_USERID,
@F_USERNAME,@F_RETURNVISITFLAG,@F_RETURNVISITSTATE,@F_RETURNVISITRESULT,@F_RETURNVISITCONTENT,@F_DELETEFLAG,@F_ALLUSETIMES,@F_STARTTIME,@F_ENDTIME,
@F_REMAINDERTIME,@F_REMAINDERENDTIME,@F_SUBSCRIBETIME1,@F_SUBSCRIBETIME2,@F_ACCEPTTIMELIMIT,@F_ASKFINISHTIME,@F_OVERTIMES,@F_FORMID,@F_HASTENCOUNTS,
@F_RANGEID,@F_RANGEX,@F_RANGEY,@F_INSTANCEID,@F_CUSTOMERID,@F_REPAIRMANID,@F_REPAIRMANNAME,@F_REPAIRMANPHONE,@F_REPAIRREQUEST,@F_REPAIRCLOSEMANID,
@F_REPAIRCLOSEMANNAME,@F_REPAIRCLOSEREASONS,@F_REPAIRCLOSEREPTID,@F_REPAIRCLOSEREPT,@F_REPAIRLEVEL,@F_REPAIRLEVELNAME,@F_SENTORDERTIME,@F_USERPHONE,
@F_RETURNVISITTIME,@F_REQUESTSERVICETIME,@F_SERVICETYPE,@F_DECLARATIONTIME,@F_SERVICENATURE,@F_SERVICEWAY,@F_RETURNVISITMAN,@F_RETURNVISITID,
@F_RETURNVISITOPINION,@F_RETURNVISITPROBLEM,@F_CallId,@F_CREATEBYids)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERTYPEID", SqlDbType.Int,4),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERNAME", SqlDbType.VarChar,100),
                    new SqlParameter("@F_NUMBER", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERNAME", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMAN", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMANTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ADSLACCOUNT", SqlDbType.VarChar,50),
                    new SqlParameter("@F_BANDWIDTH", SqlDbType.VarChar,50),
                    new SqlParameter("@F_STANDARDADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_INSTALLADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_KSHADDRESSCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_PROVINCE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CITY", SqlDbType.VarChar,50),
                    new SqlParameter("@F_AREA", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ROAD", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HOUSING", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERFROM", SqlDbType.VarChar,500),
                    new SqlParameter("@F_WORKORDERLEVELID", SqlDbType.Int,4),
                    new SqlParameter("@F_FILEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_CONTENT", SqlDbType.Text),
                    new SqlParameter("@F_CREATEBY", SqlDbType.Int,4),
                    new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
                    new SqlParameter("@F_DEPTCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EMPCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DEPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERNAME", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITSTATE", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITCONTENT", SqlDbType.VarChar,800),
                    new SqlParameter("@F_DELETEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_ALLUSETIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_STARTTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_ENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME1", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME2", SqlDbType.DateTime),
                    new SqlParameter("@F_ACCEPTTIMELIMIT", SqlDbType.DateTime),
                    new SqlParameter("@F_ASKFINISHTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_OVERTIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_FORMID", SqlDbType.Int,4),
                    new SqlParameter("@F_HASTENCOUNTS", SqlDbType.Int,4),
                    new SqlParameter("@F_RANGEID", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEX", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEY", SqlDbType.Decimal,9),
                    new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CUSTOMERID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRMANPHONE", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRREQUEST", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_REPAIRCLOSEMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRCLOSEREASONS", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_REPAIRCLOSEREPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEREPT", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_REPAIRLEVEL", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRLEVELNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_SENTORDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_USERPHONE", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REQUESTSERVICETIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SERVICETYPE", SqlDbType.NVarChar,1000),
                    new SqlParameter("@F_DECLARATIONTIME", SqlDbType.Decimal,9),
                    new SqlParameter("@F_SERVICENATURE", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_SERVICEWAY", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITMAN", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITID", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NChar,10),
                    new SqlParameter("@F_RETURNVISITPROBLEM", SqlDbType.NVarChar,2000),
                     new SqlParameter("@F_CallId", SqlDbType.Int,4),
                     new SqlParameter("@F_CREATEBYids", SqlDbType.NVarChar,100)

            };
            parameters[0].Value = model.F_WORKORDERTYPEID;
            parameters[1].Value = model.F_WORKORDERSTATEID;
            parameters[2].Value = GetOrderNumber(int.Parse(model.F_REPAIRLEVEL.ToString()));
            parameters[3].Value = model.F_WORKORDERNAME;
            parameters[4].Value = model.F_NUMBER;
            parameters[5].Value = model.F_CUSTOMERNAME;
            parameters[6].Value = model.F_CUSTOMERTELEPHONE;
            parameters[7].Value = model.F_LINKMAN;
            parameters[8].Value = model.F_LINKMANTELEPHONE;
            parameters[9].Value = model.F_ADSLACCOUNT;
            parameters[10].Value = model.F_BANDWIDTH;
            parameters[11].Value = model.F_STANDARDADDRESS;
            parameters[12].Value = model.F_INSTALLADDRESS;
            parameters[13].Value = model.F_KSHADDRESSCODE;
            parameters[14].Value = model.F_PROVINCE;
            parameters[15].Value = model.F_CITY;
            parameters[16].Value = model.F_AREA;
            parameters[17].Value = model.F_ROAD;
            parameters[18].Value = model.F_HOUSING;
            parameters[19].Value = model.F_WORKORDERFROM;
            parameters[20].Value = model.F_WORKORDERLEVELID;
            parameters[21].Value = model.F_FILEFLAG;
            parameters[22].Value = model.F_CONTENT;
            parameters[23].Value = model.F_CREATEBY;
            parameters[24].Value = model.F_CREATEDATE;
            parameters[25].Value = model.F_DEPTCODE;
            parameters[26].Value = model.F_EMPCODE;
            parameters[27].Value = model.F_DEPTID;
            parameters[28].Value = model.F_USERID;
            parameters[29].Value = model.F_USERNAME;
            parameters[30].Value = model.F_RETURNVISITFLAG;
            parameters[31].Value = model.F_RETURNVISITSTATE;
            parameters[32].Value = model.F_RETURNVISITRESULT;
            parameters[33].Value = model.F_RETURNVISITCONTENT;
            parameters[34].Value = model.F_DELETEFLAG;
            parameters[35].Value = model.F_ALLUSETIMES;
            parameters[36].Value = model.F_STARTTIME;
            parameters[37].Value = model.F_ENDTIME;
            parameters[38].Value = model.F_REMAINDERTIME;
            parameters[39].Value = model.F_REMAINDERENDTIME;
            parameters[40].Value = model.F_SUBSCRIBETIME1;
            parameters[41].Value = model.F_SUBSCRIBETIME2;
            parameters[42].Value = model.F_ACCEPTTIMELIMIT;
            parameters[43].Value = model.F_ASKFINISHTIME;
            parameters[44].Value = model.F_OVERTIMES;
            parameters[45].Value = model.F_FORMID;
            parameters[46].Value = model.F_HASTENCOUNTS;
            parameters[47].Value = model.F_RANGEID;
            parameters[48].Value = model.F_RANGEX;
            parameters[49].Value = model.F_RANGEY;
            parameters[50].Value = model.F_INSTANCEID;
            parameters[51].Value = model.F_CUSTOMERID;
            parameters[52].Value = model.F_REPAIRMANID;
            parameters[53].Value = model.F_REPAIRMANNAME;
            parameters[54].Value = model.F_REPAIRMANPHONE;
            parameters[55].Value = model.F_REPAIRREQUEST;
            parameters[56].Value = model.F_REPAIRCLOSEMANID;
            parameters[57].Value = model.F_REPAIRCLOSEMANNAME;
            parameters[58].Value = model.F_REPAIRCLOSEREASONS;
            parameters[59].Value = model.F_REPAIRCLOSEREPTID;
            parameters[60].Value = model.F_REPAIRCLOSEREPT;
            parameters[61].Value = model.F_REPAIRLEVEL;
            parameters[62].Value = model.F_REPAIRLEVELNAME;
            parameters[63].Value = model.F_SENTORDERTIME;
            parameters[64].Value = model.F_USERPHONE;
            parameters[65].Value = model.F_RETURNVISITTIME;
            parameters[66].Value = model.F_REQUESTSERVICETIME;
            parameters[67].Value = model.F_SERVICETYPE;
            parameters[68].Value = model.F_DECLARATIONTIME;
            parameters[69].Value = model.F_SERVICENATURE;
            parameters[70].Value = model.F_SERVICEWAY;
            parameters[71].Value = model.F_RETURNVISITMAN;
            parameters[72].Value = model.F_RETURNVISITID;
            parameters[73].Value = model.F_RETURNVISITOPINION;
            parameters[74].Value = model.F_RETURNVISITPROBLEM;
            parameters[75].Value = model.F_CallId;
            parameters[76].Value = model.F_CREATEBYids;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_WORKORDERTYPEID=@F_WORKORDERTYPEID,");
            strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
            strSql.Append("F_CODE=@F_CODE,");
            strSql.Append("F_WORKORDERNAME=@F_WORKORDERNAME,");
            strSql.Append("F_NUMBER=@F_NUMBER,");
            strSql.Append("F_CUSTOMERNAME=@F_CUSTOMERNAME,");
            strSql.Append("F_CUSTOMERTELEPHONE=@F_CUSTOMERTELEPHONE,");
            strSql.Append("F_LINKMAN=@F_LINKMAN,");
            strSql.Append("F_LINKMANTELEPHONE=@F_LINKMANTELEPHONE,");
            strSql.Append("F_ADSLACCOUNT=@F_ADSLACCOUNT,");
            strSql.Append("F_BANDWIDTH=@F_BANDWIDTH,");
            strSql.Append("F_STANDARDADDRESS=@F_STANDARDADDRESS,");
            strSql.Append("F_INSTALLADDRESS=@F_INSTALLADDRESS,");
            strSql.Append("F_KSHADDRESSCODE=@F_KSHADDRESSCODE,");
            strSql.Append("F_PROVINCE=@F_PROVINCE,");
            strSql.Append("F_CITY=@F_CITY,");
            strSql.Append("F_AREA=@F_AREA,");
            strSql.Append("F_ROAD=@F_ROAD,");
            strSql.Append("F_HOUSING=@F_HOUSING,");
            strSql.Append("F_WORKORDERFROM=@F_WORKORDERFROM,");
            strSql.Append("F_WORKORDERLEVELID=@F_WORKORDERLEVELID,");
            strSql.Append("F_FILEFLAG=@F_FILEFLAG,");
            strSql.Append("F_CONTENT=@F_CONTENT,");
            strSql.Append("F_CREATEBY=@F_CREATEBY,");
            strSql.Append("F_CREATEDATE=@F_CREATEDATE,");
            strSql.Append("F_DEPTCODE=@F_DEPTCODE,");
            strSql.Append("F_EMPCODE=@F_EMPCODE,");
            strSql.Append("F_DEPTID=@F_DEPTID,");
            strSql.Append("F_USERID=@F_USERID,");
            strSql.Append("F_USERNAME=@F_USERNAME,");
            strSql.Append("F_RETURNVISITFLAG=@F_RETURNVISITFLAG,");
            strSql.Append("F_RETURNVISITSTATE=@F_RETURNVISITSTATE,");
            strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
            strSql.Append("F_RETURNVISITCONTENT=@F_RETURNVISITCONTENT,");
            strSql.Append("F_DELETEFLAG=@F_DELETEFLAG,");
            strSql.Append("F_ALLUSETIMES=@F_ALLUSETIMES,");
            strSql.Append("F_STARTTIME=@F_STARTTIME,");
            strSql.Append("F_ENDTIME=@F_ENDTIME,");
            strSql.Append("F_REMAINDERTIME=@F_REMAINDERTIME,");
            strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
            strSql.Append("F_SUBSCRIBETIME1=@F_SUBSCRIBETIME1,");
            strSql.Append("F_SUBSCRIBETIME2=@F_SUBSCRIBETIME2,");
            strSql.Append("F_ACCEPTTIMELIMIT=@F_ACCEPTTIMELIMIT,");
            strSql.Append("F_ASKFINISHTIME=@F_ASKFINISHTIME,");
            strSql.Append("F_OVERTIMES=@F_OVERTIMES,");
            strSql.Append("F_FORMID=@F_FORMID,");
            strSql.Append("F_HASTENCOUNTS=@F_HASTENCOUNTS,");
            strSql.Append("F_RANGEID=@F_RANGEID,");
            strSql.Append("F_RANGEX=@F_RANGEX,");
            strSql.Append("F_RANGEY=@F_RANGEY,");
            strSql.Append("F_INSTANCEID=@F_INSTANCEID,");
            strSql.Append("F_CUSTOMERID=@F_CUSTOMERID,");
            strSql.Append("F_REPAIRMANID=@F_REPAIRMANID,");
            strSql.Append("F_REPAIRMANNAME=@F_REPAIRMANNAME,");
            strSql.Append("F_REPAIRMANPHONE=@F_REPAIRMANPHONE,");
            strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST,");
            strSql.Append("F_REPAIRCLOSEMANID=@F_REPAIRCLOSEMANID,");
            strSql.Append("F_REPAIRCLOSEMANNAME=@F_REPAIRCLOSEMANNAME,");
            strSql.Append("F_REPAIRCLOSEREASONS=@F_REPAIRCLOSEREASONS,");
            strSql.Append("F_REPAIRCLOSEREPTID=@F_REPAIRCLOSEREPTID,");
            strSql.Append("F_REPAIRCLOSEREPT=@F_REPAIRCLOSEREPT,");
            strSql.Append("F_REPAIRLEVEL=@F_REPAIRLEVEL,");
            strSql.Append("F_REPAIRLEVELNAME=@F_REPAIRLEVELNAME,");
            strSql.Append("F_SENTORDERTIME=@F_SENTORDERTIME,");
            strSql.Append("F_USERPHONE=@F_USERPHONE,");
            strSql.Append("F_RETURNVISITTIME=@F_RETURNVISITTIME,");
            strSql.Append("F_REQUESTSERVICETIME=@F_REQUESTSERVICETIME,");
            strSql.Append("F_SERVICETYPE=@F_SERVICETYPE,");
            strSql.Append("F_DECLARATIONTIME=@F_DECLARATIONTIME,");
            strSql.Append("F_SERVICENATURE=@F_SERVICENATURE,");
            strSql.Append("F_SERVICEWAY=@F_SERVICEWAY,");
            strSql.Append("F_RETURNVISITMAN=@F_RETURNVISITMAN,");
            strSql.Append("F_RETURNVISITID=@F_RETURNVISITID,");
            strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
            strSql.Append("F_RETURNVISITPROBLEM=@F_RETURNVISITPROBLEM,");
            strSql.Append("F_CREATEBYids=@F_CREATEBYids,");

            strSql.Append("F_CallId=@F_CallId");

            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERTYPEID", SqlDbType.Int,4),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERNAME", SqlDbType.VarChar,100),
                    new SqlParameter("@F_NUMBER", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERNAME", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CUSTOMERTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMAN", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LINKMANTELEPHONE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ADSLACCOUNT", SqlDbType.VarChar,50),
                    new SqlParameter("@F_BANDWIDTH", SqlDbType.VarChar,50),
                    new SqlParameter("@F_STANDARDADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_INSTALLADDRESS", SqlDbType.VarChar,200),
                    new SqlParameter("@F_KSHADDRESSCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_PROVINCE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CITY", SqlDbType.VarChar,50),
                    new SqlParameter("@F_AREA", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ROAD", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HOUSING", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERFROM", SqlDbType.VarChar,500),
                    new SqlParameter("@F_WORKORDERLEVELID", SqlDbType.Int,4),
                    new SqlParameter("@F_FILEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_CONTENT", SqlDbType.Text),
                    new SqlParameter("@F_CREATEBY", SqlDbType.Int,4),
                    new SqlParameter("@F_CREATEDATE", SqlDbType.DateTime),
                    new SqlParameter("@F_DEPTCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EMPCODE", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DEPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERID", SqlDbType.Int,4),
                    new SqlParameter("@F_USERNAME", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITSTATE", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITCONTENT", SqlDbType.VarChar,800),
                    new SqlParameter("@F_DELETEFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_ALLUSETIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_STARTTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_ENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REMAINDERENDTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME1", SqlDbType.DateTime),
                    new SqlParameter("@F_SUBSCRIBETIME2", SqlDbType.DateTime),
                    new SqlParameter("@F_ACCEPTTIMELIMIT", SqlDbType.DateTime),
                    new SqlParameter("@F_ASKFINISHTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_OVERTIMES", SqlDbType.Int,4),
                    new SqlParameter("@F_FORMID", SqlDbType.Int,4),
                    new SqlParameter("@F_HASTENCOUNTS", SqlDbType.Int,4),
                    new SqlParameter("@F_RANGEID", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEX", SqlDbType.Decimal,9),
                    new SqlParameter("@F_RANGEY", SqlDbType.Decimal,9),
                    new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
                    new SqlParameter("@F_CUSTOMERID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRMANPHONE", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRREQUEST", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_REPAIRCLOSEMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEMANNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_REPAIRCLOSEREASONS", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_REPAIRCLOSEREPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRCLOSEREPT", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_REPAIRLEVEL", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRLEVELNAME", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_SENTORDERTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_USERPHONE", SqlDbType.VarChar,20),
                    new SqlParameter("@F_RETURNVISITTIME", SqlDbType.DateTime),
                    new SqlParameter("@F_REQUESTSERVICETIME", SqlDbType.DateTime),
                    new SqlParameter("@F_SERVICETYPE", SqlDbType.NVarChar,1000),
                    new SqlParameter("@F_DECLARATIONTIME", SqlDbType.Decimal,9),
                    new SqlParameter("@F_SERVICENATURE", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_SERVICEWAY", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITMAN", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_RETURNVISITID", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NChar,10),
                    new SqlParameter("@F_RETURNVISITPROBLEM", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_CREATEBYids", SqlDbType.NVarChar,100),

                new SqlParameter("@F_CallId", SqlDbType.Int,4),


                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
            parameters[0].Value = model.F_WORKORDERTYPEID;
            parameters[1].Value = model.F_WORKORDERSTATEID;
            parameters[2].Value = model.F_CODE;
            parameters[3].Value = model.F_WORKORDERNAME;
            parameters[4].Value = model.F_NUMBER;
            parameters[5].Value = model.F_CUSTOMERNAME;
            parameters[6].Value = model.F_CUSTOMERTELEPHONE;
            parameters[7].Value = model.F_LINKMAN;
            parameters[8].Value = model.F_LINKMANTELEPHONE;
            parameters[9].Value = model.F_ADSLACCOUNT;
            parameters[10].Value = model.F_BANDWIDTH;
            parameters[11].Value = model.F_STANDARDADDRESS;
            parameters[12].Value = model.F_INSTALLADDRESS;
            parameters[13].Value = model.F_KSHADDRESSCODE;
            parameters[14].Value = model.F_PROVINCE;
            parameters[15].Value = model.F_CITY;
            parameters[16].Value = model.F_AREA;
            parameters[17].Value = model.F_ROAD;
            parameters[18].Value = model.F_HOUSING;
            parameters[19].Value = model.F_WORKORDERFROM;
            parameters[20].Value = model.F_WORKORDERLEVELID;
            parameters[21].Value = model.F_FILEFLAG;
            parameters[22].Value = model.F_CONTENT;
            parameters[23].Value = model.F_CREATEBY;
            parameters[24].Value = model.F_CREATEDATE;
            parameters[25].Value = model.F_DEPTCODE;
            parameters[26].Value = model.F_EMPCODE;
            parameters[27].Value = model.F_DEPTID;
            parameters[28].Value = model.F_USERID;
            parameters[29].Value = model.F_USERNAME;
            parameters[30].Value = model.F_RETURNVISITFLAG;
            parameters[31].Value = model.F_RETURNVISITSTATE;
            parameters[32].Value = model.F_RETURNVISITRESULT;
            parameters[33].Value = model.F_RETURNVISITCONTENT;
            parameters[34].Value = model.F_DELETEFLAG;
            parameters[35].Value = model.F_ALLUSETIMES;
            parameters[36].Value = model.F_STARTTIME;
            parameters[37].Value = model.F_ENDTIME;
            parameters[38].Value = model.F_REMAINDERTIME;
            parameters[39].Value = model.F_REMAINDERENDTIME;
            parameters[40].Value = model.F_SUBSCRIBETIME1;
            parameters[41].Value = model.F_SUBSCRIBETIME2;
            parameters[42].Value = model.F_ACCEPTTIMELIMIT;
            parameters[43].Value = model.F_ASKFINISHTIME;
            parameters[44].Value = model.F_OVERTIMES;
            parameters[45].Value = model.F_FORMID;
            parameters[46].Value = model.F_HASTENCOUNTS;
            parameters[47].Value = model.F_RANGEID;
            parameters[48].Value = model.F_RANGEX;
            parameters[49].Value = model.F_RANGEY;
            parameters[50].Value = model.F_INSTANCEID;
            parameters[51].Value = model.F_CUSTOMERID;
            parameters[52].Value = model.F_REPAIRMANID;
            parameters[53].Value = model.F_REPAIRMANNAME;
            parameters[54].Value = model.F_REPAIRMANPHONE;
            parameters[55].Value = model.F_REPAIRREQUEST;
            parameters[56].Value = model.F_REPAIRCLOSEMANID;
            parameters[57].Value = model.F_REPAIRCLOSEMANNAME;
            parameters[58].Value = model.F_REPAIRCLOSEREASONS;
            parameters[59].Value = model.F_REPAIRCLOSEREPTID;
            parameters[60].Value = model.F_REPAIRCLOSEREPT;
            parameters[61].Value = model.F_REPAIRLEVEL;
            parameters[62].Value = model.F_REPAIRLEVELNAME;
            parameters[63].Value = model.F_SENTORDERTIME;
            parameters[64].Value = model.F_USERPHONE;
            parameters[65].Value = model.F_RETURNVISITTIME;
            parameters[66].Value = model.F_REQUESTSERVICETIME;
            parameters[67].Value = model.F_SERVICETYPE;
            parameters[68].Value = model.F_DECLARATIONTIME;
            parameters[69].Value = model.F_SERVICENATURE;
            parameters[70].Value = model.F_SERVICEWAY;
            parameters[71].Value = model.F_RETURNVISITMAN;
            parameters[72].Value = model.F_RETURNVISITID;
            parameters[73].Value = model.F_RETURNVISITOPINION;
            parameters[74].Value = model.F_RETURNVISITPROBLEM;
            parameters[75].Value = model.F_CREATEBYids;
            parameters[76].Value = model.F_CallId;
            parameters[77].Value = model.F_WORKORDERID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool Update1(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_CONTENT=@F_CONTENT");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CONTENT", SqlDbType.Text),
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
            parameters[0].Value = model.F_CONTENT;
            parameters[1].Value = model.F_WORKORDERID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 定责人员更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateDZuser(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append(" F_ROAD=@F_ROAD");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID AND (F_ROAD='' Or F_ROAD IS NULL)");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_ROAD", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
            parameters[0].Value = model.F_ROAD;
            parameters[1].Value = model.F_WORKORDERID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 定责事件分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateDZClass(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" update T_Wo_WorkOrderBase set ");
            strSql.Append(" F_PROVINCE=@F_PROVINCE, ");
            strSql.Append(" F_WORKORDERSTATEID=5, ");
            strSql.Append(" F_REPAIRREQUEST='已定责', ");
            strSql.Append(" F_CITY=@F_CITY, ");
            strSql.Append(" F_SERVICENATURE=@F_SERVICENATURE, ");
            strSql.Append(" F_SERVICETYPE=@F_SERVICETYPE, ");
            strSql.Append(" F_HASTENCOUNTS=ISNULL(F_HASTENCOUNTS,0)+1, ");
            strSql.Append(" F_AREA=@F_AREA ");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID AND F_WORKORDERSTATEID>3");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_PROVINCE",model.F_PROVINCE ),
                    new SqlParameter("@F_CITY", model.F_CITY),
                    new SqlParameter("@F_AREA", model.F_AREA),
                    new SqlParameter("@F_WORKORDERID", model.F_WORKORDERID),
                    new SqlParameter("@F_SERVICENATURE", model.F_SERVICENATURE),
                    new SqlParameter("@F_SERVICETYPE", model.F_SERVICETYPE)

            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int F_WORKORDERID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Wo_WorkOrderBase ");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)
};
            parameters[0].Value = F_WORKORDERID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_WORKORDERIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Wo_WorkOrderBase ");
            strSql.Append(" where F_WORKORDERID in (" + F_WORKORDERIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZXDT.CallCenter.Model.T_Wo_WorkOrderBase GetModel(int F_WORKORDERID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select  top 1 F_WORKORDERID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,
F_CODE,F_WORKORDERNAME,F_NUMBER,F_CUSTOMERNAME,F_CUSTOMERTELEPHONE,F_LINKMAN,F_LINKMANTELEPHONE,
F_ADSLACCOUNT,F_BANDWIDTH,F_STANDARDADDRESS,F_INSTALLADDRESS,F_KSHADDRESSCODE,F_PROVINCE,F_CITY,F_AREA,
F_ROAD,F_HOUSING,F_WORKORDERFROM,F_WORKORDERLEVELID,F_FILEFLAG,F_CONTENT,F_CREATEBY,F_CREATEDATE,F_DEPTCODE,
F_EMPCODE,F_DEPTID,F_USERID,F_USERNAME,F_RETURNVISITFLAG,F_RETURNVISITSTATE,F_RETURNVISITRESULT,F_RETURNVISITCONTENT,
F_DELETEFLAG,F_ALLUSETIMES,F_STARTTIME,F_ENDTIME,F_REMAINDERTIME,F_REMAINDERENDTIME,F_SUBSCRIBETIME1,F_SUBSCRIBETIME2,
F_ACCEPTTIMELIMIT,F_ASKFINISHTIME,F_OVERTIMES,F_FORMID,F_HASTENCOUNTS,F_RANGEID,F_RANGEX,F_RANGEY,F_INSTANCEID,F_CUSTOMERID,
F_REPAIRMANID,F_REPAIRMANNAME,F_REPAIRMANPHONE,F_REPAIRREQUEST,F_REPAIRCLOSEMANID,F_REPAIRCLOSEMANNAME,F_REPAIRCLOSEREASONS
,F_REPAIRCLOSEREPTID,F_REPAIRCLOSEREPT,F_REPAIRLEVEL,F_REPAIRLEVELNAME,F_SENTORDERTIME,F_USERPHONE,F_RETURNVISITTIME,
F_REQUESTSERVICETIME,F_SERVICETYPE,F_DECLARATIONTIME,F_SERVICENATURE,F_SERVICEWAY,F_RETURNVISITMAN,F_RETURNVISITID,
F_RETURNVISITOPINION,F_RETURNVISITPROBLEM,F_CallId,F_CREATEBYids  from T_Wo_WorkOrderBase ");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)
};
            parameters[0].Value = F_WORKORDERID;

            ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model = new ZXDT.CallCenter.Model.T_Wo_WorkOrderBase();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["F_WORKORDERID"] != null && ds.Tables[0].Rows[0]["F_WORKORDERID"].ToString() != "")
                {
                    model.F_WORKORDERID = int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"] != null && ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"].ToString() != "")
                {
                    model.F_WORKORDERTYPEID = int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERTYPEID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"] != null && ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"].ToString() != "")
                {
                    model.F_WORKORDERSTATEID = int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERSTATEID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CODE"] != null && ds.Tables[0].Rows[0]["F_CODE"].ToString() != "")
                {
                    model.F_CODE = ds.Tables[0].Rows[0]["F_CODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_WORKORDERNAME"] != null && ds.Tables[0].Rows[0]["F_WORKORDERNAME"].ToString() != "")
                {
                    model.F_WORKORDERNAME = ds.Tables[0].Rows[0]["F_WORKORDERNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_NUMBER"] != null && ds.Tables[0].Rows[0]["F_NUMBER"].ToString() != "")
                {
                    model.F_NUMBER = ds.Tables[0].Rows[0]["F_NUMBER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_CUSTOMERNAME"] != null && ds.Tables[0].Rows[0]["F_CUSTOMERNAME"].ToString() != "")
                {
                    model.F_CUSTOMERNAME = ds.Tables[0].Rows[0]["F_CUSTOMERNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_CUSTOMERTELEPHONE"] != null && ds.Tables[0].Rows[0]["F_CUSTOMERTELEPHONE"].ToString() != "")
                {
                    model.F_CUSTOMERTELEPHONE = ds.Tables[0].Rows[0]["F_CUSTOMERTELEPHONE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_LINKMAN"] != null && ds.Tables[0].Rows[0]["F_LINKMAN"].ToString() != "")
                {
                    model.F_LINKMAN = ds.Tables[0].Rows[0]["F_LINKMAN"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_LINKMANTELEPHONE"] != null && ds.Tables[0].Rows[0]["F_LINKMANTELEPHONE"].ToString() != "")
                {
                    model.F_LINKMANTELEPHONE = ds.Tables[0].Rows[0]["F_LINKMANTELEPHONE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_ADSLACCOUNT"] != null && ds.Tables[0].Rows[0]["F_ADSLACCOUNT"].ToString() != "")
                {
                    model.F_ADSLACCOUNT = ds.Tables[0].Rows[0]["F_ADSLACCOUNT"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_BANDWIDTH"] != null && ds.Tables[0].Rows[0]["F_BANDWIDTH"].ToString() != "")
                {
                    model.F_BANDWIDTH = ds.Tables[0].Rows[0]["F_BANDWIDTH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_STANDARDADDRESS"] != null && ds.Tables[0].Rows[0]["F_STANDARDADDRESS"].ToString() != "")
                {
                    model.F_STANDARDADDRESS = ds.Tables[0].Rows[0]["F_STANDARDADDRESS"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_INSTALLADDRESS"] != null && ds.Tables[0].Rows[0]["F_INSTALLADDRESS"].ToString() != "")
                {
                    model.F_INSTALLADDRESS = ds.Tables[0].Rows[0]["F_INSTALLADDRESS"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_KSHADDRESSCODE"] != null && ds.Tables[0].Rows[0]["F_KSHADDRESSCODE"].ToString() != "")
                {
                    model.F_KSHADDRESSCODE = ds.Tables[0].Rows[0]["F_KSHADDRESSCODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_PROVINCE"] != null && ds.Tables[0].Rows[0]["F_PROVINCE"].ToString() != "")
                {
                    model.F_PROVINCE = ds.Tables[0].Rows[0]["F_PROVINCE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_CITY"] != null && ds.Tables[0].Rows[0]["F_CITY"].ToString() != "")
                {
                    model.F_CITY = ds.Tables[0].Rows[0]["F_CITY"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_AREA"] != null && ds.Tables[0].Rows[0]["F_AREA"].ToString() != "")
                {
                    model.F_AREA = ds.Tables[0].Rows[0]["F_AREA"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_ROAD"] != null && ds.Tables[0].Rows[0]["F_ROAD"].ToString() != "")
                {
                    model.F_ROAD = ds.Tables[0].Rows[0]["F_ROAD"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_HOUSING"] != null && ds.Tables[0].Rows[0]["F_HOUSING"].ToString() != "")
                {
                    model.F_HOUSING = ds.Tables[0].Rows[0]["F_HOUSING"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_WORKORDERFROM"] != null && ds.Tables[0].Rows[0]["F_WORKORDERFROM"].ToString() != "")
                {
                    model.F_WORKORDERFROM = ds.Tables[0].Rows[0]["F_WORKORDERFROM"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_WORKORDERLEVELID"] != null && ds.Tables[0].Rows[0]["F_WORKORDERLEVELID"].ToString() != "")
                {
                    model.F_WORKORDERLEVELID = int.Parse(ds.Tables[0].Rows[0]["F_WORKORDERLEVELID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_FILEFLAG"] != null && ds.Tables[0].Rows[0]["F_FILEFLAG"].ToString() != "")
                {
                    model.F_FILEFLAG = int.Parse(ds.Tables[0].Rows[0]["F_FILEFLAG"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CONTENT"] != null && ds.Tables[0].Rows[0]["F_CONTENT"].ToString() != "")
                {
                    model.F_CONTENT = ds.Tables[0].Rows[0]["F_CONTENT"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_CREATEBY"] != null && ds.Tables[0].Rows[0]["F_CREATEBY"].ToString() != "")
                {
                    model.F_CREATEBY = int.Parse(ds.Tables[0].Rows[0]["F_CREATEBY"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CREATEDATE"] != null && ds.Tables[0].Rows[0]["F_CREATEDATE"].ToString() != "")
                {
                    model.F_CREATEDATE = DateTime.Parse(ds.Tables[0].Rows[0]["F_CREATEDATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_DEPTCODE"] != null && ds.Tables[0].Rows[0]["F_DEPTCODE"].ToString() != "")
                {
                    model.F_DEPTCODE = ds.Tables[0].Rows[0]["F_DEPTCODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_EMPCODE"] != null && ds.Tables[0].Rows[0]["F_EMPCODE"].ToString() != "")
                {
                    model.F_EMPCODE = ds.Tables[0].Rows[0]["F_EMPCODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_DEPTID"] != null && ds.Tables[0].Rows[0]["F_DEPTID"].ToString() != "")
                {
                    model.F_DEPTID = int.Parse(ds.Tables[0].Rows[0]["F_DEPTID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_USERID"] != null && ds.Tables[0].Rows[0]["F_USERID"].ToString() != "")
                {
                    model.F_USERID = int.Parse(ds.Tables[0].Rows[0]["F_USERID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_USERNAME"] != null && ds.Tables[0].Rows[0]["F_USERNAME"].ToString() != "")
                {
                    model.F_USERNAME = ds.Tables[0].Rows[0]["F_USERNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITFLAG"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITFLAG"].ToString() != "")
                {
                    model.F_RETURNVISITFLAG = int.Parse(ds.Tables[0].Rows[0]["F_RETURNVISITFLAG"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITSTATE"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITSTATE"].ToString() != "")
                {
                    model.F_RETURNVISITSTATE = int.Parse(ds.Tables[0].Rows[0]["F_RETURNVISITSTATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITRESULT"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITRESULT"].ToString() != "")
                {
                    model.F_RETURNVISITRESULT = int.Parse(ds.Tables[0].Rows[0]["F_RETURNVISITRESULT"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITCONTENT"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITCONTENT"].ToString() != "")
                {
                    model.F_RETURNVISITCONTENT = ds.Tables[0].Rows[0]["F_RETURNVISITCONTENT"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_DELETEFLAG"] != null && ds.Tables[0].Rows[0]["F_DELETEFLAG"].ToString() != "")
                {
                    model.F_DELETEFLAG = int.Parse(ds.Tables[0].Rows[0]["F_DELETEFLAG"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_ALLUSETIMES"] != null && ds.Tables[0].Rows[0]["F_ALLUSETIMES"].ToString() != "")
                {
                    model.F_ALLUSETIMES = int.Parse(ds.Tables[0].Rows[0]["F_ALLUSETIMES"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_STARTTIME"] != null && ds.Tables[0].Rows[0]["F_STARTTIME"].ToString() != "")
                {
                    model.F_STARTTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_STARTTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_ENDTIME"] != null && ds.Tables[0].Rows[0]["F_ENDTIME"].ToString() != "")
                {
                    model.F_ENDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_ENDTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REMAINDERTIME"] != null && ds.Tables[0].Rows[0]["F_REMAINDERTIME"].ToString() != "")
                {
                    model.F_REMAINDERTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_REMAINDERTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REMAINDERENDTIME"] != null && ds.Tables[0].Rows[0]["F_REMAINDERENDTIME"].ToString() != "")
                {
                    model.F_REMAINDERENDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_REMAINDERENDTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_SUBSCRIBETIME1"] != null && ds.Tables[0].Rows[0]["F_SUBSCRIBETIME1"].ToString() != "")
                {
                    model.F_SUBSCRIBETIME1 = DateTime.Parse(ds.Tables[0].Rows[0]["F_SUBSCRIBETIME1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_SUBSCRIBETIME2"] != null && ds.Tables[0].Rows[0]["F_SUBSCRIBETIME2"].ToString() != "")
                {
                    model.F_SUBSCRIBETIME2 = DateTime.Parse(ds.Tables[0].Rows[0]["F_SUBSCRIBETIME2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_ACCEPTTIMELIMIT"] != null && ds.Tables[0].Rows[0]["F_ACCEPTTIMELIMIT"].ToString() != "")
                {
                    model.F_ACCEPTTIMELIMIT = DateTime.Parse(ds.Tables[0].Rows[0]["F_ACCEPTTIMELIMIT"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_ASKFINISHTIME"] != null && ds.Tables[0].Rows[0]["F_ASKFINISHTIME"].ToString() != "")
                {
                    model.F_ASKFINISHTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_ASKFINISHTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_OVERTIMES"] != null && ds.Tables[0].Rows[0]["F_OVERTIMES"].ToString() != "")
                {
                    model.F_OVERTIMES = int.Parse(ds.Tables[0].Rows[0]["F_OVERTIMES"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_FORMID"] != null && ds.Tables[0].Rows[0]["F_FORMID"].ToString() != "")
                {
                    model.F_FORMID = int.Parse(ds.Tables[0].Rows[0]["F_FORMID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_HASTENCOUNTS"] != null && ds.Tables[0].Rows[0]["F_HASTENCOUNTS"].ToString() != "")
                {
                    model.F_HASTENCOUNTS = int.Parse(ds.Tables[0].Rows[0]["F_HASTENCOUNTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RANGEID"] != null && ds.Tables[0].Rows[0]["F_RANGEID"].ToString() != "")
                {
                    model.F_RANGEID = decimal.Parse(ds.Tables[0].Rows[0]["F_RANGEID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RANGEX"] != null && ds.Tables[0].Rows[0]["F_RANGEX"].ToString() != "")
                {
                    model.F_RANGEX = decimal.Parse(ds.Tables[0].Rows[0]["F_RANGEX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RANGEY"] != null && ds.Tables[0].Rows[0]["F_RANGEY"].ToString() != "")
                {
                    model.F_RANGEY = decimal.Parse(ds.Tables[0].Rows[0]["F_RANGEY"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_INSTANCEID"] != null && ds.Tables[0].Rows[0]["F_INSTANCEID"].ToString() != "")
                {
                    model.F_INSTANCEID = int.Parse(ds.Tables[0].Rows[0]["F_INSTANCEID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CUSTOMERID"] != null && ds.Tables[0].Rows[0]["F_CUSTOMERID"].ToString() != "")
                {
                    model.F_CUSTOMERID = int.Parse(ds.Tables[0].Rows[0]["F_CUSTOMERID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRMANID"] != null && ds.Tables[0].Rows[0]["F_REPAIRMANID"].ToString() != "")
                {
                    model.F_REPAIRMANID = int.Parse(ds.Tables[0].Rows[0]["F_REPAIRMANID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRMANNAME"] != null && ds.Tables[0].Rows[0]["F_REPAIRMANNAME"].ToString() != "")
                {
                    model.F_REPAIRMANNAME = ds.Tables[0].Rows[0]["F_REPAIRMANNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRMANPHONE"] != null && ds.Tables[0].Rows[0]["F_REPAIRMANPHONE"].ToString() != "")
                {
                    model.F_REPAIRMANPHONE = ds.Tables[0].Rows[0]["F_REPAIRMANPHONE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRREQUEST"] != null && ds.Tables[0].Rows[0]["F_REPAIRREQUEST"].ToString() != "")
                {
                    model.F_REPAIRREQUEST = ds.Tables[0].Rows[0]["F_REPAIRREQUEST"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANID"] != null && ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANID"].ToString() != "")
                {
                    model.F_REPAIRCLOSEMANID = int.Parse(ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANNAME"] != null && ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANNAME"].ToString() != "")
                {
                    model.F_REPAIRCLOSEMANNAME = ds.Tables[0].Rows[0]["F_REPAIRCLOSEMANNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRCLOSEREASONS"] != null && ds.Tables[0].Rows[0]["F_REPAIRCLOSEREASONS"].ToString() != "")
                {
                    model.F_REPAIRCLOSEREASONS = ds.Tables[0].Rows[0]["F_REPAIRCLOSEREASONS"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPTID"] != null && ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPTID"].ToString() != "")
                {
                    model.F_REPAIRCLOSEREPTID = int.Parse(ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPTID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPT"] != null && ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPT"].ToString() != "")
                {
                    model.F_REPAIRCLOSEREPT = ds.Tables[0].Rows[0]["F_REPAIRCLOSEREPT"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRLEVEL"] != null && ds.Tables[0].Rows[0]["F_REPAIRLEVEL"].ToString() != "")
                {
                    model.F_REPAIRLEVEL = int.Parse(ds.Tables[0].Rows[0]["F_REPAIRLEVEL"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REPAIRLEVELNAME"] != null && ds.Tables[0].Rows[0]["F_REPAIRLEVELNAME"].ToString() != "")
                {
                    model.F_REPAIRLEVELNAME = ds.Tables[0].Rows[0]["F_REPAIRLEVELNAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_SENTORDERTIME"] != null && ds.Tables[0].Rows[0]["F_SENTORDERTIME"].ToString() != "")
                {
                    model.F_SENTORDERTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_SENTORDERTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_USERPHONE"] != null && ds.Tables[0].Rows[0]["F_USERPHONE"].ToString() != "")
                {
                    model.F_USERPHONE = ds.Tables[0].Rows[0]["F_USERPHONE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITTIME"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITTIME"].ToString() != "")
                {
                    model.F_RETURNVISITTIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_RETURNVISITTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_REQUESTSERVICETIME"] != null && ds.Tables[0].Rows[0]["F_REQUESTSERVICETIME"].ToString() != "")
                {
                    model.F_REQUESTSERVICETIME = DateTime.Parse(ds.Tables[0].Rows[0]["F_REQUESTSERVICETIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_SERVICETYPE"] != null && ds.Tables[0].Rows[0]["F_SERVICETYPE"].ToString() != "")
                {
                    model.F_SERVICETYPE = ds.Tables[0].Rows[0]["F_SERVICETYPE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_DECLARATIONTIME"] != null && ds.Tables[0].Rows[0]["F_DECLARATIONTIME"].ToString() != "")
                {
                    model.F_DECLARATIONTIME = decimal.Parse(ds.Tables[0].Rows[0]["F_DECLARATIONTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_SERVICENATURE"] != null && ds.Tables[0].Rows[0]["F_SERVICENATURE"].ToString() != "")
                {
                    model.F_SERVICENATURE = ds.Tables[0].Rows[0]["F_SERVICENATURE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_SERVICEWAY"] != null && ds.Tables[0].Rows[0]["F_SERVICEWAY"].ToString() != "")
                {
                    model.F_SERVICEWAY = ds.Tables[0].Rows[0]["F_SERVICEWAY"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITMAN"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITMAN"].ToString() != "")
                {
                    model.F_RETURNVISITMAN = ds.Tables[0].Rows[0]["F_RETURNVISITMAN"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITID"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITID"].ToString() != "")
                {
                    model.F_RETURNVISITID = int.Parse(ds.Tables[0].Rows[0]["F_RETURNVISITID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITOPINION"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITOPINION"].ToString() != "")
                {
                    model.F_RETURNVISITOPINION = ds.Tables[0].Rows[0]["F_RETURNVISITOPINION"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_RETURNVISITPROBLEM"] != null && ds.Tables[0].Rows[0]["F_RETURNVISITPROBLEM"].ToString() != "")
                {
                    model.F_RETURNVISITPROBLEM = ds.Tables[0].Rows[0]["F_RETURNVISITPROBLEM"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_CallId"] != null && ds.Tables[0].Rows[0]["F_CallId"].ToString() != "")
                {
                    model.F_RETURNVISITID = int.Parse(ds.Tables[0].Rows[0]["F_CallId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CREATEBYids"] != null && ds.Tables[0].Rows[0]["F_CREATEBYids"].ToString() != "")
                {
                    model.F_CREATEBYids = ds.Tables[0].Rows[0]["F_CREATEBYids"].ToString();
                }

                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select F_WORKORDERID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,
F_CODE,F_WORKORDERNAME,F_NUMBER,F_CUSTOMERNAME,F_CUSTOMERTELEPHONE,F_LINKMAN,F_LINKMANTELEPHONE,
F_ADSLACCOUNT,F_BANDWIDTH,F_STANDARDADDRESS,F_INSTALLADDRESS,F_KSHADDRESSCODE,F_PROVINCE,F_CITY,
F_AREA,F_ROAD,F_HOUSING,F_WORKORDERFROM,F_WORKORDERLEVELID,F_FILEFLAG,F_CONTENT,F_CREATEBY,F_CREATEDATE,
F_DEPTCODE,F_EMPCODE,F_DEPTID,F_USERID,F_USERNAME,F_RETURNVISITFLAG,F_RETURNVISITSTATE,F_RETURNVISITRESULT
,F_RETURNVISITCONTENT,F_DELETEFLAG,F_ALLUSETIMES,F_STARTTIME,F_ENDTIME,F_REMAINDERTIME,F_REMAINDERENDTIME,
F_SUBSCRIBETIME1,F_SUBSCRIBETIME2,F_ACCEPTTIMELIMIT,F_ASKFINISHTIME,F_OVERTIMES,F_FORMID,F_HASTENCOUNTS,F_RANGEID,
F_RANGEX,F_RANGEY,F_INSTANCEID,F_CUSTOMERID,F_REPAIRMANID,F_REPAIRMANNAME,F_REPAIRMANPHONE,F_REPAIRREQUEST,F_REPAIRCLOSEMANID,
F_REPAIRCLOSEMANNAME,F_REPAIRCLOSEREASONS,F_REPAIRCLOSEREPTID,F_REPAIRCLOSEREPT,F_REPAIRLEVEL,F_REPAIRLEVELNAME,F_SENTORDERTIME,
F_USERPHONE,F_RETURNVISITTIME,F_REQUESTSERVICETIME,F_SERVICETYPE,F_DECLARATIONTIME,F_SERVICENATURE,F_SERVICEWAY,F_RETURNVISITMAN,
F_RETURNVISITID,F_RETURNVISITOPINION,F_RETURNVISITPROBLEM ,F_CallId,F_CREATEBYids ");
            strSql.Append(" FROM T_Wo_WorkOrderBase ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(@" F_WORKORDERID,F_WORKORDERTYPEID,F_WORKORDERSTATEID,
F_CODE,F_WORKORDERNAME,F_NUMBER,F_CUSTOMERNAME,F_CUSTOMERTELEPHONE,F_LINKMAN,F_LINKMANTELEPHONE,
F_ADSLACCOUNT,F_BANDWIDTH,F_STANDARDADDRESS,F_INSTALLADDRESS,F_KSHADDRESSCODE,F_PROVINCE,F_CITY,F_AREA,
F_ROAD,F_HOUSING,F_WORKORDERFROM,F_WORKORDERLEVELID,F_FILEFLAG,F_CONTENT,F_CREATEBY,F_CREATEDATE,F_DEPTCODE,
F_EMPCODE,F_DEPTID,F_USERID,F_USERNAME,F_RETURNVISITFLAG,F_RETURNVISITSTATE,F_RETURNVISITRESULT,F_RETURNVISITCONTENT,
F_DELETEFLAG,F_ALLUSETIMES,F_STARTTIME,F_ENDTIME,F_REMAINDERTIME,F_REMAINDERENDTIME,F_SUBSCRIBETIME1,F_SUBSCRIBETIME2,
F_ACCEPTTIMELIMIT,F_ASKFINISHTIME,F_OVERTIMES,F_FORMID,F_HASTENCOUNTS,F_RANGEID,F_RANGEX,F_RANGEY,F_INSTANCEID,F_CUSTOMERID,
F_REPAIRMANID,F_REPAIRMANNAME,F_REPAIRMANPHONE,F_REPAIRREQUEST,F_REPAIRCLOSEMANID,F_REPAIRCLOSEMANNAME,F_REPAIRCLOSEREASONS,
F_REPAIRCLOSEREPTID,F_REPAIRCLOSEREPT,F_REPAIRLEVEL,F_REPAIRLEVELNAME,F_SENTORDERTIME,F_USERPHONE,F_RETURNVISITTIME,F_REQUESTSERVICETIME,
F_SERVICETYPE,F_DECLARATIONTIME,F_SERVICENATURE,F_SERVICEWAY,F_RETURNVISITMAN,F_RETURNVISITID,F_RETURNVISITOPINION,F_RETURNVISITPROBLEM ,F_CallId,F_CREATEBYids");
            strSql.Append(" FROM T_Wo_WorkOrderBase ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM T_Wo_WorkOrderBase ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.F_WORKORDERID desc");
            }
            strSql.Append(")AS Row, T.*  from T_Wo_WorkOrderBase T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }
        #region
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "T_Wo_WorkOrderBase";
            parameters[1].Value = "F_WORKORDERID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/
        #endregion
        #endregion  Method

        #region  编辑工单信息
        /// <summary>
        /// 编辑工单信息
        /// </summary>
        /// <param name="model">工单实体</param>
        /// <returns></returns>
        public bool UpdateWorkOrderInfoModel(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            //历史工单id
            int historyId = 0;
            Model.T_Wo_WorkOrderBase modelbase = GetModel(model.F_WORKORDERID);

            // 提交
            if (model.F_WORKORDERSTATEID > 0)
            {
                if (model.F_RETURNVISITFLAG == null)
                {
                    model.F_RETURNVISITFLAG = 0;
                }

                if (model.F_REQUESTSERVICETIME.HasValue && model.F_REQUESTSERVICETIME.Value.Year == 1)
                {
                    model.F_REQUESTSERVICETIME = null;
                }
                else if (model.F_REQUESTSERVICETIME.HasValue)
                {
                  //  model.F_REQUESTSERVICETIME = model.F_REQUESTSERVICETIME.Value.AddDays(1).AddSeconds(-1);
                }
                else
                {
                    model.F_REQUESTSERVICETIME = null;
                }

                //  if (model.F_HOUSING == "表扬" || model.F_HOUSING == "咨询" || model.F_HOUSING == "挂失")
                if (model.F_HOUSING == "表扬")
                {
                    //  model.F_WORKORDERTYPEID = 3;


                    model.F_WORKORDERTYPEID = 3;

                    if (model.F_HOUSING == "表扬")
                    {
                        if (model.HistoryOrderList != null && model.HistoryOrderList.Count > 0)
                        {
                            //先看看这个 工单有没有表扬的记录  有的话给删掉

                            DataTable dt = NoticeBll.GetList(" OrderId='" + model.F_WORKORDERID + "'").Tables[0];

                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {
                                    int NoticeId = Convert.ToInt32(dr["NoticeId"]);
                                    Model.T_Wo_WorkOrderNotice modelNotice = NoticeBll.GetModel(NoticeId);
                                    int userid = Convert.ToInt32(model.F_LINKMAN);
                                    
                                    NoticeBll.Delete(NoticeId);
                                }

                            }


                            foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                            {
                                Model.T_Wo_WorkOrderNotice modelNotice = new Model.T_Wo_WorkOrderNotice();
                                modelNotice.OrderId = model.F_WORKORDERID;
                                modelNotice.NoticeType = 0;
                                modelNotice.NoticeState = 1;
                                modelNotice.NoticeDeptName = historyModel.F_NEXTOWNERARRID.ToMyString();
                                modelNotice.NoticeDeptId = historyModel.F_OPTBTNID.ToInt32();
                                NoticeBll.Add(modelNotice);
                            }
                        }
                    }
                    if (model.F_RETURNVISITFLAG == 1)
                    {
                        model.F_WORKORDERSTATEID = 3;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "待回访";
                    }
                    else
                    {
                        model.F_ENDTIME = DateTime.Now;
                        model.F_WORKORDERSTATEID = 5;
                        model.F_REPAIRREQUEST = "已处理";
                    }

                }
                //  if (model.F_WORKORDERTYPEID == 1)
                else if (model.F_WORKORDERTYPEID == 1)
                {
                    //转单

                    if (model.HistoryOrderList != null)
                    {
                        foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                        {
                            historyModel.F_INSTANCEID = model.F_WORKORDERID;
                            historyModel.F_OPTDATE = DateTime.Now;
                            historyModel.F_WORKORDERSTATEID = 0;
                            historyModel.F_StateName = "未处理";
                            historyModel.NeedReplayTime = model.F_REQUESTSERVICETIME;
                            historyId = InsertWorkOrderHistoryModel(historyModel);
                        }
                        if (model.HistoryOrderList.Count > 0)
                        {
                            historyId = model.HistoryOrderList.Count;
                        }
                    }


                    if (model.F_HOUSING == "咨询" || model.F_HOUSING == "挂失")
                    {
                        #region
                        //if (model.F_RETURNVISITFLAG!= 1)
                        //{
                        //    model.F_WORKORDERSTATEID = 3;
                        //    model.F_ENDTIME = DateTime.Now;
                        //    model.F_REPAIRREQUEST = "待回访";
                        //}
                        //else
                        //{
                        //    model.F_WORKORDERSTATEID = 1;
                        //    model.F_ENDTIME = DateTime.Now;
                        //    model.F_REPAIRREQUEST = "处理中";
                        //}
                        #endregion
                        model.F_WORKORDERSTATEID = 1;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "已转办";
                        #region
                        //if (model.F_RETURNVISITFLAG != 1)
                        //{

                        //}
                        //else
                        //{
                        //    model.F_WORKORDERSTATEID = 3;
                        //    model.F_ENDTIME = DateTime.Now;
                        //    model.F_REPAIRREQUEST = "待回访";
                        //}


                        //foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                        //{
                        //    historyModel.F_INSTANCEID = model.F_WORKORDERID;
                        //    historyModel.F_StateName = "处理中";
                        //    historyId = InsertWorkOrderHistoryModel(historyModel);
                        //}
                        #endregion
                    }

                }
                else if (model.F_HOUSING == "投诉")
                {
                    if (model.F_RETURNVISITFLAG == 1)
                    {
                        model.F_WORKORDERSTATEID = 3;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "待回访";
                    }
                    else
                    {
                        model.F_WORKORDERSTATEID = 4;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "待定责";
                    }

                    foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                    {
                        historyId = InsertWorkOrderHistoryModel(historyModel);
                    }
                }
                else if (model.F_HOUSING == "建议")
                {

                    if (model.F_RETURNVISITFLAG == 1)
                    {
                        model.F_WORKORDERSTATEID = 3;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "待回访";
                    }
                    else
                    {
                        model.F_WORKORDERSTATEID = 5;
                        model.F_ENDTIME = DateTime.Now;
                        model.F_REPAIRREQUEST = "已处理";
                    }


                    foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                    {
                        historyId = InsertWorkOrderHistoryModel(historyModel);
                    }
                }


                //记录派单时间计算工单超时
                model.F_SENTORDERTIME = DateTime.Now;
                //超时时间 直接结束的工单超时时间为0
                //int tempn = (int)DateUtil.DateDiff(DateInterval.Second, modelbase.F_CREATEBY.ToDateTime().AddDays(5), DateTime.Now);
                //if (tempn < 0)
                //{
                //    tempn = 0;
                //}
                model.F_OVERTIMES = 0;

            }
            string F_HOUSINGint = "0";
            switch (model.F_HOUSING)
            {
                case "咨询":
                    F_HOUSINGint = "1";
                    break;
                case "投诉":
                    F_HOUSINGint = "2";
                    break;
                case "建议":
                    F_HOUSINGint = "3";
                    break;
                case "表扬":
                    F_HOUSINGint = "4";
                    break;
                case "挂失":
                    F_HOUSINGint = "5";
                    break;
            }
            DbHelperSQL.ExecuteSql(string.Format("update T_Call_CallRecords set F_ServiceType={0}  where CallId=(select top 1 F_KSHADDRESSCODE from  T_Wo_WorkOrderBase where F_WORKORDERID={1})", F_HOUSINGint, model.F_WORKORDERID));

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_CUSTOMERID=@F_CUSTOMERID,");
            strSql.Append("F_OVERTIMES=@F_OVERTIMES,");
            strSql.Append("F_SENTORDERTIME=@F_SENTORDERTIME,");
            strSql.Append("F_CUSTOMERNAME=@F_CUSTOMERNAME,");
            strSql.Append("F_CUSTOMERTELEPHONE=@F_CUSTOMERTELEPHONE,");
            //strSql.Append("F_WORKORDERFROM=@F_WORKORDERFROM,");
            strSql.Append("F_RETURNVISITPROBLEM=@F_RETURNVISITPROBLEM,");
            strSql.Append("F_REPAIRLEVEL=@F_REPAIRLEVEL,");
            strSql.Append("F_ADSLACCOUNT=@F_ADSLACCOUNT,");
            strSql.Append("F_WORKORDERLEVELID=@F_WORKORDERLEVELID,");
            strSql.Append("F_WORKORDERNAME=@F_WORKORDERNAME,");
            strSql.Append("F_CONTENT=@F_CONTENT,");
            strSql.Append("F_WORKORDERTYPEID=@F_WORKORDERTYPEID,");
            //strSql.Append("F_USERID=@F_USERID,");
            //strSql.Append("F_REPAIRMANNAME=@F_REPAIRMANNAME,");
            // strSql.Append("F_CREATEDATE=@F_CREATEDATE,");
            strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
            strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST,");
            strSql.Append("F_INSTALLADDRESS=@F_INSTALLADDRESS,");
            strSql.Append("F_DEPTID=@F_DEPTID,");
            strSql.Append("F_DEPTCODE=@F_DEPTCODE,");
            strSql.Append("F_CREATEBY=@F_CREATEBY,");
            strSql.Append("F_USERNAME=@F_USERNAME,");
            strSql.Append("F_REQUESTSERVICETIME=@F_REQUESTSERVICETIME,");
            strSql.Append("F_RETURNVISITCONTENT=@F_RETURNVISITCONTENT,");
            strSql.Append("F_RETURNVISITFLAG=@F_RETURNVISITFLAG,");
            strSql.Append("F_RETURNVISITTIME =@F_RETURNVISITTIME,");
            strSql.Append("F_CODE =@F_CODE,");
            strSql.Append("F_FILEFLAG =@F_FILEFLAG,");
            strSql.Append("F_HOUSING =@F_HOUSING,");
            // strSql.Append("F_LINKMAN =@F_LINKMAN,");
            //strSql.Append("F_REPAIRMANID =@F_REPAIRMANID,");
            strSql.Append("F_REMAINDERENDTIME =@F_REMAINDERENDTIME,");
            strSql.Append("F_RETURNVISITOPINION =@F_RETURNVISITOPINION,");
            strSql.Append("F_ENDTIME =@F_ENDTIME,");
            strSql.Append("F_FORMID =@F_FORMID");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");


            SqlParameter[] parameters = {
                    new SqlParameter("@F_CUSTOMERID", model.F_CUSTOMERID),
                    new SqlParameter("@F_CUSTOMERNAME", model.F_CUSTOMERNAME),
                    new SqlParameter("@F_CUSTOMERTELEPHONE", model.F_CUSTOMERTELEPHONE),
                    new SqlParameter("@F_OVERTIMES", model.F_OVERTIMES),
                    new SqlParameter("@F_RETURNVISITPROBLEM", model.F_RETURNVISITPROBLEM),
                    new SqlParameter("@F_REPAIRLEVEL", model.F_REPAIRLEVEL),
                    new SqlParameter("@F_ADSLACCOUNT", model.F_ADSLACCOUNT),
                    new SqlParameter("@F_WORKORDERLEVELID", model.F_WORKORDERLEVELID),
                    new SqlParameter("@F_WORKORDERNAME", model.F_WORKORDERNAME),
                    new SqlParameter("@F_CONTENT", model.F_CONTENT),
                    new SqlParameter("@F_WORKORDERTYPEID", model.F_WORKORDERTYPEID),
                    new SqlParameter("@F_USERID",model.F_USERID),
					//new SqlParameter("@F_REPAIRMANNAME", SqlDbType.NVarChar,200),
					//new SqlParameter("@F_CREATEDATE", DateTime.Now),
                    new SqlParameter("@F_WORKORDERSTATEID", model.F_WORKORDERSTATEID),
                    new SqlParameter("@F_REPAIRREQUEST", model.F_REPAIRREQUEST),
                    new SqlParameter("@F_INSTALLADDRESS", model.F_INSTALLADDRESS),
                    new SqlParameter("@F_DEPTID", model.F_DEPTID),
                    new SqlParameter("@F_DEPTCODE", model.F_DEPTCODE),
                    new SqlParameter("@F_CREATEBY", model.F_CREATEBY),
                    new SqlParameter("@F_USERNAME", model.F_USERNAME),
                    new SqlParameter("@F_REQUESTSERVICETIME",model.F_REQUESTSERVICETIME),
                    new SqlParameter("@F_RETURNVISITCONTENT", model.F_RETURNVISITCONTENT),
                    new SqlParameter("@F_RETURNVISITFLAG", model.F_RETURNVISITFLAG),
                    new SqlParameter("@F_RETURNVISITTIME ", model.F_RETURNVISITTIME),
                    new SqlParameter("@F_CODE ", model.F_CODE),
                    new SqlParameter("@F_FILEFLAG", model.F_FILEFLAG),
                    new SqlParameter("@F_HOUSING ", model.F_HOUSING),
                   // new SqlParameter("@F_LINKMAN", SqlDbType.NVarChar,200),
                    //new SqlParameter("@F_REPAIRMANID", SqlDbType.Int,4),
                    new SqlParameter("@F_REMAINDERENDTIME",model.F_REMAINDERENDTIME),
                    new SqlParameter("@F_RETURNVISITOPINION", model.F_RETURNVISITOPINION),
                    new SqlParameter("@F_FORMID", historyId),
                    new SqlParameter("@F_ENDTIME", model.F_ENDTIME),
                    new SqlParameter("@F_SENTORDERTIME", model.F_SENTORDERTIME),
                    new SqlParameter("@F_WORKORDERID", model.F_WORKORDERID)};


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }


        }

        //业务类型
        DAL.T_Wo_WorkOrderType dal = new T_Wo_WorkOrderType();

        /// <summary>
        /// 获取订单编号
        /// </summary>
        /// <param name="bussnessType">业务类型</param>
        /// <returns></returns>
        public string GetOrderNumber(int bussnessType)
        {
            string orderNumber = "";

            if (bussnessType > 0)
            {
                Model.T_Wo_WorkOrderType model = dal.GetModel(bussnessType);
                if (model != null && !string.IsNullOrEmpty(model.F_ParentName))
                {
                    orderNumber += model.F_ParentName;
                }
            }
            orderNumber += DateTime.Now.ToString("yyyyMMdd");
            //当前最大编号
            string maxOrderNum = GetMaxOrderNumber(orderNumber);

            if (!string.IsNullOrEmpty(maxOrderNum))
            {
                orderNumber += (int.Parse(("1" + maxOrderNum.Substring(10)).ToString()) + 1).ToString().Substring(1);
            }
            else
            {
                orderNumber += "0001";
            }
            return orderNumber;
        }

        /// <summary>
        /// 获取最大编号
        /// </summary>
        /// <param name="orderNumStart">编号前面部门（ZX20180322）</param>
        /// <returns></returns>
        public string GetMaxOrderNumber(string orderNumStart)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  max(F_CODE) from T_Wo_WorkOrderBase ");
            strSql.Append(" where F_CODE like '" + orderNumStart + "%' ");


            ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model = new ZXDT.CallCenter.Model.T_Wo_WorkOrderBase();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 插入转办信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int InsertWorkOrderHistoryModel(ZXDT.CallCenter.Model.T_Wo_WorkOrderHistory model)
        {
            object time = model.ReplayTime;
            if (model.ReplayTime.Year == 1)
            {
                time = null;
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wo_WorkOrderHistory(");
            strSql.Append("F_WORKORDERSTATEID,F_OPTUSERID,F_OPTDATE,F_NEXTOWNERARRID,F_REMARK,F_OPTBTNID,F_INSTANCEID,F_StateName,F_UserName,NeedReplayTime,F_TASKFLAG,ReplayTime)");
            strSql.Append(" values (");
            strSql.Append("@F_WORKORDERSTATEID,@F_OPTUSERID,@F_OPTDATE,@F_NEXTOWNERARRID,@F_REMARK,@F_OPTBTNID,@F_INSTANCEID,@F_StateName,@F_UserName,@NeedReplayTime,@F_TASKFLAG,@ReplayTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_OPTUSERID", SqlDbType.Int,4),
                    new SqlParameter("@F_OPTDATE", SqlDbType.DateTime),
                    new SqlParameter("@F_NEXTOWNERARRID", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_REMARK", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_OPTBTNID", SqlDbType.Int,4),
                    new SqlParameter("@F_INSTANCEID", SqlDbType.Int,4),
                    new SqlParameter("@F_StateName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_UserName", SqlDbType.NVarChar,200),
                    new SqlParameter("@NeedReplayTime", SqlDbType.DateTime),
                    new SqlParameter("@F_TASKFLAG", SqlDbType.Int,4),
                    new SqlParameter("@ReplayTime", time),

                                        };
            parameters[0].Value = model.F_WORKORDERSTATEID;
            parameters[1].Value = model.F_OPTUSERID;
            parameters[2].Value = model.F_OPTDATE;
            parameters[3].Value = model.F_NEXTOWNERARRID;
            parameters[4].Value = model.F_REMARK;
            parameters[5].Value = model.F_OPTBTNID;
            parameters[6].Value = model.F_INSTANCEID;
            parameters[7].Value = model.F_StateName;
            parameters[8].Value = model.F_UserName;
            parameters[9].Value = model.NeedReplayTime;
            parameters[10].Value = model.F_TASKFLAG;


            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        #endregion  ExtensionMethod

        #region 提交转办信息

        public bool EditMyOrderInfo(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            bool EditStatus = false;

            //历史工单id
            int historyId = EditMyOrderHistoryInfo(model);

            //修改历史记录成功
            if (historyId > 0)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Wo_WorkOrderBase set ");
                strSql.Append("F_DEPTID=@F_DEPTID,");
                strSql.Append("F_DEPTCODE=@F_DEPTCODE,");
                strSql.Append("F_CREATEBY=@F_CREATEBY,");
                strSql.Append("F_USERNAME=@F_USERNAME,");
                strSql.Append("F_REQUESTSERVICETIME=@F_REQUESTSERVICETIME,");
                strSql.Append("F_FORMID =@F_FORMID,");
                strSql.Append("F_REMAINDERENDTIME =@F_REMAINDERENDTIME,");
                strSql.Append("F_RETURNVISITRESULT =@F_RETURNVISITRESULT,");
                strSql.Append("F_ROAD =@F_ROAD,");
                strSql.Append("F_RETURNVISITOPINION =@F_RETURNVISITOPINION");
                strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
                SqlParameter[] parameters = {
                    new SqlParameter("@F_DEPTID", SqlDbType.Int,4),
                    new SqlParameter("@F_DEPTCODE", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CREATEBY", SqlDbType.Int,4),
                    new SqlParameter("@F_USERNAME", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_REQUESTSERVICETIME",SqlDbType.DateTime),
                    new SqlParameter("@F_FORMID", SqlDbType.Int,4),
                      new SqlParameter("@F_REMAINDERENDTIME",SqlDbType.DateTime),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_ROAD", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
                parameters[0].Value = model.F_DEPTID;
                parameters[1].Value = model.F_DEPTCODE;
                parameters[2].Value = model.F_CREATEBY;
                parameters[3].Value = model.F_USERNAME;
                parameters[4].Value = model.F_REQUESTSERVICETIME;
                parameters[5].Value = historyId;
                parameters[6].Value = model.F_REMAINDERENDTIME;
                parameters[7].Value = model.F_RETURNVISITRESULT;
                parameters[8].Value = model.F_ROAD;
                parameters[9].Value = model.F_RETURNVISITOPINION;
                parameters[10].Value = model.F_WORKORDERID;
                EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
            }
            return EditStatus;

        }

        /// <summary>
        /// 处理转办信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SubmitOrder(Model.T_Wo_WorkOrderHistory model)
        {
            bool EditStatus = false;
            DAL.T_Wo_WorkOrderHistory bllOrderHistory = new DAL.T_Wo_WorkOrderHistory();

            //如果工单状态处理中
            if (model.F_WORKORDERSTATEID == 0)
            {
                //更新新本次转办信息
                Model.T_Wo_WorkOrderHistory eidthistoryModel = bllOrderHistory.GetModel(model.F_HISTORYID);
                //工单主键
                eidthistoryModel.F_REMARK = model.F_REMARK;//处理内容
                eidthistoryModel.F_StateName = "已处理";
                eidthistoryModel.F_WORKORDERSTATEID = 1;
                eidthistoryModel.ReplayTime = DateTime.Now;

                if (bllOrderHistory.Update(eidthistoryModel))
                {
                    //判断是否所有的转办已经被处理 F_WORKORDERSTATEID=1 处理中  F_WORKORDERTYPEID=1转单
                    int n = bllOrderHistory.GetRecordCount(string.Format("F_WORKORDERSTATEID=0   and F_StateName='未处理'     and F_INSTANCEID=(select F_WORKORDERID from T_Wo_WorkOrderBase where F_WORKORDERID='{0}' and F_WORKORDERSTATEID=1 and F_WORKORDERTYPEID=1)", eidthistoryModel.F_INSTANCEID));// (F_REMARK != '已撤回' or F_REMARK IS NULL)
                    EditStatus = true;
                    if (n == 0)
                    {
                        LogAciton.AddAction(eidthistoryModel.F_UserName, eidthistoryModel.F_OPTUSERID.ToInt32(), "历史工单模块调用工单模块", "模块调用", "DAL/T_Wo_WorkOrderBase/SubmitOrder", "DAL/T_Wo_WorkOrderBase/UpdateOrderToHF");
                        UpdateOrderToHF(eidthistoryModel.F_INSTANCEID.ToInt32());
                    }
                    //如果有转办信息插入转办信息
                    // historyId = InsertWorkOrderHistoryModel(historyModel);
                }


            }
            return EditStatus;

        }


        /// <summary>
        /// 处理转办信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SubmitOrder(Model.T_Wo_WorkOrderHistory model, int? workorderid, string F_username)
        {
            bool EditStatus = false;
            DAL.T_Wo_WorkOrderHistory bllOrderHistory = new DAL.T_Wo_WorkOrderHistory();

            //如果工单状态处理中
            if (model.F_WORKORDERSTATEID == 0)
            {

                if (model.F_HISTORYID != 0)//cong待回访中驳回的时候 model.F_HISTORYID=0
                {

                    //DbHelperSQL.ExecuteSql("  UPDATE T_Wo_WorkOrderHistory SET F_WORKORDERSTATEID=1, F_StateName ='已处理', F_REMARK='" + model.F_REMARK + "',ReplayTime=getdate() WHERE  F_INSTANCEID='" + workorderid + "' AND F_UserName='" + F_username + "' and NeedReplayTime is not null AND F_StateName NOT LIKE '%撤回%'  AND F_StateName NOT LIKE '%驳回%'");
                    DbHelperSQL.ExecuteSql("  UPDATE T_Wo_WorkOrderHistory SET F_WORKORDERSTATEID=1, F_StateName ='已处理', F_REMARK='" + model.F_REMARK + "',ReplayTime=getdate() WHERE  F_HISTORYID='" + model.F_HISTORYID + "' ");

                    ////更新新本次转办信息
                    //Model.T_Wo_WorkOrderHistory eidthistoryModel = bllOrderHistory.GetModel(model.F_HISTORYID);
                    ////工单主键
                    //eidthistoryModel.F_REMARK = model.F_REMARK;//处理内容
                    //eidthistoryModel.F_StateName = "已处理";
                    //eidthistoryModel.F_WORKORDERSTATEID = 1;
                    //eidthistoryModel.ReplayTime = DateTime.Now;

                    //if (bllOrderHistory.Update(eidthistoryModel))
                    //{
                    //  判断是否所有的转办已经被处理 F_WORKORDERSTATEID = 1 处理中 F_WORKORDERTYPEID = 1转单
                    int n = bllOrderHistory.GetRecordCount(string.Format("F_WORKORDERSTATEID=0   and F_StateName='未处理'     and F_INSTANCEID=(select F_WORKORDERID from T_Wo_WorkOrderBase where F_WORKORDERID='{0}' and F_WORKORDERSTATEID=1 and F_WORKORDERTYPEID=1)", workorderid));// (F_REMARK != '已撤回' or F_REMARK IS NULL)
                    EditStatus = true;
                    if (n == 0)
                    {
                        LogAciton.AddAction(F_username, 0, "历史工单模块调用工单模块", "模块调用workorderid="+ workorderid.ToString(), "DAL/T_Wo_WorkOrderBase/SubmitOrder", "DAL/T_Wo_WorkOrderBase/UpdateOrderToHF1");
                        UpdateOrderToHF(workorderid == null ? 0 : workorderid.ToInt32());
                    }

                    //}
                }
                else
                {
                    //
                    int n = DbHelperSQL.ExecuteSql("  UPDATE T_Wo_WorkOrderHistory SET F_REMARK='" + model.F_REMARK + "',ReplayTime=getdate() WHERE  F_INSTANCEID='" + workorderid + "' AND F_UserName='" + F_username + "' and NeedReplayTime is not null AND ReplayTime IS NOT NULL ");

                    EditStatus = true;
                    if (n == 1)
                    {
                        LogAciton.AddAction(F_username, 0, "历史工单模块调用工单模块", "模块调用workorderid=" + workorderid.ToString(), "DAL/T_Wo_WorkOrderBase/SubmitOrder", "DAL/T_Wo_WorkOrderBase/UpdateOrderToHF2");
                        UpdateOrderToHF(workorderid == null ? 0 : workorderid.ToInt32());
                    }
                }

            }
            return EditStatus;

        }

        //转单处理完  转回复
        public void UpdateOrderToHF(int F_WORKORDERID)
        {
            Model.T_Wo_WorkOrderBase modelbase = GetModel(F_WORKORDERID);

            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append(" F_REMAINDERTIME=GETDATE(), ");
            if (modelbase.F_RETURNVISITFLAG == 1)
            {
                strSql.Append("F_REPAIRREQUEST='待回访', ");
                strSql.Append("F_WORKORDERSTATEID=3,");
            }
            else if (modelbase.F_HOUSING == "投诉")
            {
                strSql.Append("F_ENDTIME=GETDATE(),  ");
                strSql.Append("F_WORKORDERSTATEID=4,");
                strSql.Append("F_REPAIRREQUEST='待定责', ");
            }
            else
            {
                strSql.Append("F_ENDTIME=GETDATE(),  ");
                strSql.Append("F_WORKORDERSTATEID=5,");
                strSql.Append("F_REPAIRREQUEST='已处理', ");
            }
            //  strSql.Append("F_OVERTIMES=CASE WHEN ISNULL(DATEDIFF(second, DATEADD(day,5,F_SENTORDERTIME), GETDATE()),0)<1  THEN 0 ELSE DATEDIFF(second, DATEADD(day,5,F_SENTORDERTIME), GETDATE()) END ");

            //计划回访时间 F_RETURNVISITTIME（原来的派单时间+5改成计划回访时间）
            strSql.Append("F_OVERTIMES=CASE WHEN ISNULL(DATEDIFF(second, F_RETURNVISITTIME, GETDATE()),0)<1  THEN 0 ELSE DATEDIFF(second, F_RETURNVISITTIME, GETDATE()) END ");

            //转单F_WORKORDERTYPEID= 1转单 3客服处理  处理中    F_WORKORDERSTATEID=0未处理 1处理中  2已办结（结束） 3待回访 4待定责 5待通知 
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID and F_WORKORDERTYPEID=1 and F_WORKORDERSTATEID=1");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WORKORDERID",F_WORKORDERID)};


            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 回访转工单
        /// </summary>
        /// <param name="F_WORKORDERID"></param>
        /// <param name="type">type 0转单 1定责</param>
        public bool UpdateOrderToZD(Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
            strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
            strSql.Append("F_ROAD=@F_ROAD,");
            strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
            strSql.Append("F_WORKORDERSTATEID=1,");//转单
            strSql.Append("F_WORKORDERTYPEID=1,");//待回访转处理中
            strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID  and F_WORKORDERSTATEID=3");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_REMAINDERENDTIME",model.F_REMAINDERENDTIME),
                    new SqlParameter("@F_RETURNVISITRESULT", model.F_RETURNVISITRESULT),
                    new SqlParameter("@F_ROAD", ""),
                    new SqlParameter("@F_RETURNVISITOPINION", model.F_RETURNVISITOPINION),
                    new SqlParameter("@F_REPAIRREQUEST","回访转单处理中"),
                    new SqlParameter("@F_WORKORDERID", model.F_WORKORDERID)};
            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 回访转定责
        /// </summary>
        /// <param name="F_WORKORDERID"></param>
        /// <param name="type">type 0转单 1定责</param>
        public bool UpdateOrderToDZ(Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
            strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
            strSql.Append("F_ROAD=@F_ROAD,");
            strSql.Append("F_ENDTIME=@F_ENDTIME,");
            //原来的回访时间的判断是  派单时间加5 改成 计划回访时间 F_RETURNVISITTIME
            //  strSql.Append("F_OVERTIMES= CASE WHEN ISNULL(DATEDIFF(second, DATEADD(day,5,F_SENTORDERTIME), GETDATE()),0)< 1 OR F_HOUSING!= '投诉' THEN 0 ELSE DATEDIFF(second, DATEADD(day,5,F_SENTORDERTIME), GETDATE()) END,");
            strSql.Append("F_OVERTIMES= CASE WHEN ISNULL(DATEDIFF(second,F_RETURNVISITTIME, GETDATE()),0)< 1 OR F_HOUSING!= '投诉' THEN 0 ELSE DATEDIFF(second, F_RETURNVISITTIME, GETDATE()) END,");

            strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
            strSql.Append("F_WORKORDERSTATEID=4,");//定责
            strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID  and F_WORKORDERSTATEID=3");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_REMAINDERENDTIME",model.F_REMAINDERENDTIME),
                    new SqlParameter("@F_RETURNVISITRESULT", model.F_RETURNVISITRESULT),
                    new SqlParameter("@F_ROAD", ""),//原为满意度，前端没有用，后用作定责人员
                    new SqlParameter("@F_RETURNVISITOPINION", model.F_RETURNVISITOPINION),
                    new SqlParameter("@F_REPAIRREQUEST","待定责"),
                    new SqlParameter("@F_ENDTIME",model.F_ENDTIME),
                    new SqlParameter("@F_WORKORDERID", model.F_WORKORDERID)};
            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }
        /// <summary>
        /// 回访转已处理
        /// </summary>
        /// <param name="F_WORKORDERID"></param>
        /// <param name="type">type 0转单 1定责</param>
        public bool UpdateOrderToOver(Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
            strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
            strSql.Append("F_ROAD=@F_ROAD,");
            strSql.Append("F_ENDTIME=@F_ENDTIME,");
            strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
            strSql.Append("F_WORKORDERSTATEID=5,");//定责
            strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID  and F_WORKORDERSTATEID=3");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_REMAINDERENDTIME",model.F_REMAINDERENDTIME),
                    new SqlParameter("@F_RETURNVISITRESULT", model.F_RETURNVISITRESULT),
                    new SqlParameter("@F_ROAD", ""),//原为满意度，前端没有用，后用作定责人员
                    new SqlParameter("@F_RETURNVISITOPINION", model.F_RETURNVISITOPINION),
                    new SqlParameter("@F_REPAIRREQUEST","已处理"),
                    new SqlParameter("@F_ENDTIME",model.F_ENDTIME),
                    new SqlParameter("@F_WORKORDERID", model.F_WORKORDERID)};
            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }


        //修改并插入转办历史信息
        public int EditMyOrderHistoryInfo(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            //历史工单id
            int historyId = 0;

            //如果工单状态不等于2
            if (model.F_WORKORDERSTATEID == 1)
            {
                //更新新本次转办信息
                Model.T_Wo_WorkOrderHistory eidthistoryModel = new Model.T_Wo_WorkOrderHistory();
                //工单主键
                eidthistoryModel.F_HISTORYID = int.Parse(model.F_FORMID.ToString());//主键
                eidthistoryModel.F_REMARK = model.F_RETURNVISITCONTENT;//处理内容
                eidthistoryModel.F_StateName = "已处理";
                eidthistoryModel.F_WORKORDERSTATEID = 1;
                eidthistoryModel.ReplayTime = DateTime.Now;


                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Wo_WorkOrderHistory set ");
                strSql.Append("F_REMARK=@F_REMARK,");
                strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
                strSql.Append("F_StateName=@F_StateName,");
                strSql.Append("ReplayTime=@ReplayTime");
                strSql.Append(" where F_HISTORYID=@F_HISTORYID");
                SqlParameter[] parameters = {
                    new SqlParameter("@F_REMARK", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_StateName", SqlDbType.NVarChar,200),
                    new SqlParameter("@ReplayTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HISTORYID", SqlDbType.Int,4)};
                parameters[0].Value = eidthistoryModel.F_REMARK;
                parameters[1].Value = eidthistoryModel.F_WORKORDERSTATEID;
                parameters[2].Value = eidthistoryModel.F_StateName;
                parameters[3].Value = eidthistoryModel.ReplayTime;
                parameters[4].Value = eidthistoryModel.F_HISTORYID;
                if (DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0)
                {
                    //插入转办信息
                    Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
                    historyModel.F_INSTANCEID = model.F_WORKORDERID;
                    historyModel.F_OPTBTNID = model.F_DEPTID;//部门
                    historyModel.F_NEXTOWNERARRID = model.F_DEPTCODE;//部门
                    historyModel.F_OPTUSERID = model.F_CREATEBY;//人员
                    historyModel.F_UserName = model.F_USERNAME;//人员
                    historyModel.F_OPTDATE = DateTime.Now;
                    historyModel.F_WORKORDERSTATEID = 0;
                    historyModel.F_StateName = "未处理";
                    historyModel.NeedReplayTime = model.F_REQUESTSERVICETIME;
                    historyId = InsertWorkOrderHistoryModel(historyModel);
                }

            }



            return historyId;

        }

        #endregion


        # region 全媒体客服处理回访
        /// <summary>
        /// 全媒体客服处理回访
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SubmitOrderHF(Model.T_Wo_WorkOrderBase model)
        {
            bool EditStatus = false;
            DAL.T_Wo_WorkOrderHistory bllOrderHistory = new DAL.T_Wo_WorkOrderHistory();
            Model.T_Wo_WorkOrderBase modelbase = GetModel(model.F_WORKORDERID);
            //如果工单状态处理中
            if (modelbase.F_WORKORDERSTATEID == 3)
            {
                if (modelbase.F_RETURNVISITFLAG == 0)
                {
                    //model.F_RETURNVISITOPINION = ""; 不需要回访，假如你回访了，也记录
                }
                if (modelbase.F_ENDTIME != null)
                    model.F_ENDTIME = modelbase.F_ENDTIME;
                else
                    model.F_ENDTIME = DateTime.Now;
                //需要继续转单处理
                if (model.F_WORKORDERSTATEID == 1)
                {
                    foreach (Model.T_Wo_WorkOrderHistory historyModel in model.HistoryOrderList)
                    {
                        historyModel.F_INSTANCEID = model.F_WORKORDERID;
                        historyModel.F_OPTDATE = DateTime.Now;
                        historyModel.F_WORKORDERSTATEID = 0;
                        historyModel.F_StateName = "未处理";
                        historyModel.NeedReplayTime = model.F_REQUESTSERVICETIME;
                        InsertWorkOrderHistoryModel(historyModel);
                    }
                    LogAciton.AddAction(model.F_USERNAME, model.F_USERID.ToInt32(), "回访模块转转单模块", "模块调用", "DAL/T_Wo_WorkOrderBase/SubmitOrderHF", "DAL/T_Wo_WorkOrderBase/UpdateOrderToZD");
                    EditStatus = UpdateOrderToZD(model);
                }
                else if (model.F_WORKORDERSTATEID == 4 && modelbase.F_HOUSING != "投诉")//回访完成 转已处理
                {
                    LogAciton.AddAction(model.F_USERNAME, model.F_USERID.ToInt32(), "回访模块转已处理模块", "模块调用", "DAL/T_Wo_WorkOrderBase/SubmitOrderHF", "DAL/T_Wo_WorkOrderBase/UpdateOrderToOver");
                    EditStatus = UpdateOrderToOver(model);
                }
                else if (model.F_WORKORDERSTATEID == 4 && modelbase.F_HOUSING == "投诉")//回访完成 转定责
                {
                    LogAciton.AddAction(model.F_USERNAME, model.F_USERID.ToInt32(), "回访模块转待定责模块", "模块调用", "DAL/T_Wo_WorkOrderBase/SubmitOrderHF", "DAL/T_Wo_WorkOrderBase/UpdateOrderToDZ");
                    EditStatus = UpdateOrderToDZ(model);
                }
            }
            return EditStatus;
        }
        #endregion

        #region 办结转办信息

        public bool CloseMyOrderInfo(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            bool EditStatus = false;

            //修改历史记录成功
            if (CloseMyOrderHistoryInfo(model))
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update T_Wo_WorkOrderBase set ");
                strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
                strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
                //strSql.Append("F_ROAD=@F_ROAD,");
                strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
                strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
                strSql.Append("F_REPAIRREQUEST=@F_REPAIRREQUEST");
                strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
                SqlParameter[] parameters = {
                    new SqlParameter("@F_REMAINDERENDTIME",SqlDbType.DateTime),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_ROAD", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_REPAIRREQUEST", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
                parameters[0].Value = model.F_REMAINDERENDTIME;
                parameters[1].Value = model.F_RETURNVISITRESULT;
                parameters[2].Value = model.F_ROAD;
                parameters[3].Value = model.F_RETURNVISITOPINION;
                parameters[4].Value = model.F_WORKORDERSTATEID;
                parameters[5].Value = model.F_REPAIRREQUEST;
                parameters[6].Value = model.F_WORKORDERID;
                EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
            }
            return EditStatus;

        }



        //修改并插入转办历史信息
        public bool CloseMyOrderHistoryInfo(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {

            //更新新本次转办信息
            Model.T_Wo_WorkOrderHistory eidthistoryModel = new Model.T_Wo_WorkOrderHistory();
            //工单主键
            eidthistoryModel.F_HISTORYID = int.Parse(model.F_FORMID.ToString());//主键
            eidthistoryModel.F_REMARK = model.F_RETURNVISITCONTENT;//处理内容
            eidthistoryModel.F_StateName = "已处理";
            eidthistoryModel.F_WORKORDERSTATEID = 1;
            eidthistoryModel.ReplayTime = DateTime.Now;


            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderHistory set ");
            strSql.Append("F_REMARK=@F_REMARK,");
            strSql.Append("F_WORKORDERSTATEID=@F_WORKORDERSTATEID,");
            strSql.Append("F_StateName=@F_StateName,");
            strSql.Append("ReplayTime=@ReplayTime");
            strSql.Append(" where F_HISTORYID=@F_HISTORYID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_REMARK", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_WORKORDERSTATEID", SqlDbType.Int,4),
                    new SqlParameter("@F_StateName", SqlDbType.NVarChar,200),
                    new SqlParameter("@ReplayTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HISTORYID", SqlDbType.Int,4)};
            parameters[0].Value = eidthistoryModel.F_REMARK;
            parameters[1].Value = eidthistoryModel.F_WORKORDERSTATEID;
            parameters[2].Value = eidthistoryModel.F_StateName;
            parameters[3].Value = eidthistoryModel.ReplayTime;
            parameters[4].Value = eidthistoryModel.F_HISTORYID;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;

        }

        #endregion

        #region  编辑历史工单信息
        /// <summary>
        /// 编辑工单信息
        /// </summary>
        /// <param name="model">工单实体</param>
        /// <returns></returns>
        public bool UpdateHistoryWorkOrderInfoModel(ZXDT.CallCenter.Model.T_Wo_WorkOrderBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrderBase set ");
            strSql.Append("F_CUSTOMERID=@F_CUSTOMERID,");
            strSql.Append("F_CUSTOMERNAME=@F_CUSTOMERNAME,");
            strSql.Append("F_CUSTOMERTELEPHONE=@F_CUSTOMERTELEPHONE,");
            strSql.Append("F_RETURNVISITPROBLEM=@F_RETURNVISITPROBLEM,");
            strSql.Append("F_REPAIRLEVEL=@F_REPAIRLEVEL,");
            strSql.Append("F_ADSLACCOUNT=@F_ADSLACCOUNT,");
            strSql.Append("F_WORKORDERLEVELID=@F_WORKORDERLEVELID,");
            strSql.Append("F_WORKORDERNAME=@F_WORKORDERNAME,");
            strSql.Append("F_CONTENT=@F_CONTENT,");
            strSql.Append("F_RETURNVISITFLAG=@F_RETURNVISITFLAG,");
            strSql.Append("F_RETURNVISITTIME =@F_RETURNVISITTIME,");
            strSql.Append("F_REMAINDERENDTIME=@F_REMAINDERENDTIME,");
            strSql.Append("F_RETURNVISITRESULT=@F_RETURNVISITRESULT,");
            //strSql.Append("F_ROAD=@F_ROAD,");
            strSql.Append("F_RETURNVISITOPINION=@F_RETURNVISITOPINION,");
            strSql.Append("F_FILEFLAG =@F_FILEFLAG,");
            strSql.Append("F_HOUSING =@F_HOUSING,");//F_RETURNVISITCONTENT 处理回复
            strSql.Append("F_RETURNVISITCONTENT =@F_RETURNVISITCONTENT");
            strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CUSTOMERID", SqlDbType.Int,4),
                    new SqlParameter("@F_CUSTOMERNAME", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CUSTOMERTELEPHONE", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_RETURNVISITPROBLEM", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_REPAIRLEVEL",SqlDbType.Int,4),
                    new SqlParameter("@F_ADSLACCOUNT", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_WORKORDERLEVELID", SqlDbType.Int,4),
                    new SqlParameter("@F_WORKORDERNAME", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CONTENT", SqlDbType.NVarChar,4000),
                    new SqlParameter("@F_RETURNVISITFLAG", SqlDbType.Int,4),
                    new SqlParameter("@F_RETURNVISITTIME ", SqlDbType.DateTime),
                         new SqlParameter("@F_REMAINDERENDTIME",SqlDbType.DateTime),
                    new SqlParameter("@F_RETURNVISITRESULT", SqlDbType.Int,4),
                    new SqlParameter("@F_ROAD", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_RETURNVISITOPINION", SqlDbType.NVarChar,4000),
                         new SqlParameter("@F_FILEFLAG", SqlDbType.Int,4),
                           new SqlParameter("@F_HOUSING ", SqlDbType.NVarChar,200),
                             new SqlParameter("@F_RETURNVISITCONTENT ", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
            parameters[0].Value = model.F_CUSTOMERID;
            parameters[1].Value = model.F_CUSTOMERNAME;
            parameters[2].Value = model.F_CUSTOMERTELEPHONE;
            parameters[3].Value = model.F_RETURNVISITPROBLEM;
            parameters[4].Value = model.F_REPAIRLEVEL;
            parameters[5].Value = model.F_ADSLACCOUNT;
            parameters[6].Value = model.F_WORKORDERLEVELID;
            parameters[7].Value = model.F_WORKORDERNAME;
            parameters[8].Value = model.F_CONTENT;
            parameters[9].Value = model.F_RETURNVISITFLAG;
            parameters[10].Value = model.F_RETURNVISITTIME;
            parameters[11].Value = model.F_REMAINDERENDTIME;
            parameters[12].Value = model.F_RETURNVISITRESULT;
            parameters[13].Value = model.F_ROAD;
            parameters[14].Value = model.F_RETURNVISITOPINION;
            parameters[15].Value = model.F_FILEFLAG;
            parameters[16].Value = model.F_HOUSING;
            parameters[17].Value = model.F_RETURNVISITCONTENT;
            parameters[18].Value = model.F_WORKORDERID;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }


        }

        #endregion  ExtensionMethod


        #region 工单撤回
        public bool ResetWorkOrderOldJiekou(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" update T_Wo_WorkOrderBase set ");
                strSql.Append(" F_WORKORDERSTATEID=0,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);

                
                //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                //strSql.Append(" F_StateName = '已撤回' where F_HISTORYID in ( SELECT TOP 1  F_HISTORYID FROM  dbo.T_Wo_WorkOrderHistory where F_INSTANCEID=" + workOrderId + " order by F_OPTDATE desc)");
               
                //先不发布
                strSql.Append(" update T_Wo_WorkOrderHistory set ");
                strSql.Append(" F_StateName = '已撤回'  WHERE  F_workorderstateid=0 AND F_StateName='未处理' and F_INSTANCEID= " + workOrderId);



                result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                int hisid = EditOrderHistoryInfoOldJiekou(workOrderId, byid, byname, bmid, bmmc);

            }
            return result;
        }
        //插入撤消工单历史信息
        public int EditOrderHistoryInfoOldJiekou(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            //历史工单id
            int historyId = 0;
            //插入撤消信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 0;
            historyModel.F_StateName = "已撤回";
            historyModel.F_TASKFLAG = 2; //编辑工单列表：撤回
            historyModel.F_REMARK = byname + "撤回，转补录工单";
            historyId = InsertWorkOrderHistoryModel(historyModel);
            //if (historyId > 0)
            //{
            //    StringBuilder strSql = new StringBuilder();
            //    strSql.Append(" update T_Wo_WorkOrderBase set ");
            //    strSql.Append("   F_Cancel = (select top 1 F_HISTORYID  from T_Wo_WorkOrderHistory where F_WORKORDERSTATEID = 0  and F_INSTANCEID = " + workOrderId + "  and F_OPTUSERID = " + byid + " and (F_REMARK !='已撤消' or  F_REMARK IS NULL) order by F_HISTORYID desc)  where F_WORKORDERID = " + workOrderId + "");

            //    var result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
            //}
            #region
            //if (historyId > 0)
            //{
            //    StringBuilder strSql = new StringBuilder();
            //    strSql.Append("update T_Wo_WorkOrderBase set ");
            //    strSql.Append("F_FORMID=@F_FORMID");
            //    strSql.Append(" where F_WORKORDERID=@F_WORKORDERID");
            //    SqlParameter[] parameters = {
            //        new SqlParameter("@F_FORMID",  SqlDbType.Int,4),
            //        new SqlParameter("@F_WORKORDERID", SqlDbType.Int,4)};
            //    parameters[0].Value = historyId;
            //    parameters[1].Value = workOrderId;
            //    bool EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;

            //}
            #endregion
            return historyId;

        }

        #endregion





        /// 工单状态F_WORKORDERSTATEID  0处理中 1已处理，12 从编辑工单撤回到补录工单  13 从待处理中驳回到补录工单  14 从待回访中驳回到处理中  15 从已处理中撤回到处理中 16 从待定责驳回到待回访 17 从已回访中撤回到待回访


        //转办多人 时 单人驳回 则把所有的操作记录都改成驳回
        #region 待处理的工单驳回到补录工单
        public bool OverruleWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc, string opinion)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" update T_Wo_WorkOrderBase set ");
                strSql.Append(" F_WORKORDERSTATEID=0,F_WORKORDERTYPEID=1,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);

                //转办多人 时 单人驳回 则把所有的操作记录都改成驳回
                //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                //strSql.Append(" F_StateName = '已驳回'  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_INSTANCEID= " + workOrderId + " ORDER BY f_optdate DESC)  ");
                //先不发布
                strSql.Append(" update T_Wo_WorkOrderHistory set ");
                strSql.Append(" F_StateName = '已驳回'  WHERE  F_workorderstateid=0 AND F_StateName='未处理' and F_INSTANCEID= " + workOrderId   );



                result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                int hisid = EditOverruleOrderHistoryInfo(workOrderId, byid, byname, bmid, bmmc,opinion);

            }
            return result;
        }
        //待处理的工单 插入驳回工单历史信息
        public int EditOverruleOrderHistoryInfo(int workOrderId, int byid, string byname, int bmid, string bmmc, string opinion)
        {
            //历史工单id
            int historyId = 0;
            //插入驳回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 0;// 13;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 3;//待处理的工单驳回
            historyModel.F_REMARK = byname + "驳回，转补录工单;" +"驳回意见："+opinion;
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }


        #endregion




        #region 待回访的工单驳回 至处理中
        public bool OverruleDHFWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc,string opinion)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" update T_Wo_WorkOrderBase set ");
                strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId + ";");
                //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                //strSql.Append(" F_StateName = '待回访驳回，至处理中'  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_WORKORDERSTATEID=1 and F_INSTANCEID= " + workOrderId + " ORDER BY f_optdate DESC)  ");
                strSql.Append(" update T_Wo_WorkOrderHistory set ");
                strSql.Append(" F_StateName = '未处理',F_WORKORDERSTATEID=0,ReplayTime=null  WHERE F_INSTANCEID= " + workOrderId + " AND F_StateName='已处理' and F_WORKORDERSTATEID=1 and NeedReplayTime is not null and  ReplayTime is not null ; ");
                result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                int hisid = EditOverruleDHFOrderHistoryInfo(workOrderId, byid, byname, bmid, bmmc, opinion);

            }
            return result;
        }
        //待处理的工单 插入驳回工单历史信息
        public int EditOverruleDHFOrderHistoryInfo(int workOrderId, int byid, string byname, int bmid, string bmmc,string opinion)
        {
            //历史工单id
            int historyId = 0;
            //插入驳回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 1;//0 ;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 5;//从待回访的列表里驳回
            historyModel.F_REMARK = byname + "从待回访驳回，至待处理;"+"驳回意见："+opinion;
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }


        #endregion
        //驳回待定责工单到待回访
        public bool OverruleDDZWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc,string opinion)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                Model.T_Wo_WorkOrderBase model = GetModel(workOrderId);

                //转单的待定责驳回
                if (model.F_WORKORDERTYPEID == 1)
                {
                    if (model.F_RETURNVISITFLAG == 1) //等于1 是回访
                    {

                        StringBuilder strSql = new StringBuilder();
                        strSql.Append(" update T_Wo_WorkOrderBase set ");
                        strSql.Append(" F_WORKORDERSTATEID=3,F_REPAIRREQUEST='待回访',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);

                        result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                        int hisid = EditBoHuiDDZWorkOrder(workOrderId, byid, byname, bmid, bmmc, opinion);
                    }

                    else //待定责工单如果不回访，驳回到处理人 的处理列表
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append(" update T_Wo_WorkOrderBase set ");
                        strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId + ";");

                        strSql.Append(" update T_Wo_WorkOrderHistory set ");
                        strSql.Append(" F_StateName = '未处理',F_WORKORDERSTATEID=0,ReplayTime=null  WHERE F_INSTANCEID= " + workOrderId + " AND F_StateName='已处理' and F_WORKORDERSTATEID=1 and NeedReplayTime is not null and  ReplayTime is not null ; ");

                        result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                        int hisid = EditCheHuiDDZWorkOrder2(workOrderId, byid, byname, bmid, bmmc, opinion);
                    }
                }
                //客服处理的待定责驳回
                if (model.F_WORKORDERTYPEID == 3)
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=0,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);

                    result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                    int hisid = EditBoHuiDDZWorkOrderKF(workOrderId, byid, byname, bmid, bmmc, opinion);

                }
            }
            return result;
        }
        //待定责工单到插入驳回工单历史信息
        public int EditOverruleDDZOrderHistoryInfo(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            //历史工单id
            int historyId = 0;
            //插入驳回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 3;// 16;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 7; //从待定责工单 驳回到待回访
            historyModel.F_REMARK = byname + "驳回，转待回访";
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }

        //撤回已处理且待回访的工单
        public bool CheHuiYCLWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc,string reason)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                Model.T_Wo_WorkOrderBase model = GetModel(workOrderId);

                if (model.F_WORKORDERTYPEID == 3)
                {

                }
                else
                {

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId + ";");
                    strSql.Append(" update T_Wo_WorkOrderHistory set ");
                    strSql.Append(" F_StateName = '未处理',F_WORKORDERSTATEID=0,ReplayTime=null  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_INSTANCEID= " + workOrderId + " AND F_UserName='" + byname + "' and F_WORKORDERSTATEID=1 and NeedReplayTime is not null and  ReplayTime is not null ORDER BY f_optdate DESC) ; ");
                    //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                    //strSql.Append(" F_REMARK = '已驳回'  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_INSTANCEID= " + workOrderId + " ORDER BY f_optdate DESC)  ");
                    result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                    // int hisid = EditCheHuiYCLWorkOrder(workOrderId, byid, byname, bmid, bmmc);

                    //历史工单id
                    int historyId = 0;
                    //插入撤回信息
                    Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
                    historyModel.F_INSTANCEID = workOrderId;
                    historyModel.F_OPTUSERID = byid;
                    historyModel.F_UserName = byname;
                    historyModel.F_OPTBTNID = bmid;
                    historyModel.F_NEXTOWNERARRID = bmmc;
                    historyModel.F_OPTDATE = DateTime.Now;
                    historyModel.F_WORKORDERSTATEID = 1;//0
                    historyModel.F_StateName = "已撤回";
                    historyModel.F_TASKFLAG = 7; // 
                    if (string.IsNullOrEmpty(reason))
                    {
                        historyModel.F_REMARK = byname + "撤回，转待处理";
                    }
                    else
                    {
                        historyModel.F_REMARK = byname + "撤回，转待处理; 撤回原因："+reason;
                    }
                    historyId = InsertWorkOrderHistoryModel(historyModel);
                  


                }

            }
            return result;


        }
        public int EditCheHuiYCLWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            //历史工单id
            int historyId = 0;
            //插入撤回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 1;//0
            historyModel.F_StateName = "已撤回";
            historyModel.F_TASKFLAG = 7; // 
            historyModel.F_REMARK = byname + "撤回，转待处理";
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }




        //撤回已回访即待定责的工单
        public bool CheHuiDDZWorkOrderOldJiekou(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                Model.T_Wo_WorkOrderBase model = GetModel(workOrderId);
                if (model.F_RETURNVISITFLAG == 1) //等于1 是回访
                {

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=3,F_REPAIRREQUEST='待回访',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                    //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                    //strSql.Append(" F_REMARK = '已驳回'  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_INSTANCEID= " + workOrderId + " ORDER BY f_optdate DESC)  ");
                    result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                    int hisid = EditCheHuiDDZWorkOrder(workOrderId, byid, byname, bmid, bmmc);
                }
                else //不回访工单 待定责工单转到待处理
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                    //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                    //strSql.Append(" F_REMARK = '已驳回'  WHERE  F_HISTORYID =(  SELECT TOP 1  F_HISTORYID FROM dbo.T_Wo_WorkOrderHistory  WHERE F_INSTANCEID= " + workOrderId + " ORDER BY f_optdate DESC)  ");
                    result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                    int hisid = EditCheHuiYCLWorkOrder(workOrderId, byid, byname, bmid, bmmc);
                }

            }
            return result;


        }
        public int EditCheHuiDDZWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc)
        {
            //历史工单id
            int historyId = 0;
            //插入撤回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 3;//5
            historyModel.F_StateName = "已撤回";
            historyModel.F_TASKFLAG = 7; // 
            historyModel.F_REMARK = byname + "撤回，转待回访";
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }


        public int EditBoHuiDDZWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc,string opinion)
        {
            //历史工单id
            int historyId = 0;
            //插入撤回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 3;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 7; // 
            historyModel.F_REMARK = byname + "驳回，转待回访;驳回意见：" + opinion;
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }

        //不回访的转待处理
        public int EditCheHuiDDZWorkOrder2(int workOrderId, int byid, string byname, int bmid, string bmmc, string opinion)
        {
            //历史工单id
            int historyId = 0;
            //插入撤回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 0;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 7; // 
            historyModel.F_REMARK = byname + "驳回，转待处理;驳回意见：" + opinion;
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }



        public int EditBoHuiDDZWorkOrderKF(int workOrderId, int byid, string byname, int bmid, string bmmc, string opinion)
        {
            //历史工单id
            int historyId = 0;
            //插入撤回信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 6;
            historyModel.F_StateName = "已驳回";
            historyModel.F_TASKFLAG = 7; // 
            historyModel.F_REMARK = byname + "驳回，转补录工单;驳回意见：" + opinion;
            historyId = InsertWorkOrderHistoryModel(historyModel);
            return historyId;

        }




        #region 待处理的工单撤回 需要审批工单撤回;客服处理的工单撤回也是这个
        public bool ResetWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc, string reason)
        {
            bool result = false;

          Model.T_Wo_WorkOrderBase model=  GetModel(workOrderId);

            if (workOrderId > 0)
            {

                if (model.F_WORKORDERTYPEID == 3) //客服处理                   
                {
                    if (model.F_HOUSING == "投诉" && model.F_FILEFLAG == 3)
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append(" update T_Wo_WorkOrderBase set ");
                        strSql.Append(" F_WORKORDERSTATEID=9,F_REPAIRREQUEST='待定责撤回审批中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                        result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                        #region 工单历史记录
                        Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
                        historyModel.F_INSTANCEID = workOrderId;
                        historyModel.F_OPTUSERID = byid;
                        historyModel.F_UserName = byname;
                        historyModel.F_OPTBTNID = bmid;
                        historyModel.F_NEXTOWNERARRID = bmmc;
                        historyModel.F_OPTDATE = DateTime.Now;
                        historyModel.F_WORKORDERSTATEID = 8;
                        historyModel.F_StateName = "提交撤回";
                        historyModel.F_TASKFLAG = 0;
                        if (string.IsNullOrEmpty(reason))
                        {
                            historyModel.F_REMARK = byname + "撤回待定责的工单;";
                        }
                        else
                        {
                            historyModel.F_REMARK = byname + "撤回待定责的工单; 撤回原因：" + reason;
                        }
                         InsertWorkOrderHistoryModel(historyModel);
                        #endregion

                    }

                    else //客服处理非投诉 撤回到补录工单
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append(" update T_Wo_WorkOrderBase set ");
                        strSql.Append(" F_WORKORDERSTATEID=10,F_REPAIRREQUEST='已处理撤回审批中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                        result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
                        #region 工单历史记录
                        Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
                        historyModel.F_INSTANCEID = workOrderId;
                        historyModel.F_OPTUSERID = byid;
                        historyModel.F_UserName = byname;
                        historyModel.F_OPTBTNID = bmid;
                        historyModel.F_NEXTOWNERARRID = bmmc;
                        historyModel.F_OPTDATE = DateTime.Now;
                        historyModel.F_WORKORDERSTATEID = 8;
                        historyModel.F_StateName = "提交撤回";
                        historyModel.F_TASKFLAG = 0;
                        if (string.IsNullOrEmpty(reason))
                        {
                            historyModel.F_REMARK = byname + "撤回已处理的工单;";
                        }
                        else
                        {
                            historyModel.F_REMARK = byname + "撤回已处理的工单; 撤回原因：" + reason;
                        }
                        InsertWorkOrderHistoryModel(historyModel);
                        #endregion

                    }

                }
                else
                { 

                StringBuilder strSql = new StringBuilder();
                strSql.Append(" update T_Wo_WorkOrderBase set ");
                strSql.Append(" F_WORKORDERSTATEID=8,F_REPAIRREQUEST='待处理撤回审批中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                //strSql.Append(" F_StateName = '已撤回' where F_HISTORYID in ( SELECT TOP 1  F_HISTORYID FROM  dbo.T_Wo_WorkOrderHistory where F_INSTANCEID=" + workOrderId + " order by F_OPTDATE desc)");

                //先不发布
                //strSql.Append(" update T_Wo_WorkOrderHistory set ");
                //strSql.Append(" F_StateName = '已撤回'  WHERE  F_workorderstateid=0 AND F_StateName='未处理' and F_INSTANCEID= " + workOrderId);



                result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                int hisid = EditOrderHistoryInfo(workOrderId, byid, byname, bmid, bmmc, reason);
                }

            }
            return result;
        }

        //插入撤工单历史信息
        public int EditOrderHistoryInfo(int workOrderId, int byid, string byname, int bmid, string bmmc, string reason)
        {
            //历史工单id
            int historyId = 0;
            //插入操作信息
            Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
            historyModel.F_INSTANCEID = workOrderId;
            historyModel.F_OPTUSERID = byid;
            historyModel.F_UserName = byname;
            historyModel.F_OPTBTNID = bmid;
            historyModel.F_NEXTOWNERARRID = bmmc;
            historyModel.F_OPTDATE = DateTime.Now;
            historyModel.F_WORKORDERSTATEID = 8;
            historyModel.F_StateName = "提交撤回";
            historyModel.F_TASKFLAG = 0;
            if (string.IsNullOrEmpty(reason))
            {
                historyModel.F_REMARK = byname + "撤回处理中的工单;";
            }
            else
            {
                historyModel.F_REMARK = byname + "撤回处理中的工单; 撤回原因：" + reason;
            }
            historyId = InsertWorkOrderHistoryModel(historyModel);


            return historyId;

        }




        #endregion


        #region 撤回已回访即待定责的工单
        public bool CheHuiDDZWorkOrder(int workOrderId, int byid, string byname, int bmid, string bmmc,string reason)
        {
            bool result = false;

            if (workOrderId > 0)
            {
                Model.T_Wo_WorkOrderBase model = GetModel(workOrderId);
              

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=9,F_REPAIRREQUEST='待定责撤回审批中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workOrderId);
                  
                    result = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;                

                   
                    #region 工单历史记录
                    Model.T_Wo_WorkOrderHistory historyModel = new Model.T_Wo_WorkOrderHistory();
                    historyModel.F_INSTANCEID = workOrderId;
                    historyModel.F_OPTUSERID = byid;
                    historyModel.F_UserName = byname;
                    historyModel.F_OPTBTNID = bmid;
                    historyModel.F_NEXTOWNERARRID = bmmc;
                    historyModel.F_OPTDATE = DateTime.Now;
                    historyModel.F_WORKORDERSTATEID = 8;
                    historyModel.F_StateName = "";
                    historyModel.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(reason))
                    {
                        historyModel.F_REMARK = byname + "撤回待定责的工单;";
                    }
                    else
                    {
                        historyModel.F_REMARK = byname + "撤回待定责的工单; 撤回原因：" + reason;
                    }
                    InsertWorkOrderHistoryModel(historyModel);
                    #endregion
               
                

            }
            return result;


        }

        #endregion


        /// <summary>
        /// 审批列表审批
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SubmitShenPiYj(int  workorderid, int shenpiresult,string shenpiopinion,int byid,string byname,int bmid)
        {
            bool EditStatus = false;
           
            DAL.T_Wo_WorkOrderHistory bllOrderHistory = new DAL.T_Wo_WorkOrderHistory();
            //有三种工单状态需要审批

            //1.待处理的时候撤回； 即  8待处理撤回审批中(转办)    
            //2.客服处理的 已完结的工单 能撤回； 即  10 已完结撤回审批中（客服处理）
            //3.待定责的时候可以撤回。（客服处理和转办）  9 待定责撤回审批中（客服处理和转办）
             
           
            Model.T_Wo_WorkOrderBase basemodel = GetModel(workorderid);

            if (basemodel.F_WORKORDERSTATEID == 8) // 8待处理撤回审批中(转办)  
            {
                if (shenpiresult == 0) 
                { 
                    //不同意撤回，改工单状态为处理中，加一条history历史记录 
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workorderid);

                    EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                    Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                    historyModelNew.F_INSTANCEID = workorderid;
                    historyModelNew.F_OPTUSERID = byid;
                    historyModelNew.F_UserName = byname;
                    historyModelNew.F_OPTBTNID = bmid;
                    historyModelNew.F_NEXTOWNERARRID = "";
                    historyModelNew.F_OPTDATE = DateTime.Now;
                    historyModelNew.F_WORKORDERSTATEID = 1;
                    historyModelNew.F_StateName = "审批不通过";
                    historyModelNew.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(shenpiopinion))
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过";
                    }
                    else
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过; 原因：" + shenpiopinion;
                    }
                      InsertWorkOrderHistoryModel(historyModelNew);
                }
                if (shenpiresult == 1)
                {
                    //同意撤回，改工单状态为待处理，加一条history历史记录 ，修改以前的转办记录 状态为已撤回
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=0,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workorderid);
                  
                    // 转办记录改成已撤回
                    strSql.Append(" update T_Wo_WorkOrderHistory set ");
                    strSql.Append(" F_StateName = '已撤回'  WHERE  F_workorderstateid=0 AND F_StateName='未处理' and F_INSTANCEID= " + workorderid);

                    EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                    Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                    historyModelNew.F_INSTANCEID = workorderid;
                    historyModelNew.F_OPTUSERID = byid;
                    historyModelNew.F_UserName = byname;
                    historyModelNew.F_OPTBTNID = bmid;
                    historyModelNew.F_NEXTOWNERARRID = "";
                    historyModelNew.F_OPTDATE = DateTime.Now;
                    historyModelNew.F_WORKORDERSTATEID = 1;
                    historyModelNew.F_StateName = "审批通过";
                    historyModelNew.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(shenpiopinion))
                    {
                        historyModelNew.F_REMARK = byname + "审批通过";
                    }
                    else
                    {
                        historyModelNew.F_REMARK = byname + "审批通过; 原因：" + shenpiopinion;
                    }
                    InsertWorkOrderHistoryModel(historyModelNew);
                }


            }
            else if (basemodel.F_WORKORDERSTATEID == 9) // 9 待定责撤回审批中（客服处理和转办）
            {
                if (shenpiresult == 0)
                {
                    //不同意撤回，改工单状态为待定责，加一条history历史记录 
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=4,F_REPAIRREQUEST='待定责',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workorderid);

                    EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                    Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                    historyModelNew.F_INSTANCEID = workorderid;
                    historyModelNew.F_OPTUSERID = byid;
                    historyModelNew.F_UserName = byname;
                    historyModelNew.F_OPTBTNID = bmid;
                    historyModelNew.F_NEXTOWNERARRID = "";
                    historyModelNew.F_OPTDATE = DateTime.Now;
                    historyModelNew.F_WORKORDERSTATEID = 1;
                    historyModelNew.F_StateName = "审批不通过";
                    historyModelNew.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(shenpiopinion))
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过";
                    }
                    else
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过; 原因：" + shenpiopinion;
                    }
                    InsertWorkOrderHistoryModel(historyModelNew);
                }
                if (shenpiresult == 1)
                {
                    //同意撤回，改工单状态 加一条history历史记录 ，修改以前的转办记录 状态为已撤回
                    if (basemodel.F_WORKORDERTYPEID == 3)//客服处理的工单 是投诉类型的 ，从待定责撤回就是 转到补录工单
                    {
                        StringBuilder strSql1 = new StringBuilder();
                        strSql1.Append(" update T_Wo_WorkOrderBase set ");
                        strSql1.Append(" F_WORKORDERSTATEID=0,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0 ,F_RETURNVISITCONTENT='' where F_WORKORDERID=" + workorderid);

                        EditStatus = DbHelperSQL.ExecuteSql(strSql1.ToString()) > 0;

                        Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                        historyModelNew.F_INSTANCEID = workorderid;
                        historyModelNew.F_OPTUSERID = byid;
                        historyModelNew.F_UserName = byname;
                        historyModelNew.F_OPTBTNID = bmid;
                        historyModelNew.F_NEXTOWNERARRID = "";
                        historyModelNew.F_OPTDATE = DateTime.Now;
                        historyModelNew.F_WORKORDERSTATEID = 1;
                        historyModelNew.F_StateName = "审批通过";
                        historyModelNew.F_TASKFLAG = 0;
                        if (string.IsNullOrEmpty(shenpiopinion))
                        {
                            historyModelNew.F_REMARK = byname + "审批通过";
                        }
                        else
                        {
                            historyModelNew.F_REMARK = byname + "审批通过; 原因：" + shenpiopinion;
                        }
                        InsertWorkOrderHistoryModel(historyModelNew);


                    }

                    else
                    {  //转办的工单，待定责撤回的前状态是待回访或者处理中

                        if (basemodel.F_RETURNVISITFLAG == 0) //不回访                        
                        {
                            StringBuilder strSql = new StringBuilder();
                            strSql.Append(" update T_Wo_WorkOrderBase set ");
                            strSql.Append(" F_WORKORDERSTATEID=1,F_REPAIRREQUEST='处理中',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workorderid);
                            EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                        }
                        else
                        {
                            StringBuilder strSql = new StringBuilder();
                            strSql.Append(" update T_Wo_WorkOrderBase set ");
                            strSql.Append(" F_WORKORDERSTATEID=3,F_REPAIRREQUEST='待回访',F_HASTENCOUNTS=0 where F_WORKORDERID=" + workorderid);

                            EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                            Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                            historyModelNew.F_INSTANCEID = workorderid;
                            historyModelNew.F_OPTUSERID = byid;
                            historyModelNew.F_UserName = byname;
                            historyModelNew.F_OPTBTNID = bmid;
                            historyModelNew.F_NEXTOWNERARRID = "";
                            historyModelNew.F_OPTDATE = DateTime.Now;
                            historyModelNew.F_WORKORDERSTATEID = 1;
                            historyModelNew.F_StateName = "审批通过";
                            historyModelNew.F_TASKFLAG = 0;
                            if (string.IsNullOrEmpty(shenpiopinion))
                            {
                                historyModelNew.F_REMARK = byname + "审批通过";
                            }
                            else
                            {
                                historyModelNew.F_REMARK = byname + "审批通过; 原因：" + shenpiopinion;
                            }
                            InsertWorkOrderHistoryModel(historyModelNew);
                        }
                        return EditStatus;
                    }
                }




            }
            else if (basemodel.F_WORKORDERSTATEID == 10) // 客服处理的 已完结的工单 能撤回； 10 已处理撤回审批中（客服处理）
            {
                if (shenpiresult == 0)
                {
                    //不同意撤回，改工单状态为已完结，加一条history历史记录 
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=5,F_REPAIRREQUEST='已处理'  where F_WORKORDERID=" + workorderid);

                    EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                    Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                    historyModelNew.F_INSTANCEID = workorderid;
                    historyModelNew.F_OPTUSERID = byid;
                    historyModelNew.F_UserName = byname;
                    historyModelNew.F_OPTBTNID = bmid;
                    historyModelNew.F_NEXTOWNERARRID = "";
                    historyModelNew.F_OPTDATE = DateTime.Now;
                    historyModelNew.F_WORKORDERSTATEID = 5;
                    historyModelNew.F_StateName = "审批不通过";
                    historyModelNew.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(shenpiopinion))
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过";
                    }
                    else
                    {
                        historyModelNew.F_REMARK = byname + "审批不通过; 原因：" + shenpiopinion;
                    }
                    InsertWorkOrderHistoryModel(historyModelNew);
                }
                if (shenpiresult == 1)
                {
                    //同意撤回，转到补录工单；改工单状态为待处理，F_RETURNVISITCONTENT =‘’ 加一条history历史记录 ， 
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update T_Wo_WorkOrderBase set ");
                    strSql.Append(" F_WORKORDERSTATEID=0,F_REPAIRREQUEST='待处理',F_HASTENCOUNTS=0,F_RETURNVISITCONTENT=''  where F_WORKORDERID=" + workorderid);

                    if (basemodel.F_HOUSING == "表扬")
                    {
                        //把表扬记录删掉
                        DataTable dt = NoticeBll.GetList("NoticeType=0 and OrderId='" + basemodel.F_WORKORDERID + "'").Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                int deleteid = Convert.ToInt32(dr["NoticeId"].ToString());
                                NoticeBll.Delete(deleteid);
                            }
                        }


                    }


                    EditStatus = DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;

                    Model.T_Wo_WorkOrderHistory historyModelNew = new Model.T_Wo_WorkOrderHistory();
                    historyModelNew.F_INSTANCEID = workorderid;
                    historyModelNew.F_OPTUSERID = byid;
                    historyModelNew.F_UserName = byname;
                    historyModelNew.F_OPTBTNID = bmid;
                    historyModelNew.F_NEXTOWNERARRID = "";
                    historyModelNew.F_OPTDATE = DateTime.Now;
                    historyModelNew.F_WORKORDERSTATEID = 0;
                    historyModelNew.F_StateName = "审批通过";
                    historyModelNew.F_TASKFLAG = 0;
                    if (string.IsNullOrEmpty(shenpiopinion))
                    {
                        historyModelNew.F_REMARK = byname + "审批通过";
                    }
                    else
                    {
                        historyModelNew.F_REMARK = byname + "审批通过; 原因：" + shenpiopinion;
                    }
                    InsertWorkOrderHistoryModel(historyModelNew);
                }

            }
            else
            {
                return EditStatus;
            }

             
            return EditStatus;

        }



        #region 大屏相关的接口
        public DataSet GetFiveList()
        {
            string sql = "SELECT TOP 10 F_CREATEDATE,F_HOUSING, F_ADSLACCOUNT  ,F_content FROM dbo.T_Wo_WorkOrderBase  where F_WORKORDERSTATEID>0 ORDER BY F_CREATEDATE DESC";
            return DbHelperSQL.Query(sql);
        }

        public DataTable GetHistoryDayMax()
        {
            string sql = "select top 1 *   from (select convert(char(10), F_CREATEDATE, 120) as maxday, count(1) as maxcount from[T_Wo_WorkOrderBase]  group by convert(char(10), F_CREATEDATE, 120)) t  order by maxcount desc";

           // string sql = " select max(maxcount) from(select convert(char(10),F_CREATEDATE,112) as maxday,count(1) as maxcount from[T_Wo_WorkOrderBase]  group by convert(char(10), F_CREATEDATE, 112)  ) t";
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
            return dt;

           
        }


        public DataTable GetHistoryDayLongTel()
        {
            string sql = " select top 1  *　from(select convert(char(10),BeginTime,120) as maxday,sum(TalkLongTime) as maxcount from[T_Call_CallRecords]  group by convert(char(10), BeginTime, 120)   )t  order by  maxcount desc";
           // string sql = " select max(maxcount) from(select convert(char(10),BeginTime,112) as maxday,sum(TalkLongTime) as maxcount from[T_Call_CallRecords]  group by convert(char(10), BeginTime, 112)  )t";
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];

            return dt;
        }

        public int GetTodayCount()
        {
            string sql = "SELECT COUNT(*) FROM dbo.T_Wo_WorkOrderBase WHERE F_CREATEDATE >= convert(varchar(10), Getdate(), 120) ";
           DataTable dt= DbHelperSQL.Query(sql).Tables[0];


            return Convert.ToInt32(dt.Rows[0][0]);

        }


        public DataTable GetDataFluctuation()
        {
            DataTable dt = new DataTable();
     
            string sql = "select F_WORKORDERFROM,convert(char(6),F_CREATEDATE,112) yearmonth ,count(1) amount from T_Wo_WorkOrderBase where F_CREATEDATE between DateAdd(m,-11,getdate()) and GETDATE() group by F_WORKORDERFROM,convert(char(6), F_CREATEDATE, 112) order by convert(char(6), F_CREATEDATE, 112)  ";
            dt = DbHelperSQL.Query(sql).Tables[0];
            return dt; 
        }
        public DataTable GetAverageAcceptAmount()
        {
            DataTable dt = new DataTable();
            double weekAverage = 0;
            double monthAverage = 0;
            double yearAverage = 0;
            //最近一周日均 
            string endDate = DateTime.Now.ToString("yyyy-MM-dd");
            string startDate = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
            string sql = "select count(*) amount From T_Wo_WorkOrderBase t Where ";
            sql += " t.F_CREATEDATE>= '" + startDate + " 00:00:00" + "'";
            sql += " and t.F_CREATEDATE<= '" + endDate + " 23:59:59" + "'";
        DataTable countweek= DbHelperSQL.Query(sql).Tables[0];
            if (countweek.Rows.Count>0)
            {
                int countwe = Convert.ToInt32( countweek.Rows[0]["amount"]);
                if (countwe != 0)
                {
                    weekAverage = countwe / 7;
                }
            }
           
            ///最近一月
            string endDate1 = DateTime.Now.ToString("yyyy-MM-dd");
            string startDate1 = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            TimeSpan ts =Convert.ToDateTime( endDate1 )- Convert.ToDateTime(startDate1);
            int dds = ts.Days;


            string sql2 = "select count(*) amount From T_Wo_WorkOrderBase t Where ";
            sql2 += "   t.F_CREATEDATE>= '" + startDate1 + " 00:00:00" + "'";
            sql2 += " and t.F_CREATEDATE<= '" + endDate1 + " 23:59:59" + "'";
            DataTable countmonth  = DbHelperSQL.Query(sql2).Tables[0];
            if (countmonth.Rows.Count > 0)
            {
                int countmm = Convert.ToInt32(countmonth.Rows[0]["amount"]);
                if (countmm != 0)
                {
                    monthAverage = countmm / dds;
                }
                
            }

            ///最近一年
            ///
            string endDate2 = DateTime.Now.ToString();
            string startDate2 = DateTime.Now.AddYears(-1).ToString();
            TimeSpan ts2 = Convert.ToDateTime(endDate2) - Convert.ToDateTime(startDate2);
            int dds2 = ts2.Days;


            string sql3 = "select count(*) amount From T_Wo_WorkOrderBase t Where ";
            sql3 += "   F_CREATEDATE>= '" + startDate2 + "'";
            sql3 += " and F_CREATEDATE<= '" + endDate2 + "'";

            
            DataTable countyear= DbHelperSQL.Query(sql3).Tables[0];
            if (countyear.Rows.Count>0)
            {
                int countyy = Convert.ToInt32(countyear.Rows[0]["amount"]);
                if (countyy != 0)
                {
                    yearAverage = countyy / dds2;
                }
              
            }
            dt.Columns.Add("type", Type.GetType("System.String"));
            dt.Columns.Add("amount", Type.GetType("System.Int32"));
            DataRow dr = dt.NewRow();
            dr["type"] = "week";
            dr["amount"] = weekAverage;
            dt.Rows.Add(dr);
            DataRow dr2 = dt.NewRow();
            dr2["type"] = "month";
            dr2["amount"] = monthAverage;
            dt.Rows.Add(dr2);

            DataRow dr3 = dt.NewRow();
            dr3["type"] = "year";
            dr3["amount"] = yearAverage;
            dt.Rows.Add(dr3);

            return dt;
        }

        public DataTable GetYearTelAmount()
        {
            string sql = "	SELECT datepart(year, BeginTime) theyear,COUNT(*) amount FROM dbo.T_Call_CallRecords    group by datepart(year, BeginTime) order by theyear";
           // string sql = "SELECT datepart(year, F_CREATEDATE) theyear,COUNT(*) amount FROM dbo.T_Wo_WorkOrderBase WHERE (F_WORKORDERFROM = '语音工单' OR F_WORKORDERFROM = '留言工单') group by datepart(year, F_CREATEDATE)";
            DataSet ds= DbHelperSQL.Query(sql);
            return ds.Tables[0];
        }
        public DataTable GetSixMonthTelAmount()
        {
       //     //改成最近四个季度
       //DateTime begintime=     DateTime.Now.AddMonths(0 - ((DateTime.Now.Month - 1) % 3)).AddDays(1 - DateTime.Now.Day);



       //     //本季度最后一天
       //     string lastDayOfThisQuarter2 = DateTime.Parse(DateTime.Now.AddMonths(3 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");

            DateTime dt = DateTime.Parse( DateTime.Now.ToShortDateString());  //当前时间


            DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day);  //本季度初
            DateTime endQuarter = startQuarter.AddMonths(3);  //本季度末

            DateTime secondQuarter = startQuarter.AddMonths(-3);
            DateTime secondEndQuarter = endQuarter.AddMonths(-3);


            DateTime thirdQuarter = secondQuarter.AddMonths(-3);
            DateTime thirdEndQuarter = secondEndQuarter.AddMonths(-3);


            DateTime fourthQuarter = thirdQuarter.AddMonths(-3);
            DateTime fourthEndQuarter = thirdEndQuarter.AddMonths(-3);

            string sql = " select COUNT(*) from T_Call_CallRecords  where BeginTime between '"+ startQuarter + "' and  '" + endQuarter + "'";
            var   ds1 = DbHelperSQL.GetSingle(sql);

            string sql2 = " select COUNT(*) from T_Call_CallRecords  where BeginTime between '" + secondQuarter + "' and  '" + secondEndQuarter + "'";
            var ds2 = DbHelperSQL.GetSingle(sql2);

            string sql3 = " select COUNT(*) from T_Call_CallRecords  where BeginTime between '" + thirdQuarter + "' and  '" + thirdEndQuarter + "'";
            var ds3 = DbHelperSQL.GetSingle(sql3);


            string sql4 = " select COUNT(*) from T_Call_CallRecords  where BeginTime between '" + fourthQuarter + "' and  '" + fourthEndQuarter + "'";
            var ds4 = DbHelperSQL.GetSingle(sql4);

            DataTable datatable = new DataTable();
            datatable.Columns.Add("Name");
            datatable.Columns.Add("Amount");

            DataRow tr = datatable.NewRow();
            tr["Name"] = startQuarter.Year+"年第" + GetQuarterNum(startQuarter)+"季度";
            tr["Amount"] = ds1.ToString();
            datatable.Rows.Add(tr);

            DataRow tr2 = datatable.NewRow();
            tr2["Name"] = secondQuarter.Year + "年第" + GetQuarterNum(secondQuarter) + "季度"; 
            tr2["Amount"] = ds2.ToString();
            datatable.Rows.Add(tr2);

            DataRow tr3 = datatable.NewRow();
            tr3["Name"] = thirdQuarter.Year + "年第" + GetQuarterNum(thirdQuarter) + "季度"; 
            tr3["Amount"] = ds3.ToString();
            datatable.Rows.Add(tr3);

            DataRow tr4 = datatable.NewRow();
            tr4["Name"] = fourthQuarter.Year + "年第" + GetQuarterNum(fourthQuarter) + "季度";
            tr4["Amount"] = ds4.ToString();
            datatable.Rows.Add(tr4);

            return datatable;


        }
        //获取第几个季度
        public static int GetQuarterNum(DateTime dt)
        {
            int year = dt.Year;
            int jd;
            DateTime dt0 = new DateTime(year, 1, 1);
            DateTime dt1 = new DateTime(year, 4, 1);
            DateTime dt2 = new DateTime(year, 7, 1);
            DateTime dt3 = new DateTime(year, 10, 1);
            if (dt.CompareTo(dt1) < 0)
                jd = 1;
            else if (dt.CompareTo(dt2) < 0)
                jd = 2;
            else if (dt.CompareTo(dt3) < 0)
                jd = 3;
            else
                jd = 4;
            return jd;
        }

        public DataTable GetPressKeyValue(string startTime)
        {
            string startDate = startTime.Substring(0, 10) + " 00:00:00"; ;
            string endDate = startTime.Substring(12) +" 23:59:59";

            string sql = "   select typeName,count(1) total from [autoReplyType]  where   createTime between '"+startDate+"' and '"+ endDate + "'  group by typeName order by count(1) desc";
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
            string sql2 = "  select count(1) total from [autoReplyType]    where createTime between '" + startDate + "' and '" + endDate + "'  ";
            int total = Convert.ToInt32(DbHelperSQL.GetSingle(sql2));

            DataTable dt3 = new DataTable();
            dt3.Columns.Add("typeName", Type.GetType("System.String"));
            dt3.Columns.Add("amount", Type.GetType("System.Int32"));
            dt3.Columns.Add("percent", Type.GetType("System.String"));

            if (total > 0)
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        DataRow dr2 = dt3.NewRow();
                        dr2["typeName"] = dr["typeName"].ToString();
                        int currentAmount = Convert.ToInt32(dr["total"]);
                        dr2["amount"] = currentAmount;
                        double dd=  Convert.ToDouble(currentAmount) / Convert.ToDouble(total) ;
                        dr2["percent"] = dd.ToString("0.00%");
                        dt3.Rows.Add(dr2);

                    }
                }
            }

            return dt3;
        }

        

        public DataTable GetEverydayOfMonthTelAmount()
        {
            string sql = " SELECT convert(nvarchar(10),BeginTime,120) daydate,COUNT(*) amount FROM T_Call_CallRecords    WHERE DateDiff(dd,BeginTime,getdate())<=30     GROUP BY convert(nvarchar(10), BeginTime, 120)  ORDER BY daydate"; 
            //string sql = "SELECT convert(nvarchar(10),F_CREATEDATE,120) daydate,COUNT(*) amount FROM T_Wo_WorkOrderBase  WHERE F_CREATEDATE>= dateadd(month, datediff(month, 0, getdate()), 0)  and (F_WORKORDERFROM='语音工单' OR F_WORKORDERFROM='留言工单') GROUP BY convert(nvarchar(10), F_CREATEDATE, 120)  ORDER BY daydate";
            DataSet ds = DbHelperSQL.Query(sql);
            return ds.Tables[0];
        }

        public DataTable GetTodayFromTypeAmount(string startTime)
        {
            string startDate = startTime.Substring(0, 10) + " 00:00:00";
            string endDate = startTime.Substring(12) + " 23:59:59";

            string sql = " SELECT F_WORKORDERFROM workorderfrom,COUNT(1) amount FROM T_Wo_WorkOrderBase WHERE   F_CREATEDATE between  '" + startDate + "' and '" + endDate + "'  GROUP BY F_WORKORDERFROM";
            DataSet ds = DbHelperSQL.Query(sql);
            DataTable dt = ds.Tables[0];
            int telcount = 0;
            int wxcount = 0;
            int wbcount = 0;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["workorderfrom"].ToString() == "留言工单")
                    {
                        telcount += Convert.ToInt32(dr["amount"]);
                    }
                    if (dr["workorderfrom"].ToString() == "语音工单")
                    {
                        telcount += Convert.ToInt32(dr["amount"]);
                    }
                    if (dr["workorderfrom"].ToString() == "微信工单")
                    {
                        wxcount += Convert.ToInt32(dr["amount"]);
                    }
                    //if (dr["workorderfrom"].ToString() == "微博工单")
                    //{
                    //    wbcount += Convert.ToInt32(dr["amount"]);
                    //}
                }
            }
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("workorderfrom", Type.GetType("System.String"));
            dt2.Columns.Add("amount", Type.GetType("System.Int32"));

            DataRow dr2 = dt2.NewRow();
            dr2["workorderfrom"] = "话务工单";
            dr2["amount"] = telcount;
            dt2.Rows.Add(dr2);

            DataRow dr3 = dt2.NewRow();
            dr3["workorderfrom"] = "微信工单";
            dr3["amount"] = 0;
            dt2.Rows.Add(dr3);

            //DataRow dr4 = dt2.NewRow();
            //dr4["workorderfrom"] = "微博工单";
            //dr4["amount"] = wbcount;
            //dt2.Rows.Add(dr4);

            return dt2;
        }

        public DataTable GetTodayTelType(string startTime)
        {
            //string starttime=  DateTime.Now.ToShortDateString();
            //  string sql = "select F_HOUSING ,count(*) FROM dbo.T_Wo_WorkOrderBase  WHERE F_CREATEDATE>= '" + starttime + "'  GROUP BY F_HOUSING";
            string startDate = startTime.Substring(0, 10) +" 00:00:00";
            string endDate = startTime.Substring(12) + " 23:59:59";
            // string sql = "select F_HOUSING ,count(*) total FROM dbo.T_Wo_WorkOrderBase  WHERE  datediff(d, F_CREATEDATE, '" + startTime + "') = 0  GROUP BY F_HOUSING";
            string sql = "select F_HOUSING ,count(*) total FROM dbo.T_Wo_WorkOrderBase  WHERE  F_CREATEDATE between '" + startDate + "' and '" + endDate + "'  GROUP BY F_HOUSING";


            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
            return dt;


        }


        public DataTable GetTodayLineDistribution(string startTime)
        {
            // string datetime = DateTime.Now.ToString("yyyy-MM-dd");
            string sql = "";
            if (string.IsNullOrEmpty(startTime))
            {
                sql = "select F_Linenum, count(1) total  from[dbo].[T_Call_CallRecords] where CONVERT(nvarchar(7),BeginTime,120)= CONVERT(nvarchar(7), getdate(), 120)  group by  F_Linenum having  F_Linenum is not null";
            }
            else
            {
                string startDate = startTime.Substring(0, 10) + " 00:00:00";
                string endDate = startTime.Substring(12) + " 23:59:59";
                sql = "select F_Linenum, count(1) total from[dbo].[T_Call_CallRecords] where  BeginTime between   '"+ startDate + "' and '"+ endDate + "'  group by  F_Linenum having  F_Linenum is not null";
            }
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];
            return dt;             
        }
        
        #endregion
    }

}

