You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
292 lines
10 KiB
292 lines
10 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using LIS.Model;
|
|
using PEIS.Base;
|
|
using PEIS.Entity;
|
|
using PEIS.Event;
|
|
using PEIS.Presenter;
|
|
using PEIS.Utils;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PEIS.View.Base
|
|
{
|
|
public partial class OrgForm : ViewBase, IBaseOrgView
|
|
{
|
|
private List<BaseOrg> _lstOrg;
|
|
private List<BaseOrgPatient> _lstPatient;
|
|
|
|
public OrgForm()
|
|
{
|
|
InitializeComponent();
|
|
Shown += OrgForm_Shown;
|
|
MenuOrg.TsmiRefresh.Click += (s, e) =>
|
|
{
|
|
OnGetOrg();
|
|
};
|
|
MenuOrg.TsmiAdd.Click += MenuOrgAdd_Click;
|
|
MenuOrg.TsmiDelete.Click += MenuOrgDelete_Click;
|
|
MenuOrg.TsmiSave.Click += MenuOrgSave_Click;
|
|
MenuOrg.TsmiSearch.Visible = false;
|
|
MenuOrg.TstbKey.TextChanged += SearchOrg_TextChanged;
|
|
|
|
TsmiPersonImport.Click += MenuPersonImport_Click;
|
|
TsmiPersonAdd.Click += (s, e) =>
|
|
{
|
|
new SelectPatientForm(SelectPatient, "").ShowDialog();
|
|
};
|
|
|
|
TsmiPersonDelete.Click += MenuPersonDelete_Click;
|
|
TsmiPersonSave.Click += MenuPersonSave_Click;
|
|
TxtSearchPerson.TextChanged += SearchPerson_TextChanged;
|
|
DgvOrg.SelectionChanged += (s, e) =>
|
|
{
|
|
OnGetOrgPatient();
|
|
};
|
|
|
|
TxtSearchPerson.Enter += TxtSearchPerson_Enter;
|
|
TxtSearchPerson.Leave += TxtSearchPerson_Leave;
|
|
|
|
DgvPatient.Initialize();
|
|
DgvOrg.Initialize();
|
|
}
|
|
|
|
#region Base
|
|
|
|
protected override object CreatePresenter()
|
|
{
|
|
return new BaseOrgPresenter(this);
|
|
}
|
|
|
|
private void OrgForm_Shown(object sender, EventArgs e)
|
|
{
|
|
OnGetOrg();
|
|
}
|
|
|
|
public event EventHandler<Args<BaseOrg>> GetOrg;
|
|
|
|
public event EventHandler<Args<BaseOrg>> GetOrgPatient;
|
|
|
|
protected virtual void OnGetOrgPatient()
|
|
{
|
|
if (DgvOrg.GetSelectedRows().Length == 0) return;
|
|
var orgId = Convert.ToInt64(DgvOrg.GetRowCellValue(DgvOrg.GetSelectedRows()[0], "ID").ToString());
|
|
GetOrgPatient?.Invoke(this, new Args<BaseOrg> { ID = orgId });
|
|
}
|
|
|
|
protected virtual void OnGetOrg()
|
|
{
|
|
GetOrg?.Invoke(this, new Args<BaseOrg>());
|
|
}
|
|
|
|
public void ShowOrg(List<BaseOrg> items)
|
|
{
|
|
_lstOrg = items;
|
|
DgcOrg.DataSource = _lstOrg;
|
|
}
|
|
|
|
public void ShowOrgPatient(List<BaseOrgPatient> items)
|
|
{
|
|
_lstPatient = items;
|
|
DgcPatient.DataSource = _lstPatient;
|
|
}
|
|
|
|
#endregion Base
|
|
|
|
#region OpsOrg
|
|
|
|
private void SearchOrg_TextChanged(object sender, EventArgs e)
|
|
{
|
|
var search = MenuOrg.TstbKey.Text.Trim();
|
|
if (search == @"输入条件查询") return;
|
|
DgcOrg.SetDataSource(string.IsNullOrEmpty(search) ? _lstOrg : _lstOrg.Where(a => a.Name.Contains(search)).ToList());
|
|
}
|
|
|
|
private void MenuOrgSave_Click(object sender, EventArgs e)
|
|
{
|
|
DgvOrg.CloseEditor();
|
|
DgvOrg.UpdateCurrentRow();
|
|
var currentTime = CacheDataModel.GetServerTime();
|
|
foreach (var item in _lstOrg)
|
|
{
|
|
if (item.ID == 0)
|
|
{
|
|
item.CreateTime = currentTime;
|
|
item.CreatorCode = Global.currentUser.Code;
|
|
item.Creator = Global.currentUser.Name;
|
|
}
|
|
item.SaveOrUpdate();
|
|
}
|
|
Global.Msg("info", "团体信息保存成功!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除团体信息
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MenuOrgDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (DgvOrg.GetSelectedRows().Length == 0) return;
|
|
var oid = Convert.ToInt64(DgvOrg.GetRowCellValue(DgvOrg.GetSelectedRows()[0], "ID").ToString());
|
|
var name = DgvOrg.GetRowCellValue(DgvOrg.GetSelectedRows()[0], "Name").ToString();
|
|
DialogResult delConfirm = MessageBox.Show($"确定删除团体信息【{name}】?", "删除确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
|
if (delConfirm == DialogResult.Cancel) return;
|
|
bool _orgDelState = _lstOrg.Where(a => a.ID == oid).ToList()[0].Delete();
|
|
if (!_orgDelState) return;
|
|
new Entity.Log($"删除团体信息:团体名称={name}", "3").Save();
|
|
_lstPatient.ForEach(item => item.Delete());
|
|
_lstOrg.RemoveAt(_lstOrg.IndexOf(_lstOrg.Where(a => a.ID == Convert.ToInt64(DgvOrg.GetRowCellValue(DgvOrg.GetSelectedRows()[0], "ID").ToString())).ToList()[0]));
|
|
DgvOrg.RefreshData();
|
|
DgvPatient.RefreshData();
|
|
OnGetOrgPatient();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新建团体
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MenuOrgAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var newOrgForm = new NewOrgForm();
|
|
newOrgForm.NewOrgFormClosed += OnGetOrg;
|
|
newOrgForm.ShowDialog();
|
|
}
|
|
|
|
#endregion OpsOrg
|
|
|
|
#region OpsPerson
|
|
private void TxtSearchPerson_Enter(object sender, EventArgs e)
|
|
{
|
|
if (TxtSearchPerson.Text == @"输入条件查询")
|
|
{
|
|
TxtSearchPerson.Text = "";
|
|
TxtSearchPerson.ForeColor = Color.Black;
|
|
TxtSearchPerson.BackColor = Color.FromArgb(231, 234, 255);
|
|
}
|
|
}
|
|
|
|
private void TxtSearchPerson_Leave(object sender, EventArgs e)
|
|
{
|
|
if (!String.IsNullOrEmpty(TxtSearchPerson.Text)) return;
|
|
|
|
TxtSearchPerson.Text = "输入条件查询";
|
|
TxtSearchPerson.ForeColor = Color.Gray;
|
|
TxtSearchPerson.BackColor = Color.White;
|
|
}
|
|
private void SearchPerson_TextChanged(object sender, EventArgs e)
|
|
{
|
|
var search = TxtSearchPerson.Text.Trim();
|
|
if (search == @"输入条件查询") return;
|
|
DgcPatient.SetDataSource(string.IsNullOrEmpty(search) ? _lstPatient : _lstPatient.Where(a => a?.Name?.Contains(search) == true || a?.CardNo?.Contains(search) == true).ToList());
|
|
}
|
|
/// <summary>
|
|
/// 点击导入按钮,打开Excel导入界面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MenuPersonImport_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(DgvOrg.GetFocusedRow() is BaseOrg selected)) return;
|
|
new PatientImportForm(selected, ImportFormClosedRefreshPerson).ShowDialog();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入界面关闭
|
|
/// </summary>
|
|
/// <param name="patients"></param>
|
|
private void ImportFormClosedRefreshPerson(List<BaseOrgPatient> patients)
|
|
{
|
|
if (patients.Count <= 0) return;
|
|
if (DgvOrg.GetSelectedRows().Length == 0) return;
|
|
OnGetOrgPatient();
|
|
foreach (var item in patients)
|
|
{
|
|
if (_lstPatient.All(p => p.CardNo != item.CardNo))
|
|
_lstPatient.Add(item);
|
|
}
|
|
_lstPatient = _lstPatient.Distinct().ToList();
|
|
Invoke(new Action(() => DgcPatient.DataSource = null));
|
|
Invoke(new Action(() => DgcPatient.DataSource = _lstPatient));
|
|
Invoke(new Action(() => DgcPatient.Refresh()));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成员保存按钮事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MenuPersonSave_Click(object sender, EventArgs e)
|
|
{
|
|
DgvPatient.CloseEditor();
|
|
DgvPatient.UpdateCurrentRow();
|
|
|
|
foreach (var item in _lstPatient)
|
|
{
|
|
item.SaveOrUpdate();
|
|
}
|
|
OnGetOrgPatient();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成员删除按钮事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MenuPersonDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (DgvPatient.GetSelectedRows().Length == 0) return;
|
|
DialogResult delConfirm = MessageBox.Show($"确定删除 {DgvPatient.GetSelectedRows().Length} 条团体成员数据?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
|
if (delConfirm == DialogResult.OK)
|
|
{
|
|
foreach (var row in DgvPatient.GetSelectedRows())
|
|
{
|
|
var id = Convert.ToInt64(DgvPatient.GetRowCellValue(row, "ID").ToString());
|
|
bool delState = _lstPatient.Where(a => a.ID == id).ToList()[0].Delete();
|
|
if (delState)
|
|
{
|
|
new Entity.Log($@"删除团体成员:PID={DgvPatient.GetRowCellValue(row, "PID")},姓名={DgvPatient.GetRowCellValue(row, "Name")}", "3").Save();
|
|
_lstPatient.RemoveAt(_lstPatient.IndexOf(_lstPatient.Where(a => a.ID == id).ToList()[0]));
|
|
}
|
|
}
|
|
ShowOrgPatient(_lstPatient);
|
|
DgvPatient.ClearSelection();
|
|
DgvPatient.RefreshData();
|
|
}
|
|
}
|
|
|
|
#endregion OpsPerson
|
|
|
|
/// <summary>
|
|
/// 选择添加成员
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
private void SelectPatient(BasePatient item)
|
|
{
|
|
if (_lstPatient.Where(a => a.PID == item.ID).ToList().Count > 0)
|
|
{
|
|
Global.Msg("err", $@"{item.Name}, {item.Sex}, {item.CardNo} 不能重复选择!");
|
|
return;
|
|
}
|
|
_lstPatient.Add(new BaseOrgPatient
|
|
{
|
|
OID = Convert.ToInt64(DgvOrg.GetRowCellValue(DgvOrg.GetSelectedRows()[0], "ID").ToString()),
|
|
PID = item.ID,
|
|
Seq = _lstPatient.Count + 1,
|
|
Name = item.Name,
|
|
Sex = item.Sex,
|
|
CardNo = item.CardNo,
|
|
CardType = item.CardType,
|
|
Birthday = item.Birthday,
|
|
Education = item.Education,
|
|
Nation = item.Nation,
|
|
Tel1 = item.Tel1,
|
|
Tel2 = item.Tel2,
|
|
Marriage = item.Marriage
|
|
});
|
|
DgvPatient.RefreshData();
|
|
}
|
|
}
|
|
} |