using CallCenterApi.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 CallCenterApi.DAL
{
    public class T_Call_PageTemp
    {
        public T_Call_PageTemp()
        { }
        #region  Method

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.T_Call_PageTemp model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Call_PageTemp(");
            strSql.Append("F_Name)");
            strSql.Append(" values (");
            strSql.Append("@F_Name)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Name",System.Data.SqlDbType.NVarChar,300),
                };
            parameters[0].Value = model.F_Name;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 修改一条数据
        /// </summary>
        public int Update(Model.T_Call_PageTemp model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Update T_Call_PageTemp Set F_Name=@F_Name where F_Id=@F_Id");

            SqlParameter[] parameters = {
                    new SqlParameter("@F_Name",System.Data.SqlDbType.NVarChar,300),
                    new SqlParameter("@F_Id",System.Data.SqlDbType.Int,8),
                };
            parameters[0].Value = model.F_Name;
            parameters[1].Value = model.F_Id;
            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

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

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Call_PageTemp where F_Id=@F_Id");
            strSql.Append("");
            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 Model.T_Call_PageTemp GetModel(int id)
        {

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

            var dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0];
            var model = new Model.T_Call_PageTemp();
            model.F_Id = Convert.ToInt32(dt.Rows[0]["F_Id"]);
            model.F_Name = dt.Rows[0]["F_Name"] == DBNull.Value ? "" : dt.Rows[0]["F_Name"].ToString();
            return model;
        }


        #endregion  Method
    }
}
