Bill.cs 2.55 KB
using HHWCS.Model;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HHWCS.Bill
{
    public class Bill
    {
        public static List<TaskEntity> getTasks(string status,string taskNo,string pallet,DateTime? beginTime ,DateTime? endTime)
        {
            String sql = "select * from task where 1=1 ";
            if (!String.IsNullOrEmpty(status))
            {
                sql += " and status = '" + status + "'";
            }
            if (!String.IsNullOrEmpty(taskNo))
            {
                sql += " and id = " + taskNo;
            }
            if (!String.IsNullOrEmpty(pallet))
            {
                sql += " and containerCode = '" + pallet + "'";
            }
            if (beginTime != null)
            {
                sql += " and created>='" + beginTime.ToString()+"'";
            }
            if (endTime != null)
            {
                sql += " and created<='" + endTime.ToString()+"'";
            }


            DataSet ds = MySqlHelper.ExecuteDataset(AppCommon.MysqlConnection, sql);
            if (ds == null || ds.Tables.Count == 0)
            {
                return null;
            }
            return ds.Tables[0].AsEnumerable().Select(x => new TaskEntity {
                Id = (int)x["id"],
                WarehouseId = Convert.ToInt32(x["warehouseId"]),
                WarehouseCode = x["warehouseCode"]?.ToString(),
                CompanyId = x["companyId"] is DBNull?null:(int?)x["companyId"],
                Priority = Convert.ToInt32(x["priority"]),
                Type = Convert.ToInt32(x["type"]),
                Station = x["station"] is DBNull ? null : (int?)x["station"],
                ContainerId = x["containerId"] is DBNull ? null : (int?)x["containerId"],
                ContainerCode = x["containerCode"]?.ToString(),
                SourceLocation = x["sourceLocation"]?.ToString(),
                DestinationLocation = x["destinationLocation"]?.ToString(),
                Status = Convert.ToInt32(x["status"]),
                Created = x["created"] is DBNull ? null:(DateTime?)x["created"],
                CreatedBy = x["createdBy"]?.ToString(),
                BeginTime =x["beginTime"] is DBNull?null:(DateTime?)x["beginTime"],
                EndTime =x["endTime"] is DBNull ? null : (DateTime?)x["endTime"],
                LastUpdated=x["lastUpdated"] is DBNull ? null : (DateTime?)x["lastUpdated"],
            }).OrderByDescending(t=>t.Created).ToList();
        }
    }
}