using Maticsoft.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMSUI.Model
{
    public class AGVAboveFetalToolModel
    {
        public int AGVID = 0;
        public string Meaterials = "";
    }
    public class AGVAboveFetalToolInformationSQL
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(AGVAboveFetalToolModel t)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into AGVAboveFetalToolInformation(");
            strSql.Append("AGVID,Meaterials)");

            strSql.Append($" values ({t.AGVID},'{t.Meaterials}')");

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static void Delete(AGVAboveFetalToolModel t)
        {
            string strSql = $" delete from AGVAboveFetalToolInformation where AGVID = {t.AGVID}";
            DbHelperSQL.ExecuteSql(strSql);
        }
        public static List<AGVAboveFetalToolModel> GetList(string strWhere)
        {
            List<AGVAboveFetalToolModel> listAGVAboveFetalTools = new List<AGVAboveFetalToolModel>();
            StringBuilder sql = new StringBuilder();
            sql.Append($"select * from AGVAboveFetalToolInformation ");
            if (strWhere != "")
            {
                sql.Append($"{strWhere}");
            }
            DataTable dt = DbHelperSQL.Query(sql.ToString()).Tables[0];
            if (dt?.Rows.Count > 0)
            {
                listAGVAboveFetalTools = (from s in dt.AsEnumerable()
                                          select new AGVAboveFetalToolModel
                                          {
                                              AGVID = s.Field<int>("AGVID"),
                                              Meaterials = s.Field<string>("Meaterials"),
                                          }).ToList();
            }
            return listAGVAboveFetalTools;
        }
        public static bool Update(AGVAboveFetalToolModel t)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update AGVAboveFetalToolInformation set ");
            strSql.Append($"AGVID={t.AGVID}, ");
            strSql.Append($"Meaterials='{t.Meaterials}' ");
            strSql.Append($" where AGVID={t.AGVID} ");
            return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
        }
    }
}
