178 lines
6.7 KiB
C#
178 lines
6.7 KiB
C#
using DevExpress.Utils;
|
||
using DevExpress.XtraEditors;
|
||
using DevExpress.XtraEditors.Controls;
|
||
using DevExpress.XtraGrid;
|
||
using DevExpress.XtraGrid.Views.Base;
|
||
using HL_FristAidPlatform_DTO;
|
||
using HL_FristAidPlatform_Public;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Windows.Forms;
|
||
|
||
namespace HL_FristAidPlatform_PreHospitalEmergency
|
||
{
|
||
public partial class Form_Phonebook : Form
|
||
{
|
||
/// <summary>
|
||
/// 当前页
|
||
/// </summary>
|
||
public int curPage = 1;
|
||
/// <summary>
|
||
/// 每页大小
|
||
/// </summary>
|
||
public int pageSize = 100;
|
||
/// <summary>
|
||
/// 所有记录条数
|
||
/// </summary>
|
||
public int totalNumber = 0;
|
||
|
||
|
||
public Form_Phonebook()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void Form_Phonebook_Load(object sender, EventArgs e)
|
||
{
|
||
GetPhoneBookData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询电话簿
|
||
/// </summary>
|
||
public void GetPhoneBookData()
|
||
{
|
||
try
|
||
{
|
||
//车辆状态
|
||
DataTable ResultDT = DBHelpClass.Get("api/service/T_Service_FirstAid_PhoneBook?pageIndex=" + curPage + "&pageSize=" + pageSize);
|
||
gridControl1.DataSource = ResultDT;//显示分页结果
|
||
totalNumber = DBHelpClass.TotalNumber;
|
||
userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示。
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "绑定数据列表:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
public void SaveOrUpdata(string GUID, T_Service_FirstAid_PhoneBookDTO model)
|
||
{
|
||
try
|
||
{
|
||
List<T_Service_FirstAid_PhoneBookDTO> list = new List<T_Service_FirstAid_PhoneBookDTO>();
|
||
string Url = string.Empty;
|
||
//修改
|
||
if (!string.IsNullOrEmpty(GUID))
|
||
{
|
||
Url = "/api/service/T_Service_FirstAid_PhoneBook/Update";
|
||
model.GUID = GUID;
|
||
}
|
||
else
|
||
{
|
||
Url = "api/service/T_Service_FirstAid_PhoneBook";
|
||
model.GUID = Guid.NewGuid().ToString();
|
||
}
|
||
list.Add(model);
|
||
//初始化两个工厂
|
||
ClientFactory<T_Service_FirstAid_PhoneBookDTO> httpClient = new HttpClientFactory<T_Service_FirstAid_PhoneBookDTO>();
|
||
Client<T_Service_FirstAid_PhoneBookDTO> client = httpClient.VisitFactory();
|
||
if (client.Post(Url, list).Success)
|
||
{
|
||
XtraMessageBox.Show("保存信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
XtraMessageBox.Show("保存信息失败,请重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
PublicClass.WriteErrorLog(this.Text, "保存患者信息:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
private void gridView1_RowUpdated(object sender, RowObjectEventArgs e)
|
||
{
|
||
int selectRow = gridView1.GetSelectedRows()[0];
|
||
string Guid = gridView1.GetRowCellValue(selectRow, "GUID").ToString();
|
||
T_Service_FirstAid_PhoneBookDTO model = new T_Service_FirstAid_PhoneBookDTO();
|
||
model.name = gridView1.GetRowCellValue(selectRow, "name").ToString();
|
||
model.unit = gridView1.GetRowCellValue(selectRow, "unit").ToString();
|
||
model.phone = gridView1.GetRowCellValue(selectRow, "phone").ToString();
|
||
model.DeleteFlag = 0;
|
||
SaveOrUpdata(Guid, model);
|
||
GetPhoneBookData();
|
||
}
|
||
|
||
private void RowDeleted(string Guid, string name)
|
||
{
|
||
try
|
||
{
|
||
string Url = "api/service/T_Service_FirstAid_PhoneBook/Update";
|
||
List<T_Service_FirstAid_PhoneBookDTO> list = new List<T_Service_FirstAid_PhoneBookDTO>();
|
||
T_Service_FirstAid_PhoneBookDTO model = new T_Service_FirstAid_PhoneBookDTO();
|
||
model.GUID = Guid;
|
||
model.DeleteFlag = 1;
|
||
list.Add(model);
|
||
|
||
//初始化两个工厂
|
||
ClientFactory<T_Service_FirstAid_PhoneBookDTO> httpClient = new HttpClientFactory<T_Service_FirstAid_PhoneBookDTO>();
|
||
Client<T_Service_FirstAid_PhoneBookDTO> client = httpClient.VisitFactory();
|
||
|
||
//访问
|
||
ListEntity<T_Service_FirstAid_PhoneBookDTO> t = client.Post(Url, list);
|
||
if (t.Success)
|
||
{
|
||
XtraMessageBox.Show(string.Format("【{0}】已删除!", name), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
//绑定列表
|
||
GetPhoneBookData();
|
||
}
|
||
else
|
||
{
|
||
XtraMessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "删除联系人信息:\r\n" + ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Ctrl+Delete删除一行数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e)
|
||
{
|
||
ColumnView view = (sender as GridControl).FocusedView as ColumnView;
|
||
if (view == null) return;
|
||
if (e.KeyCode == Keys.Delete && e.Control && view.OptionsBehavior.AllowDeleteRows != DefaultBoolean.False && view.SelectedRowsCount > 0)
|
||
{
|
||
int selectRow = view.GetSelectedRows()[0];
|
||
string Guid = view.GetRowCellValue(selectRow, "GUID").ToString();
|
||
string Name = view.GetRowCellValue(selectRow, "name").ToString();
|
||
string unit = view.GetRowCellValue(selectRow, "unit").ToString();
|
||
if (XtraMessageBox.Show($"确定删除所选{unit}的{Name}?", "提问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
view.DeleteSelectedRows();
|
||
RowDeleted(Guid, Name);
|
||
GetPhoneBookData();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ButtonEdit_Call_ButtonClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void ButtonEdit_Transfer_ButtonClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|