diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs
index 4aeeac5..7cb3c49 100644
--- a/DM_Weight/App.xaml.cs
+++ b/DM_Weight/App.xaml.cs
@@ -311,11 +311,11 @@ namespace DM_Weight
private void PrismApplication_Startup(object sender, StartupEventArgs e)
{
// 配置数据库信息
- SCHelper.Database.DBHelper.GetInstance().SetConnectionConfig(SCHelper.Database.SCDbType.MySQL,
- "127.0.0.1",
- "hunanxianchang_db",
- "root",
- "root");
+ //SCHelper.Database.DBHelper.GetInstance().SetConnectionConfig(SCHelper.Database.SCDbType.MySQL,
+ //"127.0.0.1",
+ //"hunanxianchang_db",
+ //"root",
+ //"root");
//获取欲启动程序名
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
//检查程序是否已经启动,已经启动则显示提示退出程序
diff --git a/DM_Weight/Models/CheckRecordStockSqlSugar.cs b/DM_Weight/Models/CheckRecordStockSqlSugar.cs
new file mode 100644
index 0000000..31ba787
--- /dev/null
+++ b/DM_Weight/Models/CheckRecordStockSqlSugar.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+
+namespace DM_Weight.Models
+{
+ ///
+ /// 盘点后药品库存数
+ ///
+ [SugarTable("check_stock")]
+ public class CheckRecordStockSqlSugar
+ {
+ [SugarColumn(ColumnName ="id",IsPrimaryKey = true)]
+ public int ID { get; set; }
+ ///
+ /// 抽屉号
+ ///
+ [SugarColumn(ColumnName = "drawer_no")]
+ public int rowNo { get; set; }
+ ///
+ /// 列号
+ ///
+ [SugarColumn(ColumnName = "col_no")]
+ public int colNo { get; set; }
+ ///
+ /// 数量
+ ///
+ [SugarColumn(ColumnName = "quantity")]
+ public int quantity { get; set; }
+ ///
+ /// 批次
+ ///
+ [SugarColumn(ColumnName = "manu_no")]
+ public string manuNo { get; set; }
+ ///
+ /// 效期
+ ///
+ [SugarColumn(ColumnName = "eff_date")]
+ public string effDate { get; set; }
+ ///
+ /// 药品名称
+ ///
+ [SugarColumn(IsIgnore =true)]
+ public string drugName { get; set; }
+ ///
+ /// 规格
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string drugSpec { get; set; }
+ //
+ [SugarColumn(IsIgnore = true)]
+ public string packUnit { get; set; }
+ ///
+ /// 厂商
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string manufactory { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public int maxStock { get; set; }
+ [SugarColumn(ColumnName = "drug_id")]
+ public string drugId { get; set; }
+ [SugarColumn(ColumnName = "machine_id")]
+ public string MachineId { get; set; }
+ ///
+ /// 批次总库存
+ ///
+ [SugarColumn(ColumnName = "check_quantity")]
+ public int ManuQuantity { get; set; }
+ ///
+ /// 操作时间
+ ///
+ [SugarColumn(ColumnName = "check_time")]
+ public string optdate { get; set; }
+ ///
+ /// 操作人
+ ///
+ [SugarColumn(ColumnName = "operator")]
+ public string operatorUser { get; set; }
+ ///
+ /// 审核人
+ ///
+ [SugarColumn(ColumnName = "reviewer")]
+ public string reviewerUser { get; set; }
+
+ public List manuNoDetails { get;set; }
+
+ [Navigate(NavigateType.OneToOne, nameof(drugId))]
+ public DrugInfo DrugInfo { get; set; }
+ }
+}
diff --git a/DM_Weight/Services/SqlHelperService.cs b/DM_Weight/Services/SqlHelperService.cs
index 89944f4..1b0cc42 100644
--- a/DM_Weight/Services/SqlHelperService.cs
+++ b/DM_Weight/Services/SqlHelperService.cs
@@ -1291,8 +1291,8 @@ namespace DM_Weight.Services
totalCount = 0;
PageNum = (PageNum - 1) * PageSize;
string countSql = $@"SELECT Count(1) FROM (SELECT count(1) as Count, i.InvoiceNo, i.InvoiceDate, sum(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name PharmacyName2 from
- (SELECT drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(quantity) as quantity
- FROM in_out_invoice where status=0 and type!=2 and cancel_flag=0 GROUP BY invoice_no,drug_id) i
+ (SELECT inOutI.drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(if(inOutI.units=di.small_unit,quantity,quantity*convert_ratio)) as quantity
+ FROM in_out_invoice inOuti inner join drug_info di on inOutI.drug_id=di.Drug_ID where status=0 and type!=2 and cancel_flag=0 GROUP BY invoice_no,drug_id) i
inner join ( select c.drug_id as drug_id from channel_list c where c.machine_id = '{machine_id}' group by c.drug_id ) di on di.drug_id = i.drug_id
left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id
left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id where 1=1";
@@ -1324,8 +1324,8 @@ namespace DM_Weight.Services
var sb = new StringBuilder();
sb.Append("SELECT Count,InvoiceNo,InvoiceDate,quantity,PharmacyName1,PharmacyName2 FROM (SELECT count(1) as Count, i.InvoiceNo, i.InvoiceDate, sum(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name PharmacyName2 from ");
- sb.Append(" (SELECT drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(quantity) as quantity ");
- sb.Append(" FROM in_out_invoice where status=0 and type!=2 and cancel_flag=0 GROUP BY invoice_no,drug_id) i ");
+ sb.Append(" (SELECT inOutI.drug_id,in_pharmacy_id,out_pharmacy_id, invoice_no as InvoiceNo, DATE_FORMAT(Invoice_Date,'%Y-%m-%d') as InvoiceDate, SUM(if(inOutI.units=di.small_unit,quantity,quantity*convert_ratio)) as quantity ");
+ sb.Append(" FROM in_out_invoice inOuti inner join drug_info di on inOutI.drug_id=di.Drug_ID where status=0 and type!=2 and cancel_flag=0 GROUP BY invoice_no,drug_id) i ");
sb.Append($" inner join ( select c.drug_id as drug_id from channel_list c where c.machine_id = '{machine_id}' group by c.drug_id ) di on di.drug_id = i.drug_id");
sb.Append(" left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id");
sb.Append(" left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id where 1=1");
@@ -1498,9 +1498,10 @@ namespace DM_Weight.Services
con.Open();
try
{
- string sql = $@"SELECT id,in_pharmacy_id,out_pharmacy_id,storage,invoice_no,invoice_date,drug_id,drug_spec,
- quantity,drug_manu_no,supplier,operator,drug_eff_date FROM in_out_invoice WHERE ((((( invoice_no = '{invoiceNo}' )
- AND ( drug_id = '{drugId}' )) AND ( status = 0 )) AND ( type <> 2 )) AND ( cancel_flag = 0 ))";
+ string sql = $@"SELECT inOutI.id,inOutI.in_pharmacy_id,inOutI.out_pharmacy_id,inOutI.storage,inOutI.invoice_no,inOutI.invoice_date,inOutI.drug_id,inOutI.drug_spec,
+ if(inOuti.units=di.small_unit,quantity,quantity*convert_ratio) as quantity,inOutI.drug_manu_no,inOutI.supplier,inOutI.operator,inOutI.drug_eff_date
+ FROM in_out_invoice inOutI inner join drug_info di on inOutI.drug_id=di.Drug_ID WHERE ((((( inOutI.invoice_no = '{invoiceNo}' )
+ AND ( inOutI.drug_id = '{drugId}' )) AND ( inOutI.status = 0 )) AND ( inOutI.type <> 2 )) AND ( inOutI.cancel_flag = 0 ))";
DataSet ds = new DataSet();
MySqlDataAdapter sda = new MySqlDataAdapter(sql, con);
sda.Fill(ds);
@@ -1639,6 +1640,7 @@ namespace DM_Weight.Services
MySqlTransaction transaction = con.BeginTransaction();
try
{
+ logger.Info("保存——调拨入库");
string InvoiceNo = SelectedInvoice.InvoiceNo;
string strSql = $@"UPDATE in_out_invoice SET STATUS=1 WHERE invoice_no='{InvoiceNo}'";
MySqlCommand cmd = new MySqlCommand();
@@ -1659,6 +1661,10 @@ namespace DM_Weight.Services
{
logger.Info($"channel_stock未更新数据{updateSql}");
}
+ else
+ {
+ logger.Info($"channel_stock更新数据{updateSql}");
+ }
}
else
{
@@ -1684,6 +1690,10 @@ namespace DM_Weight.Services
{
logger.Info($"SaveInvoiceIn未更新数据{uSql}");
}
+ else
+ {
+ logger.Info($"SaveInvoiceIn更新数据{uSql}");
+ }
}
else
{
@@ -1697,6 +1707,10 @@ namespace DM_Weight.Services
{
logger.Info($"SaveInvoiceIn未新增数据——{insertSql}");
}
+ else
+ {
+ logger.Info($"SaveInvoiceIn新增数据——{insertSql}");
+ }
}
}
// 获取更新完库存后的药品库存
@@ -1729,18 +1743,25 @@ namespace DM_Weight.Services
{
logger.Info($"SaveInvoiceIn-dm_machine_record未新增数据——{iSql}");
}
- //根据ChannelLsts中的库位,删除该库位库存为0的记录
-
- string delSql = $@"DELETE FROM channel_stock WHERE MACHINE_ID='{machine_id}' AND QUANTITY<=0";
- cmd.CommandText = delSql;
- iResult = cmd.ExecuteNonQuery();
- if (iResult <= 0)
+ else
{
- logger.Info($"SaveInvoiceIn-删除未执行任何数据——{delSql}");
+ logger.Info($"SaveInvoiceIn-dm_machine_record新增数据——{iSql}");
}
}
bResult = true;
transaction.Commit();
+ //根据ChannelLsts中的库位,删除该库位库存为0的记录
+ string delSql = $@"DELETE FROM channel_stock WHERE MACHINE_ID='{machine_id}' AND QUANTITY<=0";
+ cmd.CommandText = delSql;
+ iResult = cmd.ExecuteNonQuery();
+ if (iResult <= 0)
+ {
+ logger.Info($"SaveInvoiceIn-删除未执行任何数据——{delSql}");
+ }
+ else
+ {
+ logger.Info($"SaveInvoiceIn-删除执行sql——{delSql}");
+ }
}
catch (Exception ex)
{
@@ -1995,7 +2016,7 @@ namespace DM_Weight.Services
logger.Info($"批号重复不让添加{it.DrawerType}-{it.ManuNo}-{machine_id}");
continue;
}
- string chnguid = it.Chnguid==null ? it.ChannelLst.Id : it.Chnguid;
+ string chnguid = it.Chnguid == null ? it.ChannelLst.Id : it.Chnguid;
//更新数据 库存信息
string insertSql = $@"INSERT INTO channel_stock(QUANTITY,CHNGUID,MANU_NO,EFF_DATE,ROW_NO,COL_NO,DRUG_ID,DRAWER_TYPE,BOARD_TYPE,CHSGUID,MACHINE_ID)
VALUES({it.AddQuantity},'{chnguid}','{it.ManuNo}','{it.EffDate}',{it.DrawerNo},{it.ColNo},'{it.DrugId}','{it.DrawerType}','{it.BoardType}','{Guid.NewGuid().ToString()}','{machine_id}')";
@@ -3063,6 +3084,7 @@ namespace DM_Weight.Services
transaction.Commit();
bFlag = true;
+ logger.Info($"解绑药品完成CHNGUID:{chnguid}");
}
catch (Exception ex)
{
@@ -3400,8 +3422,8 @@ namespace DM_Weight.Services
// 保存数据 盘点后药品总库存及批次库存数
string insertCheckRecordStockSql = $@"INSERT INTO check_stock(row_no,COL_NO,QUANTITY,MANU_NO,EFF_DATE,DRUG_NAME,DRUG_SPEC,PACK_UNIT,MANUFACTORY,MAX_STOCK,
DRUG_ID,MACHINE_ID,MANUqUANTITY,OPTDATE,OPERATOR,REVIEWER)
- VALUES({cStock.rowNo},{cStock.colNo},{manuQuantiy},'{cStock.manuNo}','{cStock.effDate}','{cStock.drugName}','{cStock.manufactory}','{cStock.drugSpec}','{cStock.packUnit}',
- {cStock.maxStock},'{cStock.drugId}','{cStock.MachineId}',{quantity},'{DateTime.Now.ToString()}','{operatorUser}','{reviewerUser}')";
+ VALUES({cStock.rowNo},{cStock.colNo},{quantity},'{cStock.manuNo}','{cStock.effDate}','{cStock.drugName}','{cStock.manufactory}','{cStock.drugSpec}','{cStock.packUnit}',
+ {cStock.maxStock},'{cStock.drugId}','{cStock.MachineId}',{manuQuantiy},'{DateTime.Now.ToString()}','{operatorUser}','{reviewerUser}')";
cmd.CommandText = insertCheckRecordStockSql;
int iResult = cmd.ExecuteNonQuery();
if (iResult <= 0)
@@ -3560,7 +3582,7 @@ namespace DM_Weight.Services
string strSql = $@"SELECT CKS.ID,CKS.ROW_NO,CKS.COL_NO,CKS.QUANTITY,CKS.MANU_NO,CKS.EFF_DATE,CKS.DRUG_NAME,CKS.DRUG_SPEC,CKS.PACK_UNIT,CKS.MANUFACTORY,CKS.MAX_STOCK,CKS.DRUG_ID,CKS.MACHINE_ID,
CKS.MANUQUANTITY,CKS.OPTDATE,CKS.OPERATOR,CKS.REVIEWER,
DI.PY_CODE,DI.DRUG_BARCODE,DI.DRUG_BRAND_NAME,DI.DRUG_SPEC,DI.MANUFACTORY
- FROM check_stock CKS INNER JOIN DRUG_INFO DI ON CKS.DRUG_ID=DI.DRUG_ID WHERE optdate='{optDate}'";
+ FROM check_stock CKS INNER JOIN DRUG_INFO DI ON CKS.DRUG_ID=DI.DRUG_ID WHERE optdate='{optDate}' ORDER BY CKS.DRUG_ID";
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(strSql, con);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs
index a859194..f1b2962 100644
--- a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs
+++ b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs
@@ -510,6 +510,7 @@ namespace DM_Weight.ViewModels
return;
}
+ logger.Info($"解绑药品{item.DrugId}");
item.DrugId = null;
//item.ManuNo = null;
//item.EffDate = null;
diff --git a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs
index ba30c2f..cfcea75 100644
--- a/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs
+++ b/DM_Weight/ViewModels/InvoiceInNewWindowViewModel.cs
@@ -553,113 +553,6 @@ namespace DM_Weight.ViewModels
_isFinishClick = true;
List record = ChannelStocks.Where(cs => cs.AddQuantity > 0).ToList();
string InvoiceId = SelectedInvoice.InvoiceNo;
- //var f = SqlSugarHelper.Db.UseTran(() =>
- //{
- // SqlSugarHelper.Db.Updateable(new InOutInvoice()
- // {
- // Status = 1,
- // InvoiceNo = SelectedInvoice.InvoiceNo
- // }).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo }).ExecuteCommand();
-
- // for (int i = 0; i < record.Count; i++)
- // {
-
-
- // ChannelStock it = record[i];
- // if (it.BoardType == 6 && it.PosNo == 0)
- // {
- // _portUtil.SetNumCount(it.DrawerNo, it.ColNo, it.AddQuantity);
- // }
- // if (it.Id != null)
- // {
- // // 更新数据 库存信息
- // SqlSugarHelper.Db.Updateable(new ChannelStock()
- // {
- // Quantity = it.Quantity + it.AddQuantity,
- // ManuNo = it.ManuNo,
- // EffDate = it.EffDate,
- // Id = it.Id,
- // }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand();
- // }
- // else
- // {
- // //如果批号重复则不让添加
- // List csCount = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.ManuNo == it.ManuNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity > 0).ToList();
- // if (csCount.Count > 0)
- // {
- // //repeatList.Add(it.ManuNo);
- // //stockRepeats.Add(it);
- // continue;
- // }
- // //查询现有库位中是否有库存为0的记录,如果有直接update
- // ChannelStock recordHistory = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrawerNo == it.DrawerNo && cs.ColNo == it.ColNo && cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1") && cs.Quantity <= 0).First();
- // if (recordHistory != null && recordHistory.Id != null)
- // {
- // SqlSugarHelper.Db.Updateable().SetColumns(item => new ChannelStock()
- // {
- // Quantity = it.AddQuantity,
- // ManuNo = it.ManuNo,
- // EffDate = it.EffDate
- // }).Where(item => item.Id == recordHistory.Id).ExecuteCommand();
- // }
- // else
- // {
- // // 更新数据 库存信息
- // SqlSugarHelper.Db.Insertable(new ChannelStock()
- // {
- // Quantity = it.AddQuantity,
- // Chnguid = it.Chnguid,
- // ManuNo = it.ManuNo,
- // EffDate = it.EffDate,
- // DrawerNo = it.DrawerNo,
- // ColNo = it.ColNo,
- // DrugId = it.DrugId,
- // DrawerType = it.DrawerType,
- // BoardType = it.BoardType,
- // Id = Guid.NewGuid().ToString(),
- // MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"
- // }).ExecuteCommand();
- // }
- // }
- // // 获取更新完库存后的药品库存
- // List nowChannels = SqlSugarHelper.Db.Queryable()
- // .Where(cs => cs.MachineId.Equals(it.MachineId))
- // .Where(cs => cs.DrugId.Equals(it.DrugId))
- // .Where(cs => cs.DrawerType == 1)
- // .ToList();
-
- // // 保存数据 出/入库记录
- // SqlSugarHelper.Db.Insertable(new MachineRecord()
- // {
- // MachineId = it.MachineId,
- // DrawerNo = it.DrawerNo,
- // ColNo = it.ColNo,
- // DrugId = it.DrugId,
- // ManuNo = it.ManuNo,
- // EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
- // Operator = HomeWindowViewModel.Operator?.Id,
- // Reviewer = HomeWindowViewModel.Reviewer?.Id,
- // OperationTime = DateTime.Now,
- // Quantity = it.AddQuantity,
- // Type = 1,
- // InvoiceId = InvoiceId,
- // StockQuantity = nowChannels.Sum(it => it.Quantity),
- // ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity),
- // SupplierDept = SelectedInvoice.PharmacyName1 ?? ConfigurationManager.AppSettings["supplierDept"].ToString(),
- // ReceiveDept = SelectedInvoice.PharmacyName2 ?? ConfigurationManager.AppSettings["receiveDept"].ToString()
- // }).ExecuteCommand();
- // }
- // if (ChannelLsts != null && ChannelLsts.Count > 0)
- // {
- // for (int i = 0; i < ChannelLsts.Count; i++)
- // {
- // //根据ChannelLsts中的库位,删除该库位库存为0的记录
- // SqlSugarHelper.Db.Deleteable()
- // .Where(cs => cs.Quantity <= 0 && cs.DrugId == ChannelLsts[i].DrugId && cs.MachineId == ChannelLsts[i].MachineId).ExecuteCommand();
- // }
- // }
- // return true;
- //});
bool bFlag = _mysqlHelper.SaveInvoiceIn(record, SelectedInvoice);
if (bFlag)
{