using Dapper; using Estsh.Core.Dapper; using Estsh.Core.IRepositories; using Estsh.Core.Model.ExcelModel; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Repository.IRepositories; using System.Collections; using System.Data; using System.Text; /*************************************************************************************************** * * 更新人:sitong.dong * 描述: * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Repositories { /// /// 处理菜单模块的业务数据 /// public class VendorRepository : BaseRepository, IVendorRepository { public VendorRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext) { } #region 成员方法 /// /// 根据传入条件获得菜单列表数据 /// public List getList(string strWhere, string filedOrder) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder strSql = new StringBuilder(); strSql.Append(" select * from dbo.sys_vendor a "); if (strWhere != null && !strWhere.Trim().Equals("")) { strSql.Append(" where " + strWhere); } if (filedOrder != null && !filedOrder.Trim().Equals("")) { strSql.Append(" order by " + filedOrder); } List result = dbConn.Query(strSql.ToString()).ToList(); return result; } } /// /// 根据分页条件获取分页数据列表 /// public Hashtable getListByPage(int PageSize, int PageIndex, string strWhere, string OrderBy) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); Hashtable result = new Hashtable(); DynamicParameters parameters = new DynamicParameters(); parameters.Add("@TotalCount", 0, DbType.Int32, ParameterDirection.Output); parameters.Add("@TotalPage", 0, DbType.Int32, ParameterDirection.Output); parameters.Add("@Table", "dbo.sys_vendor a"); parameters.Add("@Column", "*"); parameters.Add("@OrderColumn", OrderBy); parameters.Add("@GroupColumn", ""); parameters.Add("@PageSize", PageSize); parameters.Add("@CurrentPage", PageIndex); parameters.Add("@Group", 0); parameters.Add("@Condition", strWhere); List dataList = dbConn.Query("Com_Pagination", parameters, commandType: CommandType.StoredProcedure).ToList(); result.Add("dataList", dataList); result.Add("totalCount", parameters.Get("@TotalCount")); return result; } } public SysVendor getVendorByExistName(string vendorCode) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder strSql = new StringBuilder(); strSql.Append("select * from sys_vendor where vendor_code='" + vendorCode + "'"); SysVendor result = dbConn.Query(strSql.ToString()).FirstOrDefault(); return result; } } //清空道口号信息 public int UpdateAllVendorDock() { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder SqlStringBuilder = new StringBuilder(1024); SqlStringBuilder.Append("update sys_vendor set dock=''"); int result = dbConn.Execute(SqlStringBuilder.ToString()); return result; } } //事务批量执行添加、修改 public bool InsertData(List sqlStrings, List parameterList) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { if (dbConn.State == ConnectionState.Closed) { dbConn.Open(); } //执行事务 IDbTransaction transaction = dbConn.BeginTransaction(); if (parameterList == null || parameterList.Count == 0) { try { for (int i = 0; i < sqlStrings.Count; i++) { dbConn.Execute(sqlStrings[i], null, transaction); } transaction.Commit(); return true; } catch (Exception exception) { transaction.Rollback(); return false; } } else { try { for (int i = 0; i < sqlStrings.Count; i++) { dbConn.Execute(sqlStrings[i], parameterList[i], transaction); } transaction.Commit(); return true; } catch (Exception exception) { transaction.Rollback(); return false; } } } } public List ifVendorDock(String vendorCode) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); DynamicParameters htparams = new DynamicParameters(); htparams.Add("@vendorCode", vendorCode); String delStr = "SELECT * FROM dbo.sys_vendor WHERE vendor_code=@vendorCode "; List result = dbConn.Query(delStr, htparams).ToList(); return result; } } /// /// 插入供应商数据 /// /// /// public int saveVendor(SysVendor htParams) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder SqlStringBuilder = new StringBuilder(1024); SqlStringBuilder.Append("INSERT INTO sys_vendor (vendor_code "); SqlStringBuilder.Append(" , vendor_name "); SqlStringBuilder.Append(" ,vendor_tel "); SqlStringBuilder.Append(" , vendor_addr "); SqlStringBuilder.Append(" ,vendor_fax "); SqlStringBuilder.Append(" , vendor_mtel "); SqlStringBuilder.Append(" ,vendor_mail "); SqlStringBuilder.Append(" , vendor_sale "); SqlStringBuilder.Append(" ,vendor_pwd "); SqlStringBuilder.Append(" ,dock "); SqlStringBuilder.Append(" ,factory_id "); SqlStringBuilder.Append(" , factory_code "); SqlStringBuilder.Append(" ,enabled "); SqlStringBuilder.Append(" , create_userid "); SqlStringBuilder.Append(" , create_time )"); SqlStringBuilder.Append(" VALUES(@vendorCode "); SqlStringBuilder.Append(" , @vendorName "); SqlStringBuilder.Append(" ,@vendorTel"); SqlStringBuilder.Append(" , @vendorAddr "); SqlStringBuilder.Append(" ,@vendorFax"); SqlStringBuilder.Append(" , @vendorMtel "); SqlStringBuilder.Append(" ,@vendorMail"); SqlStringBuilder.Append(" , @vendorSale "); SqlStringBuilder.Append(" ,@vendorPwd"); SqlStringBuilder.Append(" ,@dock"); SqlStringBuilder.Append(" ,@factoryId "); SqlStringBuilder.Append(" ,@factoryCode "); SqlStringBuilder.Append(" ,'Y' "); SqlStringBuilder.Append(" , @createUserid "); SqlStringBuilder.Append(" , CONVERT(varchar(50), GETDATE(), 21)"); SqlStringBuilder.Append(" ) "); int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams); return result; } } /// /// 更新菜单数据 /// /// /// public int updateVendor(SysVendor htParams) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder SqlStringBuilder = new StringBuilder(1024); SqlStringBuilder.Append("update sys_vendor "); SqlStringBuilder.Append("SET vendor_code=@vendorCode "); SqlStringBuilder.Append(" , vendor_name=@vendorName "); SqlStringBuilder.Append(" , vendor_tel=@vendorTel "); SqlStringBuilder.Append(" , vendor_addr=@vendorAddr "); SqlStringBuilder.Append(" , vendor_fax=@vendorFax "); SqlStringBuilder.Append(" , vendor_mtel=@vendorMtel "); SqlStringBuilder.Append(" , vendor_mail=@vendorMail "); SqlStringBuilder.Append(" , vendor_sale=@vendorSale "); SqlStringBuilder.Append(" , vendor_pwd=@vendorPwd "); SqlStringBuilder.Append(" , dock=@dock "); SqlStringBuilder.Append(" , factory_id=@factoryId "); SqlStringBuilder.Append(" , factory_code=@factoryCode "); SqlStringBuilder.Append(" , update_userid=@updateUserid "); SqlStringBuilder.Append(" , update_time=CONVERT(varchar(50), GETDATE(), 21)"); SqlStringBuilder.Append("WHERE vendor_id=@vendorId "); int result = dbConn.Execute(SqlStringBuilder.ToString(), htParams); return result; } } /// /// 删除菜单数据 /// /// /// public int deleteVendor(String vendor_id) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); DynamicParameters htparams = new DynamicParameters(); htparams.Add("@vendor_id", vendor_id); String delStr = "update sys_vendor set Enabled='N' where vendor_id = @vendor_id"; int result = dbConn.Execute(delStr, htparams); return result; } } /// /// 获取下拉框菜单数据 /// /// public List getSelectVendor() { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder strSql = new StringBuilder(); strSql.Append("select part_id as [value] ,part_no as [key] from sys_part where part_type = '1' and enabled='Y' "); List result = dbConn.Query(strSql.ToString()).ToList(); return result; } } //启用 public int EnableVendor(String vendorId) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); String delStr = "update sys_vendor set Enabled='Y' WHERE vendor_id = @vendorId"; DynamicParameters htparams = new DynamicParameters(); htparams.Add("@vendorId", vendorId); int result = dbConn.Execute(delStr, htparams); return result; } } //禁用 public int DisableVendor(String vendorId) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); String delStr = "update sys_vendor set Enabled='N' WHERE vendor_id = @vendorId"; DynamicParameters htparams = new DynamicParameters(); htparams.Add("@vendorId", vendorId); int result = dbConn.Execute(delStr, htparams); return result; } } public List getExportList(string strWhere, string orderBy) { using (IDbConnection dbConn = dapperDbContext.GetDbConnection()) { dbConn.Open(); StringBuilder strSql = new StringBuilder(); strSql.Append("select * from sys_vendor where " + strWhere + orderBy); List result = dbConn.Query(strSql.ToString()).ToList(); return result; } } #endregion 成员方法 } }