using RMYY_CallCenter_Api.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RMYY_CallCenter_Api.Dal
{

    /// <summary>
    /// 数据访问类:T_Dev_WorkOrder
    /// </summary>
    public partial class T_Dev_WorkOrder
    {
        public T_Dev_WorkOrder()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Dev_WorkOrder");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(RMYY_CallCenter_Api.Model.T_Dev_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Dev_WorkOrder(");
            strSql.Append("F_Type,F_Type1,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DealType,F_TransferDeptId,F_TransferDeptName,F_Remark,F_CreateTime,F_HandleByCode,F_HandleByName,F_HandleTime,F_HandleContents,F_CarryContents,F_State,F_FinishTime,F_CreateCode,F_CreateName,F_IsDel,F_DeleteBy,F_DeleteTime,F_TransGoPerson,F_TransOutPerson,F_ControlManCode,F_ControlManName,F_DevOutState,F_WoFlag,F_DevOutNum,F_DevInNum,F_DevName,F_DevStorageTime,F_WoID,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie)");
            strSql.Append(" values (");
            strSql.Append("@F_Type,@F_Type1,@F_WorkOrderCode,@F_HosId,@F_ProposerDeptId,@F_ProposerCode,@F_ProposerName,@F_ProposerPhon,@F_Source,@F_CallID,@F_DealType,@F_TransferDeptId,@F_TransferDeptName,@F_Remark,@F_CreateTime,@F_HandleByCode,@F_HandleByName,@F_HandleTime,@F_HandleContents,@F_CarryContents,@F_State,@F_FinishTime,@F_CreateCode,@F_CreateName,@F_IsDel,@F_DeleteBy,@F_DeleteTime,@F_TransGoPerson,@F_TransOutPerson,@F_ControlManCode,@F_ControlManName,@F_DevOutState,@F_WoFlag,@F_DevOutNum,@F_DevInNum,@F_DevName,@F_DevStorageTime,@F_WoID,@F_FinishMan,@F_FinishManName,@F_FinishManPhon,@F_FinishManTalkie)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Type", SqlDbType.Int,4),
                    new SqlParameter("@F_Type1", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkOrderCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HosId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ProposerName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ProposerPhon", SqlDbType.VarChar,20),
                    new SqlParameter("@F_Source", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CallID", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DealType", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TransferDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_TransferDeptName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HandleByCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HandleByName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HandleTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HandleContents", SqlDbType.NText),
                    new SqlParameter("@F_CarryContents", SqlDbType.NText),
                    new SqlParameter("@F_State", SqlDbType.Int,4),
                    new SqlParameter("@F_FinishTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_IsDel", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteBy", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_TransGoPerson", SqlDbType.NText),
                    new SqlParameter("@F_TransOutPerson", SqlDbType.NText),
                    new SqlParameter("@F_ControlManCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ControlManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DevOutState", SqlDbType.Int,4),
                    new SqlParameter("@F_WoFlag", SqlDbType.Int,4),
                    new SqlParameter("@F_DevOutNum", SqlDbType.Int,4),
                    new SqlParameter("@F_DevInNum", SqlDbType.Int,4),
                    new SqlParameter("@F_DevName", SqlDbType.NText),
                    new SqlParameter("@F_DevStorageTime", SqlDbType.DateTime),
                    new SqlParameter("@F_WoID", SqlDbType.Int,4),
                    new SqlParameter("@F_FinishMan", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManPhon", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManTalkie", SqlDbType.VarChar,50)};
            parameters[0].Value = model.F_Type;
            parameters[1].Value = model.F_Type1;
            parameters[2].Value = model.F_WorkOrderCode;
            parameters[3].Value = model.F_HosId;
            parameters[4].Value = model.F_ProposerDeptId;
            parameters[5].Value = model.F_ProposerCode;
            parameters[6].Value = model.F_ProposerName;
            parameters[7].Value = model.F_ProposerPhon;
            parameters[8].Value = model.F_Source;
            parameters[9].Value = model.F_CallID;
            parameters[10].Value = model.F_DealType;
            parameters[11].Value = model.F_TransferDeptId;
            parameters[12].Value = model.F_TransferDeptName;
            parameters[13].Value = model.F_Remark;
            parameters[14].Value = model.F_CreateTime;
            parameters[15].Value = model.F_HandleByCode;
            parameters[16].Value = model.F_HandleByName;
            parameters[17].Value = model.F_HandleTime;
            parameters[18].Value = model.F_HandleContents;
            parameters[19].Value = model.F_CarryContents;
            parameters[20].Value = model.F_State;
            parameters[21].Value = model.F_FinishTime;
            parameters[22].Value = model.F_CreateCode;
            parameters[23].Value = model.F_CreateName;
            parameters[24].Value = model.F_IsDel;
            parameters[25].Value = model.F_DeleteBy;
            parameters[26].Value = model.F_DeleteTime;
            parameters[27].Value = model.F_TransGoPerson;
            parameters[28].Value = model.F_TransOutPerson;
            parameters[29].Value = model.F_ControlManCode;
            parameters[30].Value = model.F_ControlManName;
            parameters[31].Value = model.F_DevOutState;
            parameters[32].Value = model.F_WoFlag;
            parameters[33].Value = model.F_DevOutNum;
            parameters[34].Value = model.F_DevInNum;
            parameters[35].Value = model.F_DevName;
            parameters[36].Value = model.F_DevStorageTime;
            parameters[37].Value = model.F_WoID;
            parameters[38].Value = model.F_FinishMan;
            parameters[39].Value = model.F_FinishManName;
            parameters[40].Value = model.F_FinishManPhon;
            parameters[41].Value = model.F_FinishManTalkie;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(RMYY_CallCenter_Api.Model.T_Dev_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Dev_WorkOrder set ");
            strSql.Append("F_Type=@F_Type,");
            strSql.Append("F_Type1=@F_Type1,");
            strSql.Append("F_WorkOrderCode=@F_WorkOrderCode,");
            strSql.Append("F_HosId=@F_HosId,");
            strSql.Append("F_ProposerDeptId=@F_ProposerDeptId,");
            strSql.Append("F_ProposerCode=@F_ProposerCode,");
            strSql.Append("F_ProposerName=@F_ProposerName,");
            strSql.Append("F_ProposerPhon=@F_ProposerPhon,");
            strSql.Append("F_Source=@F_Source,");
            strSql.Append("F_CallID=@F_CallID,");
            strSql.Append("F_DealType=@F_DealType,");
            strSql.Append("F_TransferDeptId=@F_TransferDeptId,");
            strSql.Append("F_TransferDeptName=@F_TransferDeptName,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_HandleByCode=@F_HandleByCode,");
            strSql.Append("F_HandleByName=@F_HandleByName,");
            strSql.Append("F_HandleTime=@F_HandleTime,");
            strSql.Append("F_HandleContents=@F_HandleContents,");
            strSql.Append("F_CarryContents=@F_CarryContents,");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_FinishTime=@F_FinishTime,");
            strSql.Append("F_CreateCode=@F_CreateCode,");
            strSql.Append("F_CreateName=@F_CreateName,");
            strSql.Append("F_IsDel=@F_IsDel,");
            strSql.Append("F_DeleteBy=@F_DeleteBy,");
            strSql.Append("F_DeleteTime=@F_DeleteTime,");
            strSql.Append("F_TransGoPerson=@F_TransGoPerson,");
            strSql.Append("F_TransOutPerson=@F_TransOutPerson,");
            strSql.Append("F_ControlManCode=@F_ControlManCode,");
            strSql.Append("F_ControlManName=@F_ControlManName,");
            strSql.Append("F_DevOutState=@F_DevOutState,");
            strSql.Append("F_WoFlag=@F_WoFlag,");
            strSql.Append("F_DevOutNum=@F_DevOutNum,");
            strSql.Append("F_DevInNum=@F_DevInNum,");
            strSql.Append("F_DevName=@F_DevName,");
            strSql.Append("F_DevStorageTime=@F_DevStorageTime,");
            strSql.Append("F_WoID=@F_WoID,");
            strSql.Append("F_FinishMan=@F_FinishMan,");
            strSql.Append("F_FinishManName=@F_FinishManName,");
            strSql.Append("F_FinishManPhon=@F_FinishManPhon,");
            strSql.Append("F_FinishManTalkie=@F_FinishManTalkie");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Type", SqlDbType.Int,4),
                    new SqlParameter("@F_Type1", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkOrderCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HosId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ProposerName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ProposerPhon", SqlDbType.VarChar,20),
                    new SqlParameter("@F_Source", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CallID", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DealType", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TransferDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_TransferDeptName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HandleByCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HandleByName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HandleTime", SqlDbType.DateTime),
                    new SqlParameter("@F_HandleContents", SqlDbType.NText),
                    new SqlParameter("@F_CarryContents", SqlDbType.NText),
                    new SqlParameter("@F_State", SqlDbType.Int,4),
                    new SqlParameter("@F_FinishTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_IsDel", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteBy", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_TransGoPerson", SqlDbType.NText),
                    new SqlParameter("@F_TransOutPerson", SqlDbType.NText),
                    new SqlParameter("@F_ControlManCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ControlManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DevOutState", SqlDbType.Int,4),
                    new SqlParameter("@F_WoFlag", SqlDbType.Int,4),
                    new SqlParameter("@F_DevOutNum", SqlDbType.Int,4),
                    new SqlParameter("@F_DevInNum", SqlDbType.Int,4),
                    new SqlParameter("@F_DevName", SqlDbType.NText),
                    new SqlParameter("@F_DevStorageTime", SqlDbType.DateTime),
                    new SqlParameter("@F_WoID", SqlDbType.Int,4),
                    new SqlParameter("@F_FinishMan", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManPhon", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FinishManTalkie", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_Type;
            parameters[1].Value = model.F_Type1;
            parameters[2].Value = model.F_WorkOrderCode;
            parameters[3].Value = model.F_HosId;
            parameters[4].Value = model.F_ProposerDeptId;
            parameters[5].Value = model.F_ProposerCode;
            parameters[6].Value = model.F_ProposerName;
            parameters[7].Value = model.F_ProposerPhon;
            parameters[8].Value = model.F_Source;
            parameters[9].Value = model.F_CallID;
            parameters[10].Value = model.F_DealType;
            parameters[11].Value = model.F_TransferDeptId;
            parameters[12].Value = model.F_TransferDeptName;
            parameters[13].Value = model.F_Remark;
            parameters[14].Value = model.F_CreateTime;
            parameters[15].Value = model.F_HandleByCode;
            parameters[16].Value = model.F_HandleByName;
            parameters[17].Value = model.F_HandleTime;
            parameters[18].Value = model.F_HandleContents;
            parameters[19].Value = model.F_CarryContents;
            parameters[20].Value = model.F_State;
            parameters[21].Value = model.F_FinishTime;
            parameters[22].Value = model.F_CreateCode;
            parameters[23].Value = model.F_CreateName;
            parameters[24].Value = model.F_IsDel;
            parameters[25].Value = model.F_DeleteBy;
            parameters[26].Value = model.F_DeleteTime;
            parameters[27].Value = model.F_TransGoPerson;
            parameters[28].Value = model.F_TransOutPerson;
            parameters[29].Value = model.F_ControlManCode;
            parameters[30].Value = model.F_ControlManName;
            parameters[31].Value = model.F_DevOutState;
            parameters[32].Value = model.F_WoFlag;
            parameters[33].Value = model.F_DevOutNum;
            parameters[34].Value = model.F_DevInNum;
            parameters[35].Value = model.F_DevName;
            parameters[36].Value = model.F_DevStorageTime;
            parameters[37].Value = model.F_WoID;
            parameters[38].Value = model.F_FinishMan;
            parameters[39].Value = model.F_FinishManName;
            parameters[40].Value = model.F_FinishManPhon;
            parameters[41].Value = model.F_FinishManTalkie;
            parameters[42].Value = model.F_Id;

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

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

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

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


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Dev_WorkOrder GetModel(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_Id,F_Type,F_Type1,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DealType,F_TransferDeptId,F_TransferDeptName,F_Remark,F_CreateTime,F_HandleByCode,F_HandleByName,F_HandleTime,F_HandleContents,F_CarryContents,F_State,F_FinishTime,F_CreateCode,F_CreateName,F_IsDel,F_DeleteBy,F_DeleteTime,F_TransGoPerson,F_TransOutPerson,F_ControlManCode,F_ControlManName,F_DevOutState,F_WoFlag,F_DevOutNum,F_DevInNum,F_DevName,F_DevStorageTime,F_WoID,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie from T_Dev_WorkOrder ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

            RMYY_CallCenter_Api.Model.T_Dev_WorkOrder model = new RMYY_CallCenter_Api.Model.T_Dev_WorkOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Dev_WorkOrder DataRowToModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Dev_WorkOrder model = new RMYY_CallCenter_Api.Model.T_Dev_WorkOrder();
            if (row != null)
            {
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
                {
                    model.F_Id = int.Parse(row["F_Id"].ToString());
                }
                if (row["F_Type"] != null && row["F_Type"].ToString() != "")
                {
                    model.F_Type = int.Parse(row["F_Type"].ToString());
                }
                if (row["F_Type1"] != null && row["F_Type1"].ToString() != "")
                {
                    model.F_Type1 = int.Parse(row["F_Type1"].ToString());
                }
                if (row["F_WorkOrderCode"] != null)
                {
                    model.F_WorkOrderCode = row["F_WorkOrderCode"].ToString();
                }
                if (row["F_HosId"] != null && row["F_HosId"].ToString() != "")
                {
                    model.F_HosId = int.Parse(row["F_HosId"].ToString());
                }
                if (row["F_ProposerDeptId"] != null && row["F_ProposerDeptId"].ToString() != "")
                {
                    model.F_ProposerDeptId = int.Parse(row["F_ProposerDeptId"].ToString());
                }
                if (row["F_ProposerCode"] != null)
                {
                    model.F_ProposerCode = row["F_ProposerCode"].ToString();
                }
                if (row["F_ProposerName"] != null)
                {
                    model.F_ProposerName = row["F_ProposerName"].ToString();
                }
                if (row["F_ProposerPhon"] != null)
                {
                    model.F_ProposerPhon = row["F_ProposerPhon"].ToString();
                }
                if (row["F_Source"] != null)
                {
                    model.F_Source = row["F_Source"].ToString();
                }
                if (row["F_CallID"] != null)
                {
                    model.F_CallID = row["F_CallID"].ToString();
                }
                if (row["F_DealType"] != null)
                {
                    model.F_DealType = row["F_DealType"].ToString();
                }
                if (row["F_TransferDeptId"] != null && row["F_TransferDeptId"].ToString() != "")
                {
                    model.F_TransferDeptId = int.Parse(row["F_TransferDeptId"].ToString());
                }
                if (row["F_TransferDeptName"] != null)
                {
                    model.F_TransferDeptName = row["F_TransferDeptName"].ToString();
                }
                if (row["F_Remark"] != null)
                {
                    model.F_Remark = row["F_Remark"].ToString();
                }
                if (row["F_CreateTime"] != null && row["F_CreateTime"].ToString() != "")
                {
                    model.F_CreateTime = DateTime.Parse(row["F_CreateTime"].ToString());
                }
                if (row["F_HandleByCode"] != null)
                {
                    model.F_HandleByCode = row["F_HandleByCode"].ToString();
                }
                if (row["F_HandleByName"] != null)
                {
                    model.F_HandleByName = row["F_HandleByName"].ToString();
                }
                if (row["F_HandleTime"] != null && row["F_HandleTime"].ToString() != "")
                {
                    model.F_HandleTime = DateTime.Parse(row["F_HandleTime"].ToString());
                }
                if (row["F_HandleContents"] != null)
                {
                    model.F_HandleContents = row["F_HandleContents"].ToString();
                }
                if (row["F_CarryContents"] != null)
                {
                    model.F_CarryContents = row["F_CarryContents"].ToString();
                }
                if (row["F_State"] != null && row["F_State"].ToString() != "")
                {
                    model.F_State = int.Parse(row["F_State"].ToString());
                }
                if (row["F_FinishTime"] != null && row["F_FinishTime"].ToString() != "")
                {
                    model.F_FinishTime = DateTime.Parse(row["F_FinishTime"].ToString());
                }
                if (row["F_CreateCode"] != null)
                {
                    model.F_CreateCode = row["F_CreateCode"].ToString();
                }
                if (row["F_CreateName"] != null)
                {
                    model.F_CreateName = row["F_CreateName"].ToString();
                }
                if (row["F_IsDel"] != null && row["F_IsDel"].ToString() != "")
                {
                    model.F_IsDel = int.Parse(row["F_IsDel"].ToString());
                }
                if (row["F_DeleteBy"] != null)
                {
                    model.F_DeleteBy = row["F_DeleteBy"].ToString();
                }
                if (row["F_DeleteTime"] != null && row["F_DeleteTime"].ToString() != "")
                {
                    model.F_DeleteTime = DateTime.Parse(row["F_DeleteTime"].ToString());
                }
                if (row["F_TransGoPerson"] != null)
                {
                    model.F_TransGoPerson = row["F_TransGoPerson"].ToString();
                }
                if (row["F_TransOutPerson"] != null)
                {
                    model.F_TransOutPerson = row["F_TransOutPerson"].ToString();
                }
                if (row["F_ControlManCode"] != null)
                {
                    model.F_ControlManCode = row["F_ControlManCode"].ToString();
                }
                if (row["F_ControlManName"] != null)
                {
                    model.F_ControlManName = row["F_ControlManName"].ToString();
                }
                if (row["F_DevOutState"] != null && row["F_DevOutState"].ToString() != "")
                {
                    model.F_DevOutState = int.Parse(row["F_DevOutState"].ToString());
                }
                if (row["F_WoFlag"] != null && row["F_WoFlag"].ToString() != "")
                {
                    model.F_WoFlag = int.Parse(row["F_WoFlag"].ToString());
                }
                if (row["F_DevOutNum"] != null && row["F_DevOutNum"].ToString() != "")
                {
                    model.F_DevOutNum = int.Parse(row["F_DevOutNum"].ToString());
                }
                if (row["F_DevInNum"] != null && row["F_DevInNum"].ToString() != "")
                {
                    model.F_DevInNum = int.Parse(row["F_DevInNum"].ToString());
                }
                if (row["F_DevName"] != null)
                {
                    model.F_DevName = row["F_DevName"].ToString();
                }
                if (row["F_DevStorageTime"] != null && row["F_DevStorageTime"].ToString() != "")
                {
                    model.F_DevStorageTime = DateTime.Parse(row["F_DevStorageTime"].ToString());
                }
                if (row["F_WoID"] != null && row["F_WoID"].ToString() != "")
                {
                    model.F_WoID = int.Parse(row["F_WoID"].ToString());
                }
                if (row["F_FinishMan"] != null)
                {
                    model.F_FinishMan = row["F_FinishMan"].ToString();
                }
                if (row["F_FinishManName"] != null)
                {
                    model.F_FinishManName = row["F_FinishManName"].ToString();
                }
                if (row["F_FinishManPhon"] != null)
                {
                    model.F_FinishManPhon = row["F_FinishManPhon"].ToString();
                }
                if (row["F_FinishManTalkie"] != null)
                {
                    model.F_FinishManTalkie = row["F_FinishManTalkie"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_Id,F_Type,F_Type1,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DealType,F_TransferDeptId,F_TransferDeptName,F_Remark,F_CreateTime,F_HandleByCode,F_HandleByName,F_HandleTime,F_HandleContents,F_CarryContents,F_State,F_FinishTime,F_CreateCode,F_CreateName,F_IsDel,F_DeleteBy,F_DeleteTime,F_TransGoPerson,F_TransOutPerson,F_ControlManCode,F_ControlManName,F_DevOutState,F_WoFlag,F_DevOutNum,F_DevInNum,F_DevName,F_DevStorageTime,F_WoID,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie");
            strSql.Append(" FROM T_Dev_WorkOrder ");
            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_Id,F_Type,F_Type1,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DealType,F_TransferDeptId,F_TransferDeptName,F_Remark,F_CreateTime,F_HandleByCode,F_HandleByName,F_HandleTime,F_HandleContents,F_CarryContents,F_State,F_FinishTime,F_CreateCode,F_CreateName,F_IsDel,F_DeleteBy,F_DeleteTime,F_TransGoPerson,F_TransOutPerson,F_ControlManCode,F_ControlManName,F_DevOutState,F_WoFlag,F_DevOutNum,F_DevInNum,F_DevName,F_DevStorageTime,F_WoID,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie ");
            strSql.Append(" FROM T_Dev_WorkOrder ");
            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_Dev_WorkOrder ");
            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_Id desc");
            }
            strSql.Append(")AS Row, T.*  from T_Dev_WorkOrder 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());
        }

        #endregion  BasicMethod


        #region  ExtensionMethod
        /// <summary>
        /// 导出报表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            strSql.Append("F_WorkOrderCode,case isnull(F_Type,0) when 1 then '设备租赁'end,(select F_DeptName from T_Sys_Department where F_DeptId= T.F_ProposerDeptId),");
            strSql.Append("F_CarryContents, F_ProposerName, F_ProposerPhon, F_ControlManName+'('+F_ControlManCode+')',F_CreateTime,'设备租赁科',F_TransGoPerson,F_TransOutPerson,F_Remark");
            strSql.Append(" from T_Dev_WorkOrder T");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 自定义删除
        /// </summary>
        /// <param name="idlist"></param>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public bool CustomDelete(string idlist,string usercode)
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("update T_Dev_WorkOrder set F_IsDel = 1, F_DeleteBy = '"+ usercode + "', F_DeleteTime = getdate() where F_Id in ("+ idlist.TrimEnd(',') + ")or F_WoID in (" + idlist.TrimEnd(',') + ")");
            if (DbHelperSQL.ExecuteSql(strsql.ToString()) > 0)
                return true;
            else return false;
        }
        #endregion  ExtensionMethod
    }
}
