using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
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_VehicleManagement : XtraForm
{
private DataTable ResultDT;
public Form_VehicleManagement()
{
InitializeComponent();
}
private void Form_VehicleManagement_Load(object sender, EventArgs e)
{
BindDate();
}
public void BindDate()
{
try
{
ResultDT = DBHelpClass.Get(string.Format("api/base/T_Base_Ambulance/GetAmbulanceList?hospitalGuid={0}&plateNumber={1}&state={2}", Information.Hospital.GUID, "", -1));
gridControl1.DataSource = ResultDT;//显示分页结果
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据列表:\r\n" + ex);
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
int state = -1;
if (!string.IsNullOrWhiteSpace(comboBoxEdit1.Text))
{
switch (comboBoxEdit1.Text)
{
case "空闲":
state = 1;
break;
case "出车中":
state = 2;
break;
case "维修中":
state = 3;
break;
case "已报废":
state = 4;
break;
}
}
ResultDT = DBHelpClass.Get(string.Format("api/base/T_Base_Ambulance/GetAmbulanceList?hospitalGuid={0}&plateNumber={1}&state={2}", Information.Hospital.GUID, textEdit1.Text, state));
gridControl1.DataSource = ResultDT;//显示分页结果
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据列表:\r\n" + ex);
}
}
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "State")//1、空闲,2、出车中,3、维修中,4、已报废
{
int gender = PublicClass.ToInt32(e.Value, 0);
switch (gender)
{
case 1:
e.DisplayText = "空闲";
break;
case 2:
e.DisplayText = "出车中";
break;
case 3:
e.DisplayText = "维修中";
break;
case 4:
e.DisplayText = "已报废";
break;
}
}
}
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
int selectRow = gridView1.GetSelectedRows()[0];
string state = PublicClass.ToString(gridView1.GetRowCellValue(selectRow, "State").ToString(), "");
string guid = PublicClass.ToString(gridView1.GetRowCellValue(selectRow, "GUID").ToString(), "");
switch (e.Button.Caption)
{
case "选择跟车人员":
if (state == "1")
{
Form_OwnerlessPersonnel frm = new Form_OwnerlessPersonnel(guid);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.Owner = this;
frm.Show();
}
break;
}
}
///
/// 动态按钮事件
///
///
///
private void RiButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
{
int selectRow = gridView1.GetSelectedRows()[0];
string guid = PublicClass.ToString(gridView1.GetRowCellValue(selectRow, "GUID").ToString(), "");
switch (e.Button.Caption)
{
case "选择跟车人员":
Form_OwnerlessPersonnel frm = new Form_OwnerlessPersonnel(guid);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.Owner = this;
frm.Show();
break;
case "重新分配跟车人员":
VehicleUnbundlingDTO dto = new VehicleUnbundlingDTO();
List list = new List();
dto.GUID = guid;
list.Add(dto);
string Url = string.Empty;
Url = "api/admin/T_SYS_User/VehicleUnbundling";
//初始化两个工厂
ClientFactory httpClient = new HttpClientFactory();
Client client = httpClient.VisitFactory();
if (client.Post(Url, list).Success)
{
BindDate();
Form_OwnerlessPersonnel from = new Form_OwnerlessPersonnel(guid);
from.StartPosition = FormStartPosition.CenterScreen;
from.Owner = this;
from.Show();
}
break;
}
}
private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
try
{
if (ResultDT != null && e.Column.Name == "gridColumn_operate")
{
RepositoryItemButtonEdit riButtonEdit = new RepositoryItemButtonEdit();
riButtonEdit.Buttons.Clear();
riButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
string per = PublicClass.ToString(gridView1.GetRowCellValue(e.RowHandle, "Personnel"), "");
string state = PublicClass.ToString(gridView1.GetRowCellValue(e.RowHandle, "State").ToString(), "");
EditorButton bt1 = new EditorButton();
bt1.Kind = ButtonPredefines.Glyph;
bt1.Visible = true;
bt1.Enabled = true;
bt1.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
bt1.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
riButtonEdit.ButtonClick += RiButtonEdit_ButtonClick;
if (state == "1")
{
if (string.IsNullOrEmpty(per))
{
bt1.Caption = "选择跟车人员";
}
else
{
bt1.Caption = "重新分配跟车人员";
}
riButtonEdit.Buttons.Add(bt1);
e.RepositoryItem = riButtonEdit;
}
}
}
catch (Exception)
{
throw;
}
}
}
}