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_Dis_WorkOrder
	/// </summary>
	public partial class T_Dis_WorkOrder
    {
        public T_Dis_WorkOrder()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Dis_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_Dis_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Dis_WorkOrder(");
            strSql.Append("F_Type,F_OrtherType,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerDeptName,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DisNum,F_ItemMessages,F_ItemContents,F_Remark,F_CreateTime,F_CreateCode,F_CreateName,F_State,F_ControlManCode,F_ControlManName,F_TransPersonCode,F_TransPerson,F_BedPosition,F_SureMan,F_SureManName,F_SureManPhon,F_IsDel,F_DeleteBy,F_DeleteTime,F_FinishTime,F_IsThird,F_Islarge,F_CarryTime,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie,F_SendDeptId,F_SendDeptName)");
            strSql.Append(" values (");
            strSql.Append("@F_Type,@F_OrtherType,@F_WorkOrderCode,@F_HosId,@F_ProposerDeptId,@F_ProposerDeptName,@F_ProposerCode,@F_ProposerName,@F_ProposerPhon,@F_Source,@F_CallID,@F_DisNum,@F_ItemMessages,@F_ItemContents,@F_Remark,@F_CreateTime,@F_CreateCode,@F_CreateName,@F_State,@F_ControlManCode,@F_ControlManName,@F_TransPersonCode,@F_TransPerson,@F_BedPosition,@F_SureMan,@F_SureManName,@F_SureManPhon,@F_IsDel,@F_DeleteBy,@F_DeleteTime,@F_FinishTime,@F_IsThird,@F_Islarge,@F_CarryTime,@F_FinishMan,@F_FinishManName,@F_FinishManPhon,@F_FinishManTalkie,@F_SendDeptId,@F_SendDeptName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Type", SqlDbType.Int,4),
                    new SqlParameter("@F_OrtherType", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WorkOrderCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HosId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptName", SqlDbType.VarChar,50),
                    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_DisNum", SqlDbType.Int,4),
                    new SqlParameter("@F_ItemMessages", SqlDbType.NText),
                    new SqlParameter("@F_ItemContents", SqlDbType.NText),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_State", SqlDbType.Int,4),
                    new SqlParameter("@F_ControlManCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ControlManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_TransPersonCode", SqlDbType.NText),
                    new SqlParameter("@F_TransPerson", SqlDbType.NText),
                    new SqlParameter("@F_BedPosition", SqlDbType.VarChar,100),
                    new SqlParameter("@F_SureMan", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SureManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SureManPhon", SqlDbType.VarChar,20),
                    new SqlParameter("@F_IsDel", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteBy", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_FinishTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsThird", SqlDbType.Int,4),
                    new SqlParameter("@F_Islarge", SqlDbType.Int,4),
                    new SqlParameter("@F_CarryTime", SqlDbType.DateTime),
                    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_SendDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_SendDeptName", SqlDbType.VarChar,50)};
            parameters[0].Value = model.F_Type;
            parameters[1].Value = model.F_OrtherType;
            parameters[2].Value = model.F_WorkOrderCode;
            parameters[3].Value = model.F_HosId;
            parameters[4].Value = model.F_ProposerDeptId;
            parameters[5].Value = model.F_ProposerDeptName;
            parameters[6].Value = model.F_ProposerCode;
            parameters[7].Value = model.F_ProposerName;
            parameters[8].Value = model.F_ProposerPhon;
            parameters[9].Value = model.F_Source;
            parameters[10].Value = model.F_CallID;
            parameters[11].Value = model.F_DisNum;
            parameters[12].Value = model.F_ItemMessages;
            parameters[13].Value = model.F_ItemContents;
            parameters[14].Value = model.F_Remark;
            parameters[15].Value = model.F_CreateTime;
            parameters[16].Value = model.F_CreateCode;
            parameters[17].Value = model.F_CreateName;
            parameters[18].Value = model.F_State;
            parameters[19].Value = model.F_ControlManCode;
            parameters[20].Value = model.F_ControlManName;
            parameters[21].Value = model.F_TransPersonCode;
            parameters[22].Value = model.F_TransPerson;
            parameters[23].Value = model.F_BedPosition;
            parameters[24].Value = model.F_SureMan;
            parameters[25].Value = model.F_SureManName;
            parameters[26].Value = model.F_SureManPhon;
            parameters[27].Value = model.F_IsDel;
            parameters[28].Value = model.F_DeleteBy;
            parameters[29].Value = model.F_DeleteTime;
            parameters[30].Value = model.F_FinishTime;
            parameters[31].Value = model.F_IsThird;
            parameters[32].Value = model.F_Islarge;
            parameters[33].Value = model.F_CarryTime;
            parameters[34].Value = model.F_FinishMan;
            parameters[35].Value = model.F_FinishManName;
            parameters[36].Value = model.F_FinishManPhon;
            parameters[37].Value = model.F_FinishManTalkie;
            parameters[38].Value = model.F_SendDeptId;
            parameters[39].Value = model.F_SendDeptName;

            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_Dis_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Dis_WorkOrder set ");
            strSql.Append("F_Type=@F_Type,");
            strSql.Append("F_OrtherType=@F_OrtherType,");
            strSql.Append("F_WorkOrderCode=@F_WorkOrderCode,");
            strSql.Append("F_HosId=@F_HosId,");
            strSql.Append("F_ProposerDeptId=@F_ProposerDeptId,");
            strSql.Append("F_ProposerDeptName=@F_ProposerDeptName,");
            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_DisNum=@F_DisNum,");
            strSql.Append("F_ItemMessages=@F_ItemMessages,");
            strSql.Append("F_ItemContents=@F_ItemContents,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_CreateCode=@F_CreateCode,");
            strSql.Append("F_CreateName=@F_CreateName,");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_ControlManCode=@F_ControlManCode,");
            strSql.Append("F_ControlManName=@F_ControlManName,");
            strSql.Append("F_TransPersonCode=@F_TransPersonCode,");
            strSql.Append("F_TransPerson=@F_TransPerson,");
            strSql.Append("F_BedPosition=@F_BedPosition,");
            strSql.Append("F_SureMan=@F_SureMan,");
            strSql.Append("F_SureManName=@F_SureManName,");
            strSql.Append("F_SureManPhon=@F_SureManPhon,");
            strSql.Append("F_IsDel=@F_IsDel,");
            strSql.Append("F_DeleteBy=@F_DeleteBy,");
            strSql.Append("F_DeleteTime=@F_DeleteTime,");
            strSql.Append("F_FinishTime=@F_FinishTime,");
            strSql.Append("F_IsThird=@F_IsThird,");
            strSql.Append("F_Islarge=@F_Islarge,");
            strSql.Append("F_CarryTime=@F_CarryTime,");
            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("F_SendDeptId=@F_SendDeptId,");
            strSql.Append("F_SendDeptName=@F_SendDeptName");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Type", SqlDbType.Int,4),
                    new SqlParameter("@F_OrtherType", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WorkOrderCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HosId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_ProposerDeptName", SqlDbType.VarChar,50),
                    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_DisNum", SqlDbType.Int,4),
                    new SqlParameter("@F_ItemMessages", SqlDbType.NText),
                    new SqlParameter("@F_ItemContents", SqlDbType.NText),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_State", SqlDbType.Int,4),
                    new SqlParameter("@F_ControlManCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ControlManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_TransPersonCode", SqlDbType.NText),
                    new SqlParameter("@F_TransPerson", SqlDbType.NText),
                    new SqlParameter("@F_BedPosition", SqlDbType.VarChar,100),
                    new SqlParameter("@F_SureMan", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SureManName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SureManPhon", SqlDbType.VarChar,20),
                    new SqlParameter("@F_IsDel", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteBy", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_FinishTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsThird", SqlDbType.Int,4),
                    new SqlParameter("@F_Islarge", SqlDbType.Int,4),
                    new SqlParameter("@F_CarryTime", SqlDbType.DateTime),
                    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_SendDeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_SendDeptName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_Type;
            parameters[1].Value = model.F_OrtherType;
            parameters[2].Value = model.F_WorkOrderCode;
            parameters[3].Value = model.F_HosId;
            parameters[4].Value = model.F_ProposerDeptId;
            parameters[5].Value = model.F_ProposerDeptName;
            parameters[6].Value = model.F_ProposerCode;
            parameters[7].Value = model.F_ProposerName;
            parameters[8].Value = model.F_ProposerPhon;
            parameters[9].Value = model.F_Source;
            parameters[10].Value = model.F_CallID;
            parameters[11].Value = model.F_DisNum;
            parameters[12].Value = model.F_ItemMessages;
            parameters[13].Value = model.F_ItemContents;
            parameters[14].Value = model.F_Remark;
            parameters[15].Value = model.F_CreateTime;
            parameters[16].Value = model.F_CreateCode;
            parameters[17].Value = model.F_CreateName;
            parameters[18].Value = model.F_State;
            parameters[19].Value = model.F_ControlManCode;
            parameters[20].Value = model.F_ControlManName;
            parameters[21].Value = model.F_TransPersonCode;
            parameters[22].Value = model.F_TransPerson;
            parameters[23].Value = model.F_BedPosition;
            parameters[24].Value = model.F_SureMan;
            parameters[25].Value = model.F_SureManName;
            parameters[26].Value = model.F_SureManPhon;
            parameters[27].Value = model.F_IsDel;
            parameters[28].Value = model.F_DeleteBy;
            parameters[29].Value = model.F_DeleteTime;
            parameters[30].Value = model.F_FinishTime;
            parameters[31].Value = model.F_IsThird;
            parameters[32].Value = model.F_Islarge;
            parameters[33].Value = model.F_CarryTime;
            parameters[34].Value = model.F_FinishMan;
            parameters[35].Value = model.F_FinishManName;
            parameters[36].Value = model.F_FinishManPhon;
            parameters[37].Value = model.F_FinishManTalkie;
            parameters[38].Value = model.F_SendDeptId;
            parameters[39].Value = model.F_SendDeptName;
            parameters[40].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_Dis_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_Dis_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_Dis_WorkOrder GetModel(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_Id,F_Type,F_OrtherType,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerDeptName,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DisNum,F_ItemMessages,F_ItemContents,F_Remark,F_CreateTime,F_CreateCode,F_CreateName,F_State,F_ControlManCode,F_ControlManName,F_TransPersonCode,F_TransPerson,F_BedPosition,F_SureMan,F_SureManName,F_SureManPhon,F_IsDel,F_DeleteBy,F_DeleteTime,F_FinishTime,F_IsThird,F_Islarge,F_CarryTime,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie,F_SendDeptId,F_SendDeptName from T_Dis_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_Dis_WorkOrder model = new RMYY_CallCenter_Api.Model.T_Dis_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_Dis_WorkOrder DataRowToModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Dis_WorkOrder model = new RMYY_CallCenter_Api.Model.T_Dis_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_OrtherType"] != null)
                {
                    model.F_OrtherType = row["F_OrtherType"].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_ProposerDeptName"] != null)
                {
                    model.F_ProposerDeptName = row["F_ProposerDeptName"].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_DisNum"] != null && row["F_DisNum"].ToString() != "")
                {
                    model.F_DisNum = int.Parse(row["F_DisNum"].ToString());
                }
                if (row["F_ItemMessages"] != null)
                {
                    model.F_ItemMessages = row["F_ItemMessages"].ToString();
                }
                if (row["F_ItemContents"] != null)
                {
                    model.F_ItemContents = row["F_ItemContents"].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_CreateCode"] != null)
                {
                    model.F_CreateCode = row["F_CreateCode"].ToString();
                }
                if (row["F_CreateName"] != null)
                {
                    model.F_CreateName = row["F_CreateName"].ToString();
                }
                if (row["F_State"] != null && row["F_State"].ToString() != "")
                {
                    model.F_State = int.Parse(row["F_State"].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_TransPersonCode"] != null)
                {
                    model.F_TransPersonCode = row["F_TransPersonCode"].ToString();
                }
                if (row["F_TransPerson"] != null)
                {
                    model.F_TransPerson = row["F_TransPerson"].ToString();
                }
                if (row["F_BedPosition"] != null)
                {
                    model.F_BedPosition = row["F_BedPosition"].ToString();
                }
                if (row["F_SureMan"] != null)
                {
                    model.F_SureMan = row["F_SureMan"].ToString();
                }
                if (row["F_SureManName"] != null)
                {
                    model.F_SureManName = row["F_SureManName"].ToString();
                }
                if (row["F_SureManPhon"] != null)
                {
                    model.F_SureManPhon = row["F_SureManPhon"].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_FinishTime"] != null && row["F_FinishTime"].ToString() != "")
                {
                    model.F_FinishTime = DateTime.Parse(row["F_FinishTime"].ToString());
                }
                if (row["F_IsThird"] != null && row["F_IsThird"].ToString() != "")
                {
                    model.F_IsThird = int.Parse(row["F_IsThird"].ToString());
                }
                if (row["F_Islarge"] != null && row["F_Islarge"].ToString() != "")
                {
                    model.F_Islarge = int.Parse(row["F_Islarge"].ToString());
                }
                if (row["F_CarryTime"] != null && row["F_CarryTime"].ToString() != "")
                {
                    model.F_CarryTime = DateTime.Parse(row["F_CarryTime"].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();
                }
                if (row["F_SendDeptId"] != null && row["F_SendDeptId"].ToString() != "")
                {
                    model.F_SendDeptId = int.Parse(row["F_SendDeptId"].ToString());
                }
                if (row["F_SendDeptName"] != null)
                {
                    model.F_SendDeptName = row["F_SendDeptName"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_Id,F_Type,F_OrtherType,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerDeptName,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DisNum,F_ItemMessages,F_ItemContents,F_Remark,F_CreateTime,F_CreateCode,F_CreateName,F_State,F_ControlManCode,F_ControlManName,F_TransPersonCode,F_TransPerson,F_BedPosition,F_SureMan,F_SureManName,F_SureManPhon,F_IsDel,F_DeleteBy,F_DeleteTime,F_FinishTime,F_IsThird,F_Islarge,F_CarryTime,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie,F_SendDeptId,F_SendDeptName ");
            strSql.Append(" FROM T_Dis_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_OrtherType,F_WorkOrderCode,F_HosId,F_ProposerDeptId,F_ProposerDeptName,F_ProposerCode,F_ProposerName,F_ProposerPhon,F_Source,F_CallID,F_DisNum,F_ItemMessages,F_ItemContents,F_Remark,F_CreateTime,F_CreateCode,F_CreateName,F_State,F_ControlManCode,F_ControlManName,F_TransPersonCode,F_TransPerson,F_BedPosition,F_SureMan,F_SureManName,F_SureManPhon,F_IsDel,F_DeleteBy,F_DeleteTime,F_FinishTime,F_IsThird,F_Islarge,F_CarryTime,F_FinishMan,F_FinishManName,F_FinishManPhon,F_FinishManTalkie,F_SendDeptId,F_SendDeptName ");
            strSql.Append(" FROM T_Dis_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_Dis_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_Dis_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 GetListUrgExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append($"select ");
            strSql.Append($"F_WorkOrderCode,'急查标本配送',F_ItemContents,F_ControlManName+'('+F_ControlManCode+')'as F_ControlMan, ");
            strSql.Append($" F_Source,F_ProposerDeptName, F_ProposerName,F_SendDeptName,F_CreateTime, '综合保障中心'as F_TransDept,F_TransPerson,F_Remark");
            strSql.Append($" from T_Dis_WorkOrder");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            strSql.Append($" ORDER BY F_Id desc");
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListBloodExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append($"select ");
            strSql.Append($"F_WorkOrderCode,'血液制品配送',F_ProposerDeptName,F_ItemContents,F_ProposerPhon,F_ProposerName,F_Source,F_SendDeptName,");
            strSql.Append($" F_ControlManName+'('+F_ControlManCode+')'as F_ControlMan,F_CreateTime, '综合保障中心'as F_TransDept,F_TransPerson,F_Remark");
            strSql.Append($" from T_Dis_WorkOrder");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            strSql.Append($" ORDER BY F_Id desc");
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet GetListRedExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append($"select ");
            strSql.Append($"F_WorkOrderCode,F_ProposerDeptName,F_ProposerName,F_ProposerPhon,'红处方配送',F_ItemContents,");
            strSql.Append($" F_ControlManName+'('+F_ControlManCode+')'as F_ControlMan,F_CreateTime, '综合保障中心'as F_TransDept,F_TransPerson,F_Remark");
            strSql.Append($" from T_Dis_WorkOrder");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            strSql.Append($" ORDER BY F_Id desc");
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListOrtherExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append($"select ");
            strSql.Append($"F_WorkOrderCode,F_ProposerDeptName,F_OrtherType,F_ItemContents,F_ProposerName,F_ProposerPhon,");
            strSql.Append($" F_ControlManName+'('+F_ControlManCode+')'as F_ControlMan,F_SendDeptName, F_BedPosition,F_CreateTime, '综合保障中心'as F_TransDept,F_TransPerson,F_Remark");
            strSql.Append($" from T_Dis_WorkOrder");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            strSql.Append($" ORDER BY F_Id desc");
            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_Dis_WorkOrder set F_IsDel = 1, F_DeleteBy = '" + usercode + "', F_DeleteTime = getdate() where F_Id in (" + idlist.TrimEnd(',') + ")");
            if (DbHelperSQL.ExecuteSql(strsql.ToString()) > 0)
                return true;
            else return false;
        }
        #endregion  ExtensionMethod
}
}

