添加项目文件。
This commit is contained in:
parent
4173739d28
commit
a573db6b33
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.33403.182
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateAccountBookConsole", "CreateAccountBookConsole\CreateAccountBookConsole.csproj", "{6BADF332-E903-457C-A9DB-9201506B8722}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Debug|x64.Build.0 = Debug|x64
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Release|x64.ActiveCfg = Release|x64
|
||||
{6BADF332-E903-457C-A9DB-9201506B8722}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5499F1B6-15BC-4D80-8709-65DC9AF0D558}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<connectionStrings>
|
||||
<add name="dbConnect" connectionString="server=127.0.0.1;user id=root;password=root;database=xiangtan_mazuike_xx;Convert Zero Datetime=True;Allow Zero Datetime=True;Charset=utf8" />
|
||||
</connectionStrings>
|
||||
<appSettings>
|
||||
<!-- 设备id -->
|
||||
<add key="machineId" value="DM3" />
|
||||
<!--2023/7/13 药房代码 有则写无则空 -->
|
||||
<add key="storage" value="552" />
|
||||
</appSettings>
|
||||
</configuration>
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentScheduler" Version="5.5.1" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.7" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CreateAccountBookConsole.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 日结存、总结存表
|
||||
/// </summary>
|
||||
public class AccountBookG2
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int DrugId { get; set; }
|
||||
public int Type { get; set; }
|
||||
public string Department { get;set; }
|
||||
public string InvoiceNo { get; set; }
|
||||
public string OrderNo { get; set; }
|
||||
public string ManuNo { get; set; }
|
||||
public string EffDate { get; set;}
|
||||
public int YesterDayQuantity { get; set; }
|
||||
public int AddQuantity { get; set; }
|
||||
public int OutQuantity { get; set; }
|
||||
public int ManuStock { get; set; }
|
||||
public int TotalStock { get; set; }
|
||||
public int UserId1 { get; set; }
|
||||
public int UserId2 { get; set;}
|
||||
public string MachineId { get; set; }
|
||||
public string CreateDate { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CreateAccountBookConsole.Models
|
||||
{
|
||||
public class ChannelStock
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Chnguid { get; set; }
|
||||
public string MachineId { get; set; }
|
||||
public int RowNo { get; set; }
|
||||
public int ColNo { get; set; }
|
||||
public int PosNo { get;set; }
|
||||
public string DrugId { get; set; }
|
||||
public string ManuNO { get;set; }
|
||||
public string EffDate { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public int DrawerType { get; set; }
|
||||
public int BoardType { get; set; }
|
||||
|
||||
public int ManuNoQuantity { get; set; }
|
||||
public int TotalQuantity { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CreateAccountBookConsole.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 专用账册
|
||||
/// </summary>
|
||||
public class SpecialAccountBook
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string YearDM { get; set; }
|
||||
public string ManuNo { get; set; }
|
||||
public string EffDate { get; set; }
|
||||
public int BeforeQuantity { get; set; }
|
||||
public int InQuantity { get; set; }
|
||||
public int TotalQuantity { get; set; }
|
||||
public string DrawerNo { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public string PharmacyUser { get; set; }
|
||||
public string InPharmacy { get; set; }
|
||||
public string OperatorUser { get; set; }
|
||||
public string OperatorCheck { get;set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using CreateAccountBookConsole;
|
||||
using CreateAccountBookConsole.Models;
|
||||
using FluentScheduler;
|
||||
using MySqlConnector;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
JobManager.Initialize();
|
||||
|
||||
//JobManager.AddJob(
|
||||
// () => Console.WriteLine($"{DateTime.Now}1 minutes just passed."),
|
||||
// s => s.ToRunEvery(1).Minutes()
|
||||
//);
|
||||
|
||||
Console.WriteLine("定时系统已启动");
|
||||
//湘潭急诊DM1设备每天凌晨生成当日结存数据及总结存数据
|
||||
JobManager.AddJob(() => CreateClass.CreateMethod(), s => s.ToRunEvery(1).Days().At(00, 00));
|
||||
//湘潭手术室DM3设备每天凌晨生成当日结存数据
|
||||
JobManager.AddJob(() => CreateClass.CreateMethodForSSS(), s => s.ToRunEvery(1).Days().At(00, 00));
|
||||
//JobManager.JobStart += info =>
|
||||
//{
|
||||
// Console.WriteLine($"{DateTime.Now}定时任务开始执行");
|
||||
//};
|
||||
//JobManager.JobEnd += info =>
|
||||
//{
|
||||
// Console.WriteLine($"{DateTime.Now}定时任务执行结束");
|
||||
//};
|
||||
|
||||
//CreateClass.CreateMethodForSSS();
|
||||
Console.ReadLine();
|
||||
|
||||
public class CreateClass
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成日结存及总结存数据
|
||||
/// </summary>
|
||||
public static void CreateMethod()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
if (conn.State != ConnectionState.Open)
|
||||
conn.Open();
|
||||
MySqlTransaction transaction = conn.BeginTransaction();
|
||||
try
|
||||
{
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.Transaction = transaction;
|
||||
//1)查询库存,为每一个批次的药品生成日结存数据
|
||||
string sql = $@"SELECT machine_id,drug_id,manu_no,eff_date,sum(quantity) manuQuantity,(SELECT sum(quantity) from channel_stock tCS WHERE MACHINE_ID='DM1' and drawer_type=1 and quantity>0 and tCS.drug_id=bCS.drug_id) totalQuantity
|
||||
FROM channel_stock bCS
|
||||
WHERE MACHINE_ID='DM1' and drawer_type=1 and quantity>0 GROUP BY drug_id,manu_no,eff_date";
|
||||
DataSet dsQuantity = SqlHelper.ExecuteQuery(sql);
|
||||
if (dsQuantity != null && dsQuantity.Tables[0] != null && dsQuantity.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < dsQuantity.Tables[0].Rows.Count; i++)
|
||||
{
|
||||
|
||||
|
||||
string insertSpecial = $@"INSERT INTO account_book_g2(DRUG_ID,TYPE,DEPARTMENT,INVOICE_NO,MANU_NO,eff_date,add_quantity,out_quantity,manu_stock,total_stock,machine_id,create_date)
|
||||
values('{dsQuantity.Tables[0].Rows[i]["drug_id"].ToString()}',3,'急诊药房','日结','{dsQuantity.Tables[0].Rows[i]["manu_no"].ToString()}',
|
||||
'{dsQuantity.Tables[0].Rows[i]["eff_date"].ToString()}',0,0,'{dsQuantity.Tables[0].Rows[i]["manuQuantity"].ToString()}','{dsQuantity.Tables[0].Rows[i]["totalQuantity"].ToString()}','{dsQuantity.Tables[0].Rows[i]["machine_id"].ToString()}','{DateTime.Now.ToString("yyyy-MM-dd")}')";
|
||||
cmd.CommandText = insertSpecial;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
}
|
||||
transaction.Commit();
|
||||
Console.WriteLine($"{DateTime.Now}生成账册成功");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Console.WriteLine($"{DateTime.Now}生账册失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine($"{DateTime.Now}专用账册生成失败:{ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成日结存及总结存数据
|
||||
/// </summary>
|
||||
public static void CreateMethodForSSS()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
if (conn.State != ConnectionState.Open)
|
||||
conn.Open();
|
||||
MySqlTransaction transaction = conn.BeginTransaction();
|
||||
try
|
||||
{
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.Transaction = transaction;
|
||||
//1)查询库存,为每一个批次的药品生成日结存数据
|
||||
string sql = $@"SELECT machine_id,drug_id,manu_no,eff_date,IF(sum(quantity) IS null,0,sum(quantity)) manuQuantity,(SELECT IF(sum(quantity)is NULL,0,sum(quantity)) from channel_stock tCS WHERE MACHINE_ID in('DM3','DM5') and drawer_type=1 and quantity>0 and tCS.drug_id=bCS.drug_id) totalQuantity
|
||||
FROM channel_stock bCS
|
||||
WHERE MACHINE_ID in('DM1','DM5') and drawer_type=1 and quantity>0 GROUP BY drug_id,manu_no,eff_date";
|
||||
DataSet dsQuantity = SqlHelper.ExecuteQuery(sql);
|
||||
if (dsQuantity != null && dsQuantity.Tables[0] != null && dsQuantity.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < dsQuantity.Tables[0].Rows.Count; i++)
|
||||
{
|
||||
|
||||
|
||||
string insertSpecial = $@"INSERT INTO account_book_g2(DRUG_ID,TYPE,DEPARTMENT,INVOICE_NO,MANU_NO,eff_date,add_quantity,out_quantity,manu_stock,total_stock,machine_id,create_date,create_time)
|
||||
values('{dsQuantity.Tables[0].Rows[i]["drug_id"].ToString()}',3,'手术室','日结','{dsQuantity.Tables[0].Rows[i]["manu_no"].ToString()}',
|
||||
'{dsQuantity.Tables[0].Rows[i]["eff_date"].ToString()}',0,0,{dsQuantity.Tables[0].Rows[i]["manuQuantity"].ToString()},{dsQuantity.Tables[0].Rows[i]["totalQuantity"].ToString()},'DM3','{DateTime.Now.ToString("yyyy-MM-dd")}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
||||
cmd.CommandText = insertSpecial;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
}
|
||||
transaction.Commit();
|
||||
Console.WriteLine($"{DateTime.Now}CreateMethodForSSS生成账册成功");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Console.WriteLine($"{DateTime.Now}CreateMethodForSSS生账册失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine($"{DateTime.Now} CreateMethodForSSS账册生成失败:{ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
using MySqlConnector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CreateAccountBookConsole
|
||||
{
|
||||
public class SqlHelper
|
||||
{
|
||||
public static DataSet ExecuteQuery(string sql, params MySqlParameter[] param)
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(sql, conn))
|
||||
{
|
||||
if (param != null)
|
||||
cmd.Parameters.AddRange(param);
|
||||
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
|
||||
da.Fill(ds);
|
||||
if (param != null)
|
||||
cmd.Parameters.Clear();
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int ExecuteScalar(string sql, params MySqlParameter[] param)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
if (param != null)
|
||||
cmd.Parameters.AddRange(param);
|
||||
int affectCount = int.Parse(cmd.ExecuteScalar().ToString());
|
||||
|
||||
if (param != null)
|
||||
cmd.Parameters.Clear();//添加这一句即可解决此问题
|
||||
return affectCount;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行增、删、改的方法
|
||||
/// </summary>
|
||||
/// <param name="sql">预计执行的非SELECT查询语句</param>
|
||||
/// <param name="param">SQL语句中的可变参数</param>
|
||||
/// <returns>返回受影响的行数</returns>
|
||||
public static int ExecuteNonQuery(string sql, params MySqlParameter[] param)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
if (param != null)
|
||||
cmd.Parameters.AddRange(param);
|
||||
int affectCount = cmd.ExecuteNonQuery();
|
||||
if (param != null)
|
||||
cmd.Parameters.Clear();//添加这一句即可解决此问题
|
||||
return affectCount;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static long ExecuteNonQueryAndGetLastInsertedId(string sql, params MySqlParameter[] param)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||
if (param != null)
|
||||
cmd.Parameters.AddRange(param);
|
||||
int affectCount = cmd.ExecuteNonQuery();
|
||||
if (param != null)
|
||||
cmd.Parameters.Clear();
|
||||
return cmd.LastInsertedId;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool ExecuteNonQueryList(List<string> sqlList, List<MySqlParameter[]> paramList)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["dbConnect"].ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlTransaction transaction = conn.BeginTransaction();
|
||||
MySqlCommand cmd = conn.CreateCommand();
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < sqlList.Count; i++)
|
||||
{
|
||||
cmd.CommandText = sqlList[i];
|
||||
cmd.Parameters.AddRange(paramList[i]);
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();//添加这一句即可解决此问题
|
||||
}
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//logs.Log.WriteLine("错误原因:" + ex.Message);
|
||||
try
|
||||
{
|
||||
//logs.Log.WriteLine("事物回滚");
|
||||
transaction.Rollback();//出现错误就回滚...
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
throw ex1;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue