using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace DrugManagement.DAL { public class MedicamentPriceDB { public bool Exists(int Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select count(1) from MedicamentPrice where Id="+Id+"" ); return HelperDB.DbHelperSQL.Exists(strSql.ToString()); } public void Add(Model.MedicamentPrice MedicamentPriceObj) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into [MedicamentPrice]("); strSql.Append("DrugManufacturerId,MedicalItemId,PurchasePrice,TradePrice,RetailPrice,IsValid,OperatorNo,OperatorName,OperateDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(""+MedicamentPriceObj.DrugManufacturerId+","); strSql.Append(""+MedicamentPriceObj.MedicalItemId+","); strSql.Append(""+MedicamentPriceObj.PurchasePrice+","); strSql.Append(""+MedicamentPriceObj.TradePrice+","); strSql.Append(""+MedicamentPriceObj.RetailPrice+","); strSql.Append(""+MedicamentPriceObj.IsValid+","); strSql.Append("'"+MedicamentPriceObj.OperatorNo+"',"); strSql.Append("'"+MedicamentPriceObj.OperatorName+"',"); strSql.Append("'"+MedicamentPriceObj.OperateDate+"'"); strSql.Append(")"); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public void Update(Model.MedicamentPrice MedicamentPricObj) { StringBuilder strSql=new StringBuilder(); strSql.Append("update MedicamentPrice set "); strSql.Append("IsValid="+MedicamentPricObj.IsValid+","); strSql.Append("OperatorNo='"+MedicamentPricObj.OperatorNo+"',"); strSql.Append("OperatorName='"+MedicamentPricObj.OperatorName+"',"); strSql.Append("OperateDate='"+MedicamentPricObj.OperateDate+"'"); strSql.Append(" where Id="+MedicamentPricObj.Id+" "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public Model.MedicamentPrice GetModel(int Id) { Model.MedicamentPrice MedicamentPriceObj = new Model.MedicamentPrice(); StringBuilder strSql=new StringBuilder(); strSql.Append("select "); strSql.Append("Id,DrugManufacturerId,MedicalItemId,PurchasePrice,TradePrice,RetailPrice,IsValid,OperatorNo,OperatorName,OperateDate "); strSql.Append(" from MedicamentPrice "); strSql.Append(" where Id="+Id+"" ); DataSet ds = HelperDB.DbHelperSQL.GetDataSet(strSql.ToString()); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["Id"].ToString()!="") { MedicamentPriceObj.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if(ds.Tables[0].Rows[0]["DrugManufacturerId"].ToString()!="") { MedicamentPriceObj.DrugManufacturerId = int.Parse(ds.Tables[0].Rows[0]["DrugManufacturerId"].ToString()); } if(ds.Tables[0].Rows[0]["MedicalItemId"].ToString()!="") { MedicamentPriceObj.MedicalItemId = int.Parse(ds.Tables[0].Rows[0]["MedicalItemId"].ToString()); } if(ds.Tables[0].Rows[0]["PurchasePrice"].ToString()!="") { MedicamentPriceObj.PurchasePrice = decimal.Parse(ds.Tables[0].Rows[0]["PurchasePrice"].ToString()); } if(ds.Tables[0].Rows[0]["TradePrice"].ToString()!="") { MedicamentPriceObj.TradePrice = decimal.Parse(ds.Tables[0].Rows[0]["TradePrice"].ToString()); } if(ds.Tables[0].Rows[0]["RetailPrice"].ToString()!="") { MedicamentPriceObj.RetailPrice = decimal.Parse(ds.Tables[0].Rows[0]["RetailPrice"].ToString()); } if(ds.Tables[0].Rows[0]["IsValid"].ToString()!="") { MedicamentPriceObj.IsValid = int.Parse(ds.Tables[0].Rows[0]["IsValid"].ToString()); } MedicamentPriceObj.OperatorNo = ds.Tables[0].Rows[0]["OperatorNo"].ToString(); MedicamentPriceObj.OperatorName = ds.Tables[0].Rows[0]["OperatorName"].ToString(); if(ds.Tables[0].Rows[0]["OperateDate"].ToString()!="") { MedicamentPriceObj.OperateDate = DateTime.Parse(ds.Tables[0].Rows[0]["OperateDate"].ToString()); } } return MedicamentPriceObj; } public DataTable GetDataTable(int MedicalItemId) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT mp.Id, mi.No,mi.Name,dm.Name AS DrugManufacturerName,mp.PurchasePrice, mp.TradePrice, mp.RetailPrice, CASE mp.IsValid WHEN 1 THEN '有效' WHEN 0 THEN '无效' END AS IsValid "); strSql.Append("FROM MedicamentPrice mp "); strSql.Append("LEFT JOIN DrugManufacturer dm ON dm.Id =mp.DrugManufacturerId "); strSql.Append("LEFT JOIN MedicalItem mi ON mi.Id = mp.MedicalItemId WHERE MedicalItemId =" + MedicalItemId + " "); return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } } }