StableVersion4.3/HL_FristAidPlatform_PreHosp.../Form_DrugCheckIn.cs

215 lines
8.5 KiB
C#
Raw Normal View History

2024-03-11 09:47:34 +08:00
using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace HL_FristAidPlatform_PreHospitalEmergency
{
public partial class Form_DrugCheckIn : XtraForm
{
private string _managementGUID;
private string _name;
private string _source;
private string _inventory;
private string _manufacturer;
private string _batchNumber;
private string _termOfValidity;
private string _drugGuid;
private int _flag;
public Form_DrugCheckIn(string managementGUID, string name, string source, string inventory, string manufacturer, string batchNumber, string termOfValiditey, string drugGuid, int flag)
{
InitializeComponent();
_managementGUID = managementGUID;
_name = name;
_source = source;
_inventory = inventory;
_manufacturer = manufacturer;
_batchNumber = batchNumber;
_termOfValidity = termOfValiditey;
_drugGuid = drugGuid;
_flag = flag;
}
private void Form_DrugCheckIn_Load(object sender, EventArgs e)
{
try
{
textEdit6.Text = Information.User.FullName;
DataTable dt = DBHelpClass.Get(string.Format("api/base/T_Base_Drug/GetAmbulanceDrugList"));
checkedListBoxControl1.DataSource = dt;//显示分页结果
this.checkedListBoxControl1.DisplayMember = "Name";
this.checkedListBoxControl1.ValueMember = "GUID";
if (!string.IsNullOrEmpty(_managementGUID))
{
checkedListBoxControl1.SelectedIndex = -1;
txt_DrugName.Text = _name;
txt_BatchNumber.Text = _batchNumber;
txt_Inventory.Text = _inventory;
txt_Manufacturer.Text = _manufacturer;
cmb_DrugSource.Text = _source;
textEdit6.Text = Information.User.FullName;
if (_flag == 0)
{
//dateEx_TermOfValidity.DatePicker.DateValue = Convert.ToDateTime(_termOfValidity);
}
if (_flag == 1)//标识添加
{
checkedListBoxControl1.Enabled = false;
txt_BatchNumber.Enabled = false;
txt_Manufacturer.Enabled = false;
cmb_DrugSource.Enabled = false;
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据源:\r\n" + ex);
}
}
private void Form_DrugCheckIn_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
private void checkedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{
if (e.State == CheckState.Checked)
{
txt_DrugName.Text = checkedListBoxControl1.Text;
}
}
private void simpleButton2_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_Inventory.Text))
{
XtraMessageBox.Show("库存不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_Inventory.Focus();
return;
}
if (!string.IsNullOrEmpty(txt_Inventory.Text) && !Regex.IsMatch(txt_Inventory.Text.ToString(), @"^-?[1-9]\d*$|^0$"))
{
XtraMessageBox.Show("库存只能是数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_Inventory.Focus();
return;
}
if (int.Parse(txt_Inventory.Text) <= 0)
{
XtraMessageBox.Show("库存不能为0", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_Inventory.Focus();
return;
}
if (string.IsNullOrEmpty(cmb_DrugSource.Text))
{
XtraMessageBox.Show("来源不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
cmb_DrugSource.Focus();
return;
}
if (string.IsNullOrEmpty(txt_Manufacturer.Text))
{
XtraMessageBox.Show("厂家不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_Manufacturer.Focus();
return;
}
if (string.IsNullOrEmpty(txt_BatchNumber.Text))
{
XtraMessageBox.Show("药物批号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_BatchNumber.Focus();
return;
}
/* if (string.IsNullOrEmpty(dateEx_TermOfValidity.DatePicker.DateValue.ToString()))
{
XtraMessageBox.Show("有效期不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
dateEx_TermOfValidity.Focus();
return;
}*/
List<DrugManagementDTO> list = new List<DrugManagementDTO>();
DrugManagementDTO dto = new DrugManagementDTO();
if (checkedListBoxControl1.SelectedIndex == -1 && string.IsNullOrEmpty(_managementGUID))
{
XtraMessageBox.Show("必须选择药物!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
checkedListBoxControl1.Focus();
return;
}
dto.Inventory = int.Parse(txt_Inventory.Text);
dto.DrugSource = cmb_DrugSource.Text;
dto.Manufacturer = txt_Manufacturer.Text;
dto.BatchNumber = txt_BatchNumber.Text;
if (timeControl1.TimeValue != null)
{
dto.TermOfValidity = Convert.ToDateTime(timeControl1.TimeValue);
}
dto.CheckInUserID = Information.User.ID;
string Url = string.Empty;
if (_flag == 1)
{
dto.ManagementGUID = _managementGUID;
Url = "api/service/FristAidTran/ContinueAddDrug";
}
else
{
if (string.IsNullOrEmpty(_managementGUID))
{
dto.DrugGUID = checkedListBoxControl1.SelectedValue.ToString();
dto.HospitalGuid = Information.Hospital.GUID;
Url = "api/service/FristAidTran/InserDrug";
}
else
{
if (checkedListBoxControl1.SelectedIndex > -1)
{
dto.DrugGUID = checkedListBoxControl1.SelectedValue.ToString();
}
else
{
dto.DrugGUID = _drugGuid;
}
dto.ManagementGUID = _managementGUID;
dto.UpdateUserID = Information.User.ID;
Url = "api/service/FristAidTran/UpdateDrug";
}
}
list.Add(dto);
//初始化两个工厂
ClientFactory<DrugManagementDTO> httpClient = new HttpClientFactory<DrugManagementDTO>();
Client<DrugManagementDTO> client = httpClient.VisitFactory();
//访问
ListEntity<DrugManagementDTO> t = client.Post(Url, list);
if (t.Success)
{
MessageBox.Show("保存成功");
Form_DrugManagement info;
info = (Form_DrugManagement)this.Owner;
info.RefreshData();
Close();
}
else
{
MessageBox.Show("保存失败");
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}