370 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			370 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Windows.Forms;
 | |
| using AIMSBLL;
 | |
| using AIMSModel;
 | |
| 
 | |
| namespace AIMS.PublicUI.UI
 | |
| {
 | |
|     public partial class frmAnaesthesiaEventSelect : Form
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// 可用的器械
 | |
|         /// </summary>
 | |
|         public DataTable dt;
 | |
|         /// <summary>
 | |
|         /// 已选择的器械
 | |
|         /// </summary>
 | |
|         public DataTable ydt;
 | |
|         /// <summary>
 | |
|         /// 当前页数
 | |
|         /// </summary>
 | |
|         int currentPage = 0;
 | |
|         /// <summary>
 | |
|         /// 总数
 | |
|         /// </summary>
 | |
|         int total = 0;
 | |
|         /// <summary>
 | |
|         /// 总页数
 | |
|         /// </summary>
 | |
|         int pages = 0;
 | |
|         /// <summary>
 | |
|         /// 
 | |
|         /// </summary>
 | |
|         public int AnaesthesiaEventsId;
 | |
|         private AnaesthesiaEvents AnaesthesiaEvents;
 | |
| 
 | |
|         public frmAnaesthesiaEventSelect()
 | |
|         {
 | |
|             InitializeComponent();
 | |
|         }
 | |
|         private void frmApplianceSelect_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             AnaesthesiaEvents = BAnaesthesiaEvents.SelectSingle(AnaesthesiaEventsId);
 | |
|             dgvD.AutoGenerateColumns = false;
 | |
|             dgvY.AutoGenerateColumns = false;
 | |
|             dt = BEvents.SelectIdName("");
 | |
|             ydt = BEvents.GetEventsByIds(AnaesthesiaEvents.TheEventsId);
 | |
|             BindDgvY(ydt);
 | |
|             cboType_SelectedIndexChanged(null, null);
 | |
|         }
 | |
|         private void btnCancel_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             this.Close();
 | |
|         }
 | |
|         private void BindDgvY(DataTable dt)
 | |
|         {
 | |
|             dgvY.AutoGenerateColumns = false;
 | |
|             dgvY.Rows.Clear();
 | |
|             foreach (DataRow dr in dt.Rows)
 | |
|             {
 | |
|                 int index = this.dgvY.Rows.Add();
 | |
|                 this.dgvY.Rows[index].Cells["yId"].Value = dr["Id"].ToString();
 | |
|                 this.dgvY.Rows[index].Cells["yName"].Value = dr["Name"].ToString();
 | |
|             }
 | |
|         }
 | |
|         private void BindDgv(DataTable dt)
 | |
|         {
 | |
|             dgvD.AutoGenerateColumns = false;
 | |
|             dgvD.Rows.Clear();
 | |
|             int num = 1;
 | |
|             foreach (DataRow dr in dt.Rows)
 | |
|             {
 | |
|                 int index = this.dgvD.Rows.Add();
 | |
|                 this.dgvD.Rows[index].Cells["Id"].Value = dr["Id"].ToString();
 | |
|                 this.dgvD.Rows[index].Cells["Index"].Value = num;
 | |
|                 num++;
 | |
|                 this.dgvD.Rows[index].Cells["oName"].Value = dr["Name"].ToString();
 | |
|             }
 | |
|         }
 | |
|         private void cboType_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             currentPage = 0;
 | |
|             dt = BEvents.SelectIdName("");
 | |
|             SetPageText(dt);
 | |
|             BindDgv(GetTableByCurrentPage(currentPage, dt));
 | |
|         }
 | |
| 
 | |
|         private void SetPageText(DataTable table)
 | |
|         {
 | |
|             total = table.Rows.Count;
 | |
|             if (total % 10 == 0)
 | |
|             {
 | |
|                 pages = total / 10;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 pages = total / 10 + 1;
 | |
|             }
 | |
|             lblPage.Text = currentPage + 1 + "/" + pages + ",共" + total + "条";
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 得到某页的DataTable
 | |
|         /// </summary>
 | |
|         /// <param name="currPage">当前页</param>
 | |
|         /// <param name="dt">获取数据的DataTable</param>
 | |
|         /// <returns>某一页的DataTable</returns>
 | |
|         private DataTable GetTableByCurrentPage(int currPage, DataTable dt)
 | |
|         {
 | |
|             DataTable pdt = dt.Clone();
 | |
|             int index = currPage * 10;
 | |
|             for (int i = index; i < index + 10; i++)
 | |
|             {
 | |
|                 if (i == total)
 | |
|                 {
 | |
|                     break;
 | |
|                 }
 | |
|                 DataRow dr = pdt.NewRow();
 | |
|                 dr["Id"] = Convert.ToInt32(dt.Rows[i]["Id"]);
 | |
|                 dr["Name"] = dt.Rows[i]["Name"].ToString();
 | |
|                 pdt.Rows.Add(dr);
 | |
|             }
 | |
|             return pdt;
 | |
|         }
 | |
|         private void txtQuery_TextChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             dt = BEvents.SelectIdName(txtQuery.Text);
 | |
|             currentPage = 0;
 | |
|             SetPageText(dt);
 | |
|             BindDgv(GetTableByCurrentPage(currentPage, dt));
 | |
|         }
 | |
| 
 | |
|         private void lkUp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 | |
|         {
 | |
|             if (total == 0 || currentPage == 0)
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             currentPage--;
 | |
|             SetPageText(dt);
 | |
|             BindDgv(GetTableByCurrentPage(currentPage, dt));
 | |
|         }
 | |
| 
 | |
|         private void lkDown_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 | |
|         {
 | |
|             if (total == 0 || (currentPage + 1) == pages)
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
|             currentPage++;
 | |
|             SetPageText(dt);
 | |
|             BindDgv(GetTableByCurrentPage(currentPage, dt));
 | |
|         }
 | |
| 
 | |
|         private void btnSelectAll_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             foreach (DataGridViewRow row in dgvD.Rows)
 | |
|             {
 | |
|                 foreach (DataGridViewRow yRow in dgvY.Rows)
 | |
|                 {
 | |
|                     if (row.Cells["Selectc"].EditedFormattedValue.ToString() == "True" && row.Cells["oName"].Value.ToString() == yRow.Cells["yName"].Value.ToString())
 | |
|                     {
 | |
|                         MessageBox.Show("已经选过了!");
 | |
|                         foreach (DataGridViewRow drow in dgvD.Rows)
 | |
|                         {
 | |
|                             if (drow.Cells["Selectc"].EditedFormattedValue.ToString() == "True")
 | |
|                             {
 | |
|                                 drow.Cells["Selectc"].Value = false;
 | |
|                             }
 | |
|                         }
 | |
|                         return;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             List<int> list = new List<int>();
 | |
|             foreach (DataGridViewRow row in dgvD.Rows)
 | |
|             {
 | |
|                 if (row.Cells["Selectc"].EditedFormattedValue.ToString() == "True")
 | |
|                 {
 | |
|                     list.Add(Convert.ToInt32(row.Cells["Id"].Value));
 | |
|                 }
 | |
|             }
 | |
|             foreach (int id in list)
 | |
|             {
 | |
|                 DataRow ydr = ydt.NewRow();
 | |
|                 foreach (DataRow dr in dt.Rows)
 | |
|                 {
 | |
|                     if (Convert.ToInt32(dr["Id"]) == id)
 | |
|                     {
 | |
|                         ydr["Id"] = Convert.ToInt32(dr["Id"]);
 | |
|                         ydr["Name"] = dr["Name"].ToString();
 | |
|                         ydt.Rows.Add(ydr);
 | |
|                         break;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             BindDgvY(ydt);
 | |
|         }
 | |
| 
 | |
|         private void btnCancelAll_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             List<int> list = new List<int>();
 | |
|             foreach (DataGridViewRow row in dgvY.Rows)
 | |
|             {
 | |
|                 if (row.Cells["ySelect"].EditedFormattedValue.ToString() == "True")
 | |
|                 {
 | |
|                     list.Add(Convert.ToInt32(row.Cells["yId"].Value));
 | |
|                 }
 | |
|             }
 | |
|             foreach (int id in list)
 | |
|             {
 | |
|                 foreach (DataGridViewRow row in dgvY.Rows)
 | |
|                 {
 | |
|                     if (Convert.ToInt32(row.Cells["yId"].Value) == id)
 | |
|                     {
 | |
|                         dgvY.Rows.Remove(row);
 | |
|                         break;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void btnSave_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             List<int> list = new List<int>(); 
 | |
|             foreach (DataGridViewRow row in dgvY.Rows)
 | |
|             {
 | |
|                 list.Add(Convert.ToInt32(row.Cells["yId"].Value)); ;
 | |
|             }
 | |
|             string applianceId = string.Join(",", list.ToArray()); 
 | |
|             AnaesthesiaEvents.TheEventsId = applianceId;
 | |
|             int num = BAnaesthesiaEvents.Update(AnaesthesiaEvents);
 | |
|             if (num > 0)
 | |
|             { 
 | |
|                 this.Close();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void dgvD_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 | |
|         {
 | |
|             DataRow ydr = ydt.NewRow();
 | |
|             int id = Convert.ToInt32(dgvD.SelectedRows[0].Cells["Id"].Value);
 | |
|             foreach (DataRow row in ydt.Rows)
 | |
|             {
 | |
|                 if (Convert.ToInt32(row["Id"]) == id)
 | |
|                 {
 | |
|                     MessageBox.Show("已选择!");
 | |
|                     return;
 | |
|                 }
 | |
|             }
 | |
|             foreach (DataRow row in dt.Rows)
 | |
|             {
 | |
|                 if (Convert.ToInt32(row["Id"]) == id)
 | |
|                 {
 | |
|                     for (int i = 0; i < dt.Columns.Count; i++)
 | |
|                     {
 | |
|                         ydr["Id"] = row["Id"];
 | |
|                         ydr["Name"] = row["Name"];
 | |
|                     }
 | |
|                     ydt.Rows.Add(ydr);
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|             BindDgvY(ydt);
 | |
|         }
 | |
| 
 | |
|         public DataGridViewTextBoxEditingControl dgvTxt = null; // 声明 一个文本 CellEdit
 | |
|         public DataGridViewTextBoxEditingControl dgvTxtName = null; // 声明 一个文本 CellEdit
 | |
|         private void dgvY_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
 | |
|         {
 | |
|             //判断类型
 | |
|             if (dgvY.CurrentCell != null)
 | |
|             {
 | |
|                 if (dgvY.CurrentCell.ColumnIndex == 3)
 | |
|                 {
 | |
|                     dgvTxtName = (DataGridViewTextBoxEditingControl)e.Control; // 得到单元格
 | |
|                     dgvTxtName.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
 | |
|                     dgvTxtName.KeyPress += new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         void dgvTxt_KeyPress(object sender, KeyPressEventArgs e)
 | |
|         {
 | |
|             if (e.KeyChar < 48 || e.KeyChar > 57)
 | |
|             {
 | |
|                 if (e.KeyChar != 46 && e.KeyChar != 8 && e.KeyChar != 13)
 | |
|                 {
 | |
|                     e.Handled = true;
 | |
|                 }
 | |
|             }
 | |
|             TextBox tb = sender as TextBox;
 | |
|             if (e.KeyChar == 46)
 | |
|             {
 | |
|                 int n = tb.Text.LastIndexOf(".");
 | |
|                 if (n > 0) e.Handled = true;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 上移
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         private void buttonX1_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 DataGridViewSelectedRowCollection dgvsrc = dgvY.SelectedRows;//获取选中行的集合     
 | |
|                 if (dgvsrc.Count > 0)
 | |
|                 {
 | |
|                     int index = dgvY.SelectedRows[0].Index;//获取当前选中行的索引               
 | |
|                     if (index > 0)//如果该行不是第一行                 
 | |
|                     {
 | |
|                         DataGridViewRow dgvr = dgvY.Rows[index - dgvsrc.Count];//获取选中行的上一行                
 | |
|                         dgvY.Rows.RemoveAt(index - dgvsrc.Count);//删除原选中行的上一行        
 | |
|                         dgvY.Rows.Insert((index), dgvr);//将选中行的上一行插入到选中行的后面      
 | |
|                         for (int i = 0; i < dgvsrc.Count; i++)//选中移动后的行                      
 | |
|                         {
 | |
|                             dgvY.Rows[index - i - 1].Selected = true;
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 MessageBox.Show(ex.ToString());
 | |
|             }
 | |
| 
 | |
|         }
 | |
|         /// <summary>
 | |
|         /// 下移
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         private void buttonX2_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 DataGridViewSelectedRowCollection dgvsrc = dgvY.SelectedRows;//获取选中行的集合       
 | |
|                 if (dgvsrc.Count > 0)
 | |
|                 {
 | |
|                     int index = dgvY.SelectedRows[0].Index;//获取当前选中行的索引                
 | |
|                     if (index >= 0 & (dgvY.RowCount - 1) != index)//如果该行不是最后一行          
 | |
|                     {
 | |
|                         DataGridViewRow dgvr = dgvY.Rows[index + 1];//获取选中行的下一行       
 | |
|                         dgvY.Rows.RemoveAt(index + 1);//删除原选中行的上一行      
 | |
|                         dgvY.Rows.Insert((index + 1 - dgvsrc.Count), dgvr);//将选中行的上一行插入到选中行的后面   
 | |
|                         for (int i = 0; i < dgvsrc.Count; i++)//选中移动后的行            
 | |
|                         {
 | |
|                             dgvY.Rows[index + 1 - i].Selected = true;
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 MessageBox.Show(ex.ToString());
 | |
|             }
 | |
| 
 | |
| 
 | |
|         } 
 | |
|     }
 | |
| }
 |