/**  版本信息模板在安装目录下，可自行修改。
* work.cs
*
* 功 能： N/A
* 类 名： work
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2024-07-27 10:51:14   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Jpsoft.DAL
{
	/// <summary>
	/// 数据访问类:work
	/// </summary>
	public partial class Work
	{
		public Work()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string id_)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from base_work");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Jpsoft.Model.Work model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into base_work(");
			strSql.Append("id_,customer_id,name_,width_,number_,process_date,process_volume,process_remark,process_number,ratio_,colour_,estimate_quantity,estimate_remark,unit_price,reason_,cloth_price,wages_,roll_length,tag_operator,tag_factor,tag_factor_save,tag_unit,is_integer,remark_,status_,del_flag,create_by,create_time,update_by,update_time)");
			strSql.Append(" values (");
			strSql.Append("@id_,@customer_id,@name_,@width_,@number_,@process_date,@process_volume,@process_remark,@process_number,@ratio_,@colour_,@estimate_quantity,@estimate_remark,@unit_price,@reason_,@cloth_price,@wages_,@roll_length,@tag_operator,@tag_factor,@tag_factor_save,@tag_unit,@is_integer,@remark_,@status_,@del_flag,@create_by,@create_time,@update_by,@update_time)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36),
					new MySqlParameter("@customer_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@name_", MySqlDbType.VarChar,100),
					new MySqlParameter("@width_", MySqlDbType.Double),
					new MySqlParameter("@number_", MySqlDbType.VarChar,10),
					new MySqlParameter("@process_date", MySqlDbType.Timestamp),
					new MySqlParameter("@process_volume", MySqlDbType.Int32,11),
					new MySqlParameter("@process_remark", MySqlDbType.VarChar,100),
					new MySqlParameter("@process_number", MySqlDbType.Int32,11),
					new MySqlParameter("@ratio_", MySqlDbType.Decimal,10),
					new MySqlParameter("@colour_", MySqlDbType.VarChar,100),
					new MySqlParameter("@estimate_quantity", MySqlDbType.Decimal,10),
					new MySqlParameter("@estimate_remark", MySqlDbType.VarChar,100),
					new MySqlParameter("@unit_price", MySqlDbType.Decimal,10),
					new MySqlParameter("@reason_", MySqlDbType.VarChar,100),
					new MySqlParameter("@cloth_price", MySqlDbType.Decimal,10),
					new MySqlParameter("@wages_", MySqlDbType.Decimal,10),
					new MySqlParameter("@roll_length", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_operator", MySqlDbType.VarChar,10),
					new MySqlParameter("@tag_factor", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_factor_save", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_unit", MySqlDbType.VarChar,10),
					new MySqlParameter("@is_integer", MySqlDbType.Bit),
					new MySqlParameter("@remark_", MySqlDbType.VarChar,255),
					new MySqlParameter("@status_", MySqlDbType.Bit),
					new MySqlParameter("@del_flag", MySqlDbType.Bit),
					new MySqlParameter("@create_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@create_time", MySqlDbType.Timestamp),
					new MySqlParameter("@update_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@update_time", MySqlDbType.Timestamp)};
			parameters[0].Value = model.id_;
			parameters[1].Value = model.customer_id;
			parameters[2].Value = model.name_;
			parameters[3].Value = model.width_;
			parameters[4].Value = model.number_;
			parameters[5].Value = model.process_date;
			parameters[6].Value = model.process_volume;
			parameters[7].Value = model.process_remark;
			parameters[8].Value = model.process_number;
			parameters[9].Value = model.ratio_;
			parameters[10].Value = model.colour_;
			parameters[11].Value = model.estimate_quantity;
			parameters[12].Value = model.estimate_remark;
			parameters[13].Value = model.unit_price;
			parameters[14].Value = model.reason_;
			parameters[15].Value = model.cloth_price;
			parameters[16].Value = model.wages_;
			parameters[17].Value = model.roll_length;
			parameters[18].Value = model.tag_operator;
			parameters[19].Value = model.tag_factor;
			parameters[20].Value = model.tag_factor_save;
			parameters[21].Value = model.tag_unit;
			parameters[22].Value = model.is_integer;
			parameters[23].Value = model.remark_;
			parameters[24].Value = model.status_;
			parameters[25].Value = model.del_flag;
			parameters[26].Value = model.create_by;
			parameters[27].Value = model.create_time;
			parameters[28].Value = model.update_by;
			parameters[29].Value = model.update_time;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Jpsoft.Model.Work model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update base_work set ");
			strSql.Append("customer_id=@customer_id,");
			strSql.Append("name_=@name_,");
			strSql.Append("width_=@width_,");
			strSql.Append("number_=@number_,");
			strSql.Append("process_date=@process_date,");
			strSql.Append("process_volume=@process_volume,");
			strSql.Append("process_remark=@process_remark,");
			strSql.Append("process_number=@process_number,");
			strSql.Append("ratio_=@ratio_,");
			strSql.Append("colour_=@colour_,");
			strSql.Append("estimate_quantity=@estimate_quantity,");
			strSql.Append("estimate_remark=@estimate_remark,");
			strSql.Append("unit_price=@unit_price,");
			strSql.Append("reason_=@reason_,");
			strSql.Append("cloth_price=@cloth_price,");
			strSql.Append("wages_=@wages_,");
			strSql.Append("roll_length=@roll_length,");
			strSql.Append("tag_operator=@tag_operator,");
			strSql.Append("tag_factor=@tag_factor,");
			strSql.Append("tag_factor_save=@tag_factor_save,");
			strSql.Append("tag_unit=@tag_unit,");
			strSql.Append("is_integer=@is_integer,");
			strSql.Append("remark_=@remark_,");
			strSql.Append("status_=@status_,");
			strSql.Append("del_flag=@del_flag,");
			strSql.Append("create_by=@create_by,");
			strSql.Append("update_by=@update_by");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@customer_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@name_", MySqlDbType.VarChar,100),
					new MySqlParameter("@width_", MySqlDbType.Double),
					new MySqlParameter("@number_", MySqlDbType.VarChar,10),
					new MySqlParameter("@process_date", MySqlDbType.Timestamp),
					new MySqlParameter("@process_volume", MySqlDbType.Int32,11),
					new MySqlParameter("@process_remark", MySqlDbType.VarChar,100),
					new MySqlParameter("@process_number", MySqlDbType.Int32,11),
					new MySqlParameter("@ratio_", MySqlDbType.Decimal,10),
					new MySqlParameter("@colour_", MySqlDbType.VarChar,100),
					new MySqlParameter("@estimate_quantity", MySqlDbType.Decimal,10),
					new MySqlParameter("@estimate_remark", MySqlDbType.VarChar,100),
					new MySqlParameter("@unit_price", MySqlDbType.Decimal,10),
					new MySqlParameter("@reason_", MySqlDbType.VarChar,100),
					new MySqlParameter("@cloth_price", MySqlDbType.Decimal,10),
					new MySqlParameter("@wages_", MySqlDbType.Decimal,10),
					new MySqlParameter("@roll_length", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_operator", MySqlDbType.VarChar,10),
					new MySqlParameter("@tag_factor", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_factor_save", MySqlDbType.Decimal,10),
					new MySqlParameter("@tag_unit", MySqlDbType.VarChar,10),
					new MySqlParameter("@is_integer", MySqlDbType.Bit),
					new MySqlParameter("@remark_", MySqlDbType.VarChar,255),
					new MySqlParameter("@status_", MySqlDbType.Bit),
					new MySqlParameter("@del_flag", MySqlDbType.Bit),
					new MySqlParameter("@create_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@update_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)};
			parameters[0].Value = model.customer_id;
			parameters[1].Value = model.name_;
			parameters[2].Value = model.width_;
			parameters[3].Value = model.number_;
			parameters[4].Value = model.process_date;
			parameters[5].Value = model.process_volume;
			parameters[6].Value = model.process_remark;
			parameters[7].Value = model.process_number;
			parameters[8].Value = model.ratio_;
			parameters[9].Value = model.colour_;
			parameters[10].Value = model.estimate_quantity;
			parameters[11].Value = model.estimate_remark;
			parameters[12].Value = model.unit_price;
			parameters[13].Value = model.reason_;
			parameters[14].Value = model.cloth_price;
			parameters[15].Value = model.wages_;
			parameters[16].Value = model.roll_length;
			parameters[17].Value = model.tag_operator;
			parameters[18].Value = model.tag_factor;
			parameters[19].Value = model.tag_factor_save;
			parameters[20].Value = model.tag_unit;
			parameters[21].Value = model.is_integer;
			parameters[22].Value = model.remark_;
			parameters[23].Value = model.status_;
			parameters[24].Value = model.del_flag;
			parameters[25].Value = model.create_by;
			parameters[26].Value = model.update_by;
			parameters[27].Value = model.id_;

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

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string id_)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from base_work ");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Jpsoft.Model.Work GetModel(string id_)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id_,customer_id,name_,width_,number_,process_date,process_volume,process_remark,process_number,ratio_,colour_,estimate_quantity,estimate_remark,unit_price,reason_,cloth_price,wages_,roll_length,tag_operator,tag_factor,tag_factor_save,tag_unit,is_integer,remark_,status_,del_flag,create_by,create_time,update_by,update_time from base_work ");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Jpsoft.Model.Work DataRowToModel(DataRow row)
		{
			Jpsoft.Model.Work model=new Jpsoft.Model.Work();
			if (row != null)
			{
				if(row["id_"]!=null)
				{
					model.id_=row["id_"].ToString();
				}
				if(row["customer_id"]!=null)
				{
					model.customer_id=row["customer_id"].ToString();
				}
				if(row["name_"]!=null)
				{
					model.name_=row["name_"].ToString();
				}
				if (row["width_"] != null)
				{
					model.width_ = Convert.ToDouble(row["width_"]);
				}
				if (row["number_"]!=null)
				{
					model.number_=row["number_"].ToString();
				}
				if(row["process_date"]!=null && row["process_date"].ToString()!="")
				{
					model.process_date=DateTime.Parse(row["process_date"].ToString());
				}
				if(row["process_volume"]!=null && row["process_volume"].ToString()!="")
				{
					model.process_volume=int.Parse(row["process_volume"].ToString());
				}
				if(row["process_remark"]!=null)
				{
					model.process_remark=row["process_remark"].ToString();
				}
				if(row["process_number"]!=null && row["process_number"].ToString()!="")
				{
					model.process_number=int.Parse(row["process_number"].ToString());
				}
				if(row["ratio_"]!=null && row["ratio_"].ToString()!="")
				{
					model.ratio_=decimal.Parse(row["ratio_"].ToString());
				}
				if(row["colour_"]!=null)
				{
					model.colour_=row["colour_"].ToString();
				}
				if(row["estimate_quantity"]!=null && row["estimate_quantity"].ToString()!="")
				{
					model.estimate_quantity=decimal.Parse(row["estimate_quantity"].ToString());
				}
				if(row["estimate_remark"]!=null)
				{
					model.estimate_remark=row["estimate_remark"].ToString();
				}
				if(row["unit_price"]!=null && row["unit_price"].ToString()!="")
				{
					model.unit_price=decimal.Parse(row["unit_price"].ToString());
				}
				if(row["reason_"]!=null)
				{
					model.reason_=row["reason_"].ToString();
				}
				if(row["cloth_price"]!=null && row["cloth_price"].ToString()!="")
				{
					model.cloth_price=decimal.Parse(row["cloth_price"].ToString());
				}
				if(row["wages_"]!=null && row["wages_"].ToString()!="")
				{
					model.wages_=decimal.Parse(row["wages_"].ToString());
				}
				if(row["roll_length"]!=null && row["roll_length"].ToString()!="")
				{
					model.roll_length=decimal.Parse(row["roll_length"].ToString());
				}
				if(row["tag_operator"]!=null)
				{
					model.tag_operator=row["tag_operator"].ToString();
				}
				if(row["tag_factor"]!=null && row["tag_factor"].ToString()!="")
				{
					model.tag_factor=decimal.Parse(row["tag_factor"].ToString());
				}
				if(row["tag_factor_save"]!=null && row["tag_factor_save"].ToString()!="")
				{
					model.tag_factor_save=decimal.Parse(row["tag_factor_save"].ToString());
				}
				if(row["tag_unit"]!=null)
				{
					model.tag_unit=row["tag_unit"].ToString();
				}
				if(row["is_integer"]!=null && row["is_integer"].ToString()!="")
				{
					if((row["is_integer"].ToString()=="1")||(row["is_integer"].ToString().ToLower()=="true"))
					{
						model.is_integer=true;
					}
					else
					{
						model.is_integer=false;
					}
				}
				if(row["remark_"]!=null)
				{
					model.remark_=row["remark_"].ToString();
				}
				if(row["status_"]!=null && row["status_"].ToString()!="")
				{
					if((row["status_"].ToString()=="1")||(row["status_"].ToString().ToLower()=="true"))
					{
						model.status_=true;
					}
					else
					{
						model.status_=false;
					}
				}
				if(row["del_flag"]!=null && row["del_flag"].ToString()!="")
				{
					if((row["del_flag"].ToString()=="1")||(row["del_flag"].ToString().ToLower()=="true"))
					{
						model.del_flag=true;
					}
					else
					{
						model.del_flag=false;
					}
				}
				if(row["create_by"]!=null)
				{
					model.create_by=row["create_by"].ToString();
				}
				if(row["create_time"]!=null && row["create_time"].ToString()!="")
				{
					model.create_time=DateTime.Parse(row["create_time"].ToString());
				}
				if(row["update_by"]!=null)
				{
					model.update_by=row["update_by"].ToString();
				}
				if(row["update_time"]!=null && row["update_time"].ToString()!="")
				{
					model.update_time=DateTime.Parse(row["update_time"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id_,customer_id,name_,width_,number_,process_date,process_volume,process_remark,process_number,ratio_,colour_,estimate_quantity,estimate_remark,unit_price,reason_,cloth_price,wages_,roll_length,tag_operator,tag_factor,tag_factor_save,tag_unit,is_integer,remark_,status_,del_flag,create_by,create_time,update_by,update_time ");
			strSql.Append(" FROM base_work ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM base_work a LEFT JOIN base_customer b ON a.customer_id = b.id_ ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperMySQL.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.id_ desc");
			}
			strSql.Append(")AS Row, T.*  from base_work 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 DbHelperMySQL.Query(strSql.ToString());
		}

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(int PageSize, int PageIndex, string strWhere, string orderby)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT a.*,b.name_ AS customer_name FROM base_work a LEFT JOIN base_customer b ON a.customer_id = b.id_ ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append("WHERE " + strWhere);
            }
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("ORDER BY " + orderby);
            }
            strSql.AppendFormat("LIMIT {0} OFFSET {1} ", PageSize, (PageIndex - 1) * PageSize);

            return DbHelperMySQL.Query(strSql.ToString());
        }

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "base_work";
			parameters[1].Value = "id_";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

