98 lines
2.7 KiB
C#
98 lines
2.7 KiB
C#
using Dapper;
|
|
using dccdc.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace dccdc.DAL
|
|
{
|
|
public class BarCodeMaintainDal
|
|
{
|
|
|
|
/// <summary>
|
|
/// 根据id获取条码列表
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public List<BarCodeMaintainModel> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and id=@id";
|
|
}
|
|
return conn.Query<BarCodeMaintainModel>("select * from bar_code_maintain where 1=1 " + param + " order by id desc", new { @id = id}).ToList();
|
|
}
|
|
}
|
|
|
|
public bool Add(BarCodeMaintainModel model)
|
|
{
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"INSERT INTO [bar_code_maintain]
|
|
([code_name]
|
|
,[is_print]
|
|
,[status]
|
|
,[creator]
|
|
,[create_time])
|
|
VALUES
|
|
(@code_name
|
|
,@is_print
|
|
,@status
|
|
,@creator
|
|
,@create_time)";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
|
|
public bool Update(BarCodeMaintainModel model)
|
|
{
|
|
string sql = @"UPDATE [bar_code_maintain]
|
|
SET [code_name] = @code_name
|
|
WHERE id=@id
|
|
";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id删除条码
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public object del(string id)
|
|
{
|
|
string sql = @"delete bar_code_maintain where id=@id";
|
|
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
try
|
|
{
|
|
int c = conn.Execute(sql, new { id = id });
|
|
if (c > 0)
|
|
{
|
|
return new { State = 1, Message = "操作成功!" };
|
|
}
|
|
else
|
|
{
|
|
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { State = 0, Message = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|