DataGridView添加另外一个控件。

  1 using System;

  2 using System.Collections.Generic;

  3 using System.ComponentModel;

  4 using System.Drawing;

  5 using System.Data;

  6 using System.Linq;

  7 using System.Text;

  8 using System.Windows.Forms;

  9 using System.Xml;

 10 

 11 namespace XjxMobilenursing

 12 {

 13     public partial class frmNurseList : UserControl

 14     {

 15         #region 全局变量

 16         private frmNurse myparentform = null; //父窗体

 17         private string strtemplate = "";      //Web Service 返回的XML数据

 18         private bool bolLook = true;         //是否锁定

 19         private ComboBox mySingleVeto;

 20         private DataGridView mypopudatagridview = null;

 21         private int iRowIndex = 0;

 22         private string strrq1 = "";

 23         private int yzlx = 0;

 24         private Nurseinfo fNurseinfo = null; 

 25      //   private Dictionary<string, DataTable> conDataitems = new Dictionary<string, DataTable>();

 26         #endregion

 27         public frmNurseList()

 28         {

 29             InitializeComponent();

 30         }

 31         #region 类成员GET和SET方法

 32         public frmNurse OwnerParentForm

 33         {

 34             get

 35             { return myparentform; }

 36             set

 37             { this.myparentform = value; }

 38         }

 39         public bool bLook

 40         {

 41             get

 42             {

 43                 return this.bolLook;

 44             }

 45             set

 46             {

 47                 this.bolLook = value;

 48             }

 49         }

 50         public string RQ1

 51         {

 52             get

 53             {

 54                 if (!StringCommon.IsDate(this.strrq1))

 55                 {

 56                     this.strrq1 = DateTime.Now.ToString("yyyy-MM-dd");

 57 

 58                 }

 59                 return strrq1;

 60             }

 61             set

 62             {

 63                 this.strrq1 = value;

 64             }

 65         }

 66         //public Dictionary<string, DataTable> conData

 67         //{

 68         //    get

 69         //    {

 70         //        return conDataitems;

 71         //    }

 72         //    set { conDataitems = value; }

 73         //}

 74         #endregion

 75         #region 重置dataGridView数据

 76         public void ReflashTable()

 77         {

 78             try

 79             {

 80                 if (this.NurseGridList == null) return;

 81                 DataTable dt = (DataTable)NurseGridList.DataSource;

 82                 if (dt != null)

 83                 {

 84                     dt.Rows.Clear();

 85                     NurseGridList.DataSource = dt;

 86                 }

 87             }

 88             catch (Exception ex)

 89             {

 90                 MessageBox.Show(ex.Source + ":" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

 91             }

 92         }

 93         #endregion

 94         #region get护理单记录信息XML

 95         public bool getNurseListInfo(string rq1, string rq2)

 96         {

 97             try

 98             {

 99                 if (this.OwnerParentForm == null)

100                     return false;

101                 if (!StringCommon.IsDate(rq1))

102                 {

103                     rq1 = DateTime.Parse(this.OwnerParentForm.OwnerParentForm.CurrentPatientInfo.rysj).ToString("yyyy-MM-dd");

104                 }

105                 if (!StringCommon.IsDate(rq2))

106                 {

107                     rq2 = DateTime.Now.ToString("yyyy-MM-dd");

108                 }

109                 string strresult;

110                 this.strtemplate = "";

111                 strresult = this.OwnerParentForm.OwnerParentForm.Xjxinfoweb.GetNurseTableinfo(Properties.Settings.Default.strapplication_account,

112                     this.OwnerParentForm.OwnerParentForm.CurrentPatientInfo.lsh, rq1, rq2);

113 

114                 if (strresult.IndexOf("error") > -1)

115                 {

116                     return false;

117                 }

118                 else if (strresult == "")

119                 {

120                     return false;

121                 }

122                 this.strtemplate = strresult;

123                 return true;

124             }

125             catch (Exception ex)

126             {

127                 MessageBox.Show(ex.Source + ":" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

128                 return false;

129             }

130         }

131         #endregion

132         #region Set护理单信息XML到DataTable

133         private DataTable FromXML2DataTable(string XMLStr)

134         {

135             XmlDocument myDoc = new XmlDocument();

136             myDoc.LoadXml(XMLStr);

137             if (string.IsNullOrEmpty(XMLStr) || !myDoc.HasChildNodes) return null;

138             DataTable dt = new DataTable();

139             DataRow row = null;

140             DataColumn col = null;

141             //填充数据

142             foreach (XmlElement el in myDoc.SelectNodes("Nurseinfos/row"))

143             {

144                 row = dt.NewRow();

145                 foreach (XmlNode node in el.ChildNodes)

146                 {

147                     if (!dt.Columns.Contains(node.Name))

148                     {

149                         col = new DataColumn();

150                         col.ColumnName = node.Name;

151                         dt.Columns.Add(col);

152                     }

153                     row[node.Name] = node.InnerText;

154                 }

155                 dt.Rows.Add(row);

156             }

157             return dt;

158         }

159         #endregion

160         #region Set护理单信息DataTable到GridView

161         public void ShowNurseTable()

162         {

163             DataTable ds = FromXML2DataTable(this.strtemplate);

164             if (ds != null && ds.Rows.Count > 0)

165             {

166                 NurseGridList.AutoGenerateColumns = false;

167                 NurseGridList.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

168                 NurseGridList.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

169                 NurseGridList.DataSource = ds;

170                 NurseGridList.ClearSelection();

171             }

172         }

173         #endregion

174         #region Set护理单GridView可编辑

175         public void SetEditNurseTable()

176         {

177             try

178             {

179                 this.bLook = false;

180                 this.NurseGridList.ReadOnly = this.bolLook;

181                 this.NurseGridList.AllowUserToAddRows = !this.bolLook;

182                 if (this.NurseGridList.RowCount <= 0) return;

183                 this.NurseGridList.FirstDisplayedScrollingRowIndex = this.NurseGridList.Rows.Count - 1;

184                 this.NurseGridList.Rows[this.NurseGridList.Rows.Count - 1].Selected = true;

185                 this.NurseGridList.CurrentCell = this.NurseGridList.Rows[this.NurseGridList.Rows.Count - 1].Cells["rqsj"];

186                 this.NurseGridList.Focus();

187                 this.NurseGridList.BeginEdit(false);

188             }

189             catch (Exception ex)

190             {

191                 MessageBox.Show("对象:" + this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "异常信息:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

192             }

193         }

194         #endregion

195         #region Set护理单GridView删除

196         public void SetdelNurseTable()

197         {

198             try

199             {

200                 fNurseinfo = FillNurseinfo();

201                 this.yzlx = 3;

202                 string requestParam = this.PkgCtrlParams(yzlx, fNurseinfo);

203                 string rtn = OwnerParentForm.OwnerParentForm.Xjxinfoweb.SetNurseRequest(requestParam);

204                 MessageBox.Show(rtn);

205             }

206             catch (Exception ex)

207             {

208                 MessageBox.Show("对象:" + this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "异常信息:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

209             }

210         }

211         #endregion

212         #region 窗体初始化

213         private void frmNurseList_Load(object sender, EventArgs e)

214         {

215             try

216             {

217                 this.mySingleVeto = new ComboBox();

218                 this.mySingleVeto.FormattingEnabled = true;

219                 this.mySingleVeto.Items.AddRange(new object[] {

220             "",

221             "True",

222             "False"});

223                 this.mySingleVeto.BringToFront();

224                 this.mySingleVeto.SelectedIndexChanged += new System.EventHandler(this.mySingleVeto_SelectedIndexChanged);

225                 //this.mySingleVeto.Click += new System.EventHandler(this.mySingleVeto_Click);

226                 this.mySingleVeto.KeyUp += new System.Windows.Forms.KeyEventHandler(this.mySingleVeto_KeyUp);

227                 this.mySingleVeto.Visible = false;

228                 InitDataGridView(this.NurseGridList, "ZY_tHLDTJLD");

229                 this.NurseGridList.Controls.Add(this.mySingleVeto);

230 

231                 mypopudatagridview = new DataGridView();

232                 mypopudatagridview.Width = 200;

233                 mypopudatagridview.Height = 200;

234                 mypopudatagridview.AllowUserToAddRows = false;

235                 mypopudatagridview.AllowUserToDeleteRows = false;

236                 mypopudatagridview.AllowUserToResizeRows = false;

237                 mypopudatagridview.BackgroundColor = System.Drawing.Color.White;

238                 mypopudatagridview.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

239                 mypopudatagridview.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.mypopudatagridview_CellClick);

240                 mypopudatagridview.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

241                 mypopudatagridview.MultiSelect = false;

242                 mypopudatagridview.Name = "mypopudatagridview";

243                 mypopudatagridview.ReadOnly = true;

244                 mypopudatagridview.RowTemplate.Height = 23;

245                 mypopudatagridview.Cursor = Cursors.Hand;

246                 mypopudatagridview.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;

247                 mypopudatagridview.AllowUserToOrderColumns = false;

248                 mypopudatagridview.RowHeadersVisible = false;

249                 mypopudatagridview.Visible = false;

250                 this.NurseGridList.Controls.Add(mypopudatagridview);

251                 InitPopDataGridView(mypopudatagridview, "XT_TCSSZ");

252             }

253             catch (Exception ex)

254             {

255                 MessageBox.Show("对象:" + this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "异常信息:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

256             }

257         }

258         #endregion

259         #region 主GridView初始化

260         private void InitDataGridView(DataGridView sender, string strName)

261         {

262             try

263             {

264                 DataTable dt = new DataTable(strName);

265                 dt.Columns.Add("jlid");

266                 dt.Columns.Add("lsh");

267                 dt.Columns.Add("JLR");

268                 dt.Columns.Add("rqsj");

269                 dt.Columns.Add("sz");

270                 dt.Columns.Add("xybhd");

271                 dt.Columns.Add("tk_y");

272                 dt.Columns.Add("tk_z");

273                 dt.Columns.Add("dgfs_y");

274                 dt.Columns.Add("dgfs_z");

275                 dt.Columns.Add("rl_mc");

276                 dt.Columns.Add("rllx");

277                 dt.Columns.Add("rl_l");

278                 dt.Columns.Add("cl_mc");

279                 dt.Columns.Add("cllx");

280                 dt.Columns.Add("cl_l");

281                 dt.Columns.Add("bbreathingmachine");

282                 dt.Columns.Add("hx");

283                 dt.Columns.Add("s");

284                 dt.Columns.Add("f");

285                 dt.Columns.Add("qm");

286                 sender.DataSource = dt;

287                 sender.AllowUserToOrderColumns = false;

288                 sender.RowHeadersVisible = false;

289                 sender.ReadOnly = this.bolLook;

290                 sender.AllowUserToAddRows = !this.bolLook;

291                 sender.Columns["jlid"].HeaderText = "jlid";

292                 sender.Columns["jlid"].Visible = false;

293                 sender.Columns["lsh"].HeaderText = "lsh";

294                 sender.Columns["lsh"].Visible = false;

295                 sender.Columns["JLR"].HeaderText = "JLR";

296                 sender.Columns["JLR"].Visible = false;

297 

298                 sender.Columns["rqsj"].HeaderText = "日期";

299                 sender.Columns["rqsj"].Width = 100;

300                 //  sender.Columns["rqsj"].ReadOnly = this.bolLook;

301                 sender.Columns["rqsj"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

302 

303                 sender.Columns["sz"].HeaderText = "神志";

304                 sender.Columns["sz"].Width = 60;

305               //  sender.Columns["sz"].ReadOnly = this.bolLook;

306                 sender.Columns["sz"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

307 

308                 sender.Columns["xybhd"].HeaderText = "血氧饱和度%";

309                 sender.Columns["xybhd"].Width = 150;

310                 //  sender.Columns["xybhd"].ReadOnly = this.bolLook;

311                 sender.Columns["xybhd"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

312 

313                 sender.Columns["tk_y"].HeaderText = "对光反应右";

314                 sender.Columns["tk_y"].Width = 150;

315                 // sender.Columns["tk_y"].ReadOnly = this.bolLook;

316                 sender.Columns["tk_y"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

317 

318                 sender.Columns["tk_z"].HeaderText = "对光反应左";

319                 sender.Columns["tk_z"].Width = 150;

320                 // sender.Columns["tk_z"].ReadOnly = this.bolLook;

321                 sender.Columns["tk_z"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

322 

323                 sender.Columns["dgfs_y"].HeaderText = "瞳孔(右)";

324                 sender.Columns["dgfs_y"].Width = 100;

325                 //  sender.Columns["dgfs_y"].ReadOnly = this.bolLook;

326                 sender.Columns["dgfs_y"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

327 

328                 sender.Columns["dgfs_z"].HeaderText = "瞳孔(左)";

329                 sender.Columns["dgfs_z"].Width = 100;

330                 //  sender.Columns["dgfs_z"].ReadOnly = this.bolLook;

331                 sender.Columns["dgfs_z"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

332 

333                 sender.Columns["rl_mc"].HeaderText = "入量名称";

334                 sender.Columns["rl_mc"].Width = 150;

335                 // sender.Columns["rl_mc"].ReadOnly = this.bolLook;

336                 sender.Columns["rl_mc"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

337 

338 

339                 sender.Columns["rllx"].HeaderText = "入量(单位)";

340                 sender.Columns["rllx"].Width = 150;

341                 //sender.Columns["rllx"].ReadOnly = this.bolLook;

342                 sender.Columns["rllx"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

343 

344                 sender.Columns["rl_l"].HeaderText = "入量(量)";

345                 sender.Columns["rl_l"].Width = 100;

346                 //  sender.Columns["rl_l"].ReadOnly = this.bolLook;

347                 sender.Columns["rl_l"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

348 

349                 sender.Columns["cl_mc"].HeaderText = " 出量名称";

350                 sender.Columns["cl_mc"].Width = 150;

351                 // sender.Columns["cl_mc"].ReadOnly = this.bolLook;

352                 sender.Columns["cl_mc"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

353 

354 

355                 sender.Columns["cllx"].HeaderText = "出量(单位)";

356                 sender.Columns["cllx"].Width = 150;

357                 // sender.Columns["cllx"].ReadOnly = this.bolLook;

358                 sender.Columns["cllx"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

359 

360                 sender.Columns["cl_l"].HeaderText = "出量(量)";

361                 sender.Columns["cl_l"].Width = 100;

362                 // sender.Columns["cl_l"].ReadOnly = this.bolLook;

363                 sender.Columns["cl_l"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

364 

365                 sender.Columns["bbreathingmachine"].HeaderText = "呼吸机";

366                 sender.Columns["bbreathingmachine"].Width = 100;

367                 //sender.Columns["bbreathingmachine"].ReadOnly = this.bolLook;

368                 sender.Columns["bbreathingmachine"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

369 

370                 sender.Columns["hx"].HeaderText = "呼吸";

371                 sender.Columns["hx"].Width = 60;

372                 // sender.Columns["hx"].ReadOnly = this.bolLook;

373                 sender.Columns["hx"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

374 

375                 sender.Columns["s"].HeaderText = "";

376                 sender.Columns["s"].Width = 30;

377                 // sender.Columns["s"].ReadOnly = this.bolLook;

378                 sender.Columns["s"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

379 

380                 sender.Columns["f"].HeaderText = "";

381                 sender.Columns["f"].Width = 30;

382                 // sender.Columns["f"].ReadOnly = this.bolLook;

383                 sender.Columns["f"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

384 

385                 sender.Columns["qm"].HeaderText = "记录人";

386                 sender.Columns["qm"].Width = 100;

387                 //sender.Columns["qm"].ReadOnly = this.bolLook;

388                 sender.Columns["qm"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

389 

390                 sender.Tag = strName;

391             }

392             catch (Exception ex)

393             {

394                 MessageBox.Show("对象:" + this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "异常信息:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

395             }

396 

397         }

398         #endregion

399         #region 辅GridView初始化

400         private void InitPopDataGridView(DataGridView sender, string strName)

401         {

402             try

403             {

404                 DataTable dt = new DataTable(strName);

405                 dt.Columns.Add("id");

406                 dt.Columns.Add("mc");

407                 sender.DataSource = dt;

408                 sender.Columns["id"].HeaderText = "序号";

409                 sender.Columns["id"].Width = 60;

410                 sender.Columns["id"].ReadOnly = false;

411                 sender.Columns["id"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

412                 sender.Columns["mc"].HeaderText = "名称";

413                 sender.Columns["mc"].Width = 260;

414                 sender.Columns["mc"].ReadOnly = false;

415                 sender.Columns["mc"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;

416             }

417             catch (Exception ex)

418             {

419                 MessageBox.Show("对象:" + this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "异常信息:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

420             }

421 

422 

423 

424         }

425         #endregion

426         #region 主GridView触发事件

427         private void NurseGridList_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

428         {

429             if (this.bLook) return;

430             if (e.RowIndex < 0)

431             {

432                 return;

433             }

434             if (this.NurseGridList.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "rl_l".ToUpper()

435               || this.NurseGridList.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "cl_l".ToUpper())

436             {

437                 string str = e.FormattedValue.ToString();

438                 this.NurseGridList.Rows[e.RowIndex].ErrorText = "";

439 

440                 if (XjxWordE.xjxformat.StringCommon.IsNumeric(str))

441                 {

442                     if (double.Parse(str) < 0)

443                     {

444                         if (this.NurseGridList.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "cl_l".ToUpper())

445                         {

446                             this.NurseGridList.Rows[e.RowIndex].ErrorText = "分值输入的必须是大于或等于0的数字,请重输";

447                         }

448                         else

449                         {

450                             this.NurseGridList.Rows[e.RowIndex].ErrorText = "数量输入的必须是大于或等于0的数字,请重输";

451                         }

452 

453                         MessageBox.Show(this.NurseGridList.Rows[e.RowIndex].ErrorText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

454 

455                         e.Cancel = true;

456                     }

457                 }

458                 else

459                 {

460                     if (this.NurseGridList.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "cl_l".ToUpper())

461                     {

462                         this.NurseGridList.Rows[e.RowIndex].ErrorText = "分值输入的必须是数字类型,请重输";

463                     }

464                     else

465                     {

466                         this.NurseGridList.Rows[e.RowIndex].ErrorText = "数量输入的必须是数字类型,请重输";

467                     }

468 

469                     MessageBox.Show(this.NurseGridList.Rows[e.RowIndex].ErrorText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

470 

471                     e.Cancel = true;

472                 }

473             }

474 

475         }

476         private void NurseGridList_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

477         {

478             if (this.bLook) return;

479             string kind = this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToLower();

480             switch (kind)

481             {

482                 case "sz":

483                 case "tk_y":

484                 case "tk_z":

485                 case "dgfs_y":

486                 case "dgfs_z":

487                 case "rl_mc":

488                 case "rllx":

489                 case "cl_mc":

490                 case "cllx":

491                     TextBox mytextbox;

492                     mytextbox = e.Control as TextBox;

493                     mytextbox.Name = this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToLower();

494                     mytextbox.Tag = this.NurseGridList.CurrentCell;

495                     if (mytextbox == null) return;

496                     mytextbox.Click += new System.EventHandler(this.mytextbox_Click);

497                     //mytextbox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.mytextbox_KeyUp);

498                     break;

499                 default:

500                     this.mypopudatagridview.Visible = false;

501                     break;

502             }

503         }

504         private void NurseGridList_CellEnter(object sender, DataGridViewCellEventArgs e)

505         {

506             if (this.bLook) return;

507             if (this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToUpper() == "bbreathingmachine".ToUpper())

508             {

509                 Rectangle rect = this.NurseGridList.GetCellDisplayRectangle(this.NurseGridList.CurrentCell.ColumnIndex, this.NurseGridList.CurrentCell.RowIndex, false);

510                 this.mySingleVeto.Text = this.NurseGridList.CurrentCell.Value.ToString();

511                 this.mySingleVeto.Left = rect.Left;

512                 this.mySingleVeto.Top = rect.Top;

513                 this.mySingleVeto.Width = rect.Width;

514                 this.mySingleVeto.Height = rect.Height;

515                 this.mySingleVeto.Tag = this.NurseGridList.CurrentCell;

516                 this.mySingleVeto.Visible = true;

517                 this.mySingleVeto.BringToFront();

518                 this.mySingleVeto.Focus();

519                 this.mypopudatagridview.Visible = false;

520             }

521             else

522             {

523                 this.mySingleVeto.Visible = false;

524             }

525         }

526         private void NurseGridList_CurrentCellChanged(object sender, EventArgs e)

527         {

528             if (this.bLook) return;

529             string kind = this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToLower();

530             switch (kind)

531             {

532                 case "sz":

533                 case "tk_y":

534                 case "tk_z":

535                 case "dgfs_y":

536                 case "dgfs_z":

537                 case "rl_mc":

538                 case "rllx":

539                 case "cl_mc":

540                 case "cllx":

541                     if (this.mySingleVeto != null && this.mySingleVeto.Visible)

542                     {

543                         DataGridViewCell mycell = this.mySingleVeto.Tag as DataGridViewCell;

544                         if (mycell == null) return;

545                         mycell.Value = this.mySingleVeto.Text;

546                         this.mySingleVeto.Visible = false;

547                         this.mySingleVeto.Tag = null;

548                         this.NurseGridList.BeginEdit(false);

549                     }

550                     if (this.mypopudatagridview != null)

551                     {

552                         DataGridViewCell mydatagridviewcell = this.mypopudatagridview.Tag as DataGridViewCell;

553                         if ((mydatagridviewcell != null) && (this.NurseGridList.Columns[mydatagridviewcell.ColumnIndex].Name != kind))

554                         {

555                             this.mypopudatagridview.Visible = false;

556                             iRowIndex = 0;

557                             this.mypopudatagridview.Tag = null;

558                             this.NurseGridList.BeginEdit(false);

559                         }

560                     }

561                     break;

562                 case "bbreathingmachine":

563                     if (this.mypopudatagridview != null)

564                     {

565                         this.mypopudatagridview.Visible = false;

566                         iRowIndex = 0;

567                         this.mypopudatagridview.Tag = null;

568                         this.NurseGridList.BeginEdit(false);

569                     }

570                     break;

571                 default:

572                     if (this.mySingleVeto != null && this.mySingleVeto.Visible)

573                     {

574                         DataGridViewCell mycell = this.mySingleVeto.Tag as DataGridViewCell;

575                         if (mycell == null) return;

576                         mycell.Value = this.mySingleVeto.Text;

577                         this.mySingleVeto.Visible = false;

578                         this.mySingleVeto.Tag = null;

579                         this.NurseGridList.BeginEdit(false);

580                     }

581                     if (this.mypopudatagridview != null)

582                     {

583                         DataGridViewCell mydatagridviewcell = this.mypopudatagridview.Tag as DataGridViewCell;

584                         this.mypopudatagridview.Visible = false;

585                         iRowIndex = 0;

586                         this.mypopudatagridview.Tag = null;

587                         this.NurseGridList.BeginEdit(false);

588                     }

589                     break;

590             }

591         }

592         private void NurseGridList_CellClick(object sender, DataGridViewCellEventArgs e)

593         {

594             if (this.bLook) return;

595             if (this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToUpper() == "rqsj".ToUpper())

596             {

597                 SelectDatetime();

598             }

599         }

600         private void NurseGridList_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)

601         {

602             if (this.bLook) return;

603             if (this.mySingleVeto == null) return;

604             this.mySingleVeto.Visible = false;

605         }

606         private void NurseGridList_Scroll(object sender, ScrollEventArgs e)

607         {

608             if (this.bLook) return;

609             if (this.mySingleVeto == null) return;

610             this.mySingleVeto.Visible = false;

611         }

612         private void NurseGridList_RowLeave(object sender, DataGridViewCellEventArgs e)

613         {

614             fNurseinfo = FillNurseinfo();

615             string requestParam = this.PkgCtrlParams(yzlx, fNurseinfo);

616             string rtn = OwnerParentForm.OwnerParentForm.Xjxinfoweb.SetNurseRequest(requestParam);

617            // MessageBox.Show(rtn);

618         }

619         #endregion

620         #region 日期选择事件

621         public void SelectDatetime()

622         {

623             using (frmSelectsingleDate myfrm = new frmSelectsingleDate())

624             {

625                 myfrm.RQ1 = this.RQ1;

626                 if (myfrm.ShowDialog() == DialogResult.OK)

627                 {

628                     this.NurseGridList.Rows[this.NurseGridList.CurrentCell.RowIndex].Cells[this.NurseGridList.CurrentCell.ColumnIndex].Value = myfrm.RQ1;

629                     this.NurseGridList.Rows[this.NurseGridList.CurrentCell.RowIndex].Cells["s"].Value = DateTime.Now.Hour.ToString();

630                     this.NurseGridList.Rows[this.NurseGridList.CurrentCell.RowIndex].Cells["f"].Value = DateTime.Now.Minute.ToString();

631                     this.NurseGridList.CurrentCell = this.NurseGridList.Rows[this.NurseGridList.CurrentCell.RowIndex].Cells[this.NurseGridList.CurrentCell.ColumnIndex + 1];

632                     this.NurseGridList.Focus();

633                     this.NurseGridList.BeginEdit(false);

634                 }

635             }

636         }

637         #endregion

638         #region 获取控件数据小窗口grid

639         private void mytextbox_KeyUp(object sender, KeyEventArgs e)

640         {

641             string kind = this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToLower();

642             if ((kind != "sz") && (kind != "tk_y") && (kind != "tk_z") && (kind != "dgfs_y") && (kind != "dgfs_z") && (kind != "rl_mc") && (kind != "rllx") && (kind != "cl_mc") && (kind != "cllx"))

643             {

644                 e.Handled = true;

645                 return;

646             }

647             switch (e.KeyCode)

648             {

649                 case Keys.Down:

650                     if (this.mypopudatagridview.Rows.Count < 0) return;

651                     iRowIndex++;

652                     if (iRowIndex >= this.mypopudatagridview.Rows.Count) iRowIndex = this.mypopudatagridview.Rows.Count - 1;

653                     setSelectRowValue(iRowIndex);

654                     e.Handled = true;

655                     break;

656                 case Keys.Up:

657                     if (this.mypopudatagridview.Rows.Count < 0) return;

658                     iRowIndex--;

659                     if (iRowIndex < 0) iRowIndex = 0;

660                     setSelectRowValue(iRowIndex);

661                     e.Handled = true;

662                     break;

663                 case Keys.Enter:

664                     if (this.mypopudatagridview.Visible && this.mypopudatagridview.Rows.Count > 0)

665                     {

666                         setSelectRowValue(iRowIndex);

667                     }

668                     System.Windows.Forms.SendKeys.Send("{TAB}");

669                     e.Handled = true;

670                     break;

671             }

672 

673             if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) return;

674 

675             if (!this.mypopudatagridview.Visible)

676             {

677                 Rectangle rect = this.NurseGridList.GetCellDisplayRectangle(this.NurseGridList.CurrentCell.ColumnIndex, this.NurseGridList.CurrentCell.RowIndex, false);

678                 this.mypopudatagridview.Visible = true;

679 

680                 this.mypopudatagridview.Left = rect.Left;

681                 if (rect.Top + this.mypopudatagridview.Height > this.NurseGridList.Height)

682                 {

683                     this.mypopudatagridview.Top = rect.Top - this.mypopudatagridview.Height;

684                 }

685                 else

686                 {

687                     this.mypopudatagridview.Top = rect.Top + rect.Height;

688                 }

689                 this.mypopudatagridview.Tag = this.NurseGridList.CurrentCell;

690                 this.mypopudatagridview.Visible = true;

691             }

692             if (this.mypopudatagridview.Visible)

693             {

694                 TextBox mytextbox = sender as TextBox;

695                 string tbName = mytextbox.Name;

696                 if (mytextbox == null) return;

697                 if (this.NurseGridList.Columns[Name].Tag != null && this.NurseGridList.Columns[Name].Tag is DataTable)

698                 {

699                     this.mypopudatagridview.DataSource = this.NurseGridList.Columns[Name].Tag;

700                 }

701                 else

702                 {

703                     this.writePopDataGridView(tbName);

704                 }

705             }

706         }

707         private void mytextbox_Click(object sender, EventArgs e)

708         {

709             string kind = this.NurseGridList.Columns[this.NurseGridList.CurrentCell.ColumnIndex].Name.ToString().ToLower();

710             if ((kind != "sz") && (kind != "tk_y") && (kind != "tk_z") && (kind != "dgfs_y") && (kind != "dgfs_z") && (kind != "rl_mc") && (kind != "rllx") && (kind != "cl_mc") && (kind != "cllx"))

711             {

712                 return;

713             }

714             if (!this.mypopudatagridview.Visible)

715             {

716                 Rectangle rect = this.NurseGridList.GetCellDisplayRectangle(this.NurseGridList.CurrentCell.ColumnIndex, this.NurseGridList.CurrentCell.RowIndex, false);

717                 this.mypopudatagridview.Visible = true;

718 

719                 this.mypopudatagridview.Left = rect.Left;

720                 if (rect.Top + this.mypopudatagridview.Height > this.NurseGridList.Height)

721                 {

722                     this.mypopudatagridview.Top = rect.Top - this.mypopudatagridview.Height;

723                 }

724                 else

725                 {

726                     this.mypopudatagridview.Top = rect.Top + rect.Height;

727                 }

728                 this.mypopudatagridview.Tag = this.NurseGridList.CurrentCell;

729                 this.mypopudatagridview.Visible = true;

730             }

731             if (this.mypopudatagridview.Visible)

732             {

733                 TextBox mytextbox = sender as TextBox;

734                 string tbName = mytextbox.Name;

735                 if (mytextbox == null) return;

736                 //if (this.conDataitems != null && this.conDataitems.Count > 0 && this.conDataitems.ContainsKey(tbName))

737                 //{

738                 //    DataTable dt = this.conDataitems[tbName] as DataTable;

739                 //    this.mypopudatagridview.DataSource = dt;

740                 //}

741                 //else

742                 //{

743                 //    this.writePopDataGridView(tbName);

744                 //}

745                 if (this.NurseGridList.Columns[kind].Tag != null && this.NurseGridList.Columns[kind].Tag is DataTable)

746                 {

747                     this.mypopudatagridview.DataSource = this.NurseGridList.Columns[kind].Tag;

748                 }

749                 else

750                 {

751                     this.writePopDataGridView(kind);

752                 }

753             }

754 

755         }

756         private void mypopudatagridview_CellClick(object sender, DataGridViewCellEventArgs e)

757         {

758             if (e.RowIndex < 0) return;

759             iRowIndex = e.RowIndex;

760             setSelectRowValue(iRowIndex);

761             DataGridViewCell mydatagridviewcell = this.mypopudatagridview.Tag as DataGridViewCell;

762             DataGridViewCell mycell = this.mypopudatagridview.Tag as DataGridViewCell;

763             if (mydatagridviewcell != null)

764             {

765                 this.NurseGridList.FirstDisplayedScrollingRowIndex = this.NurseGridList.Rows.Count - 1;

766                 this.NurseGridList.Rows[this.NurseGridList.Rows.Count - 1].Selected = true;

767                 this.NurseGridList.CurrentCell = this.NurseGridList.Rows[mycell.RowIndex].Cells[mycell.ColumnIndex + 1];

768                 this.NurseGridList.Focus();

769                 this.NurseGridList.BeginEdit(false);

770             }

771             this.mypopudatagridview.Visible = false;

772             this.mypopudatagridview.Tag = null;

773             iRowIndex = 0;

774         }

775         public void writePopDataGridView(string Name)

776         {

777             //if (this.mypopudatagridview.RowCount > 0) ((DataTable)this.mypopudatagridview.DataSource).Clear();

778             XmlDocument myDoc = new XmlDocument();

779             string respStr = string.Empty;

780             respStr = this.OwnerParentForm.OwnerParentForm.Xjxinfoweb.GetNurseTabinfo(Name, string.Empty);

781             if (string.IsNullOrEmpty(respStr) || respStr.IndexOf("error") > -1)

782             {

783                 MessageBox.Show(respStr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

784                 return;

785             }

786             myDoc.LoadXml(respStr);

787             DataTable dt = new DataTable();

788             DataRow row = null;

789             DataColumn col = null;

790             foreach (XmlElement el in myDoc.SelectNodes("patientinfos/patientinfo"))

791             {

792                 row = dt.NewRow();

793                 foreach (XmlNode node in el.ChildNodes)

794                 {

795                     if (!dt.Columns.Contains(node.Name))

796                     {

797                         col = new DataColumn();

798                         col.ColumnName = node.Name;

799                         dt.Columns.Add(col);

800                     }

801                     row[node.Name] = node.InnerText;

802                 }

803                 dt.Rows.Add(row);

804             }

805             this.mypopudatagridview.DataSource = dt;

806             //if (!this.conDataitems.ContainsKey(Name.ToString()))

807             //{

808             //    this.conDataitems.Add(Name, dt);

809             //}

810             this.NurseGridList.Columns[Name].Tag = dt;

811         }

812         private void setSelectRowValue(int rowindex)

813         {

814             if (this.mypopudatagridview.Rows.Count < 0) return;

815             if (rowindex < 0 || rowindex > this.mypopudatagridview.Rows.Count) return;

816             this.mypopudatagridview.FirstDisplayedScrollingRowIndex = rowindex;

817             this.mypopudatagridview.Rows[rowindex].Selected = true;

818             this.NurseGridList.Rows[this.NurseGridList.CurrentCell.RowIndex].Cells[this.NurseGridList.CurrentCell.ColumnIndex].Value = this.mypopudatagridview.Rows[rowindex].Cells["mc"].Value.ToString();

819         }

820         #endregion

821         #region 获取Combox

822         private void mySingleVeto_SelectedIndexChanged(object sender, EventArgs e)

823         {

824             return;

825         }

826         private void mySingleVeto_KeyUp(object sender, KeyEventArgs e)

827         {

828             int index = mySingleVeto.SelectedIndex;

829             switch (e.KeyCode)

830             {

831                 case Keys.Up:

832                     index--;

833                     if (index < 0) index = 0;

834                     mySingleVeto.SelectedIndex = index;

835                     e.Handled = true;

836                     break;

837                 case Keys.Down:

838                     index++;

839                     if (index >= this.mySingleVeto.Items.Count) index = this.mySingleVeto.Items.Count - 1;

840                     this.mySingleVeto.SelectedIndex = index;

841                     e.Handled = true;

842                     break;

843                 case Keys.Enter:

844                     DataGridViewCell mycell = this.Tag as DataGridViewCell;

845                     if (mycell == null) return;

846                     mycell.Value = this.mySingleVeto.Text;

847                     this.NurseGridList.FirstDisplayedScrollingRowIndex = mycell.RowIndex;

848                     this.NurseGridList.Rows[mycell.RowIndex].Selected = true;

849                     this.NurseGridList.CurrentCell = this.NurseGridList.Rows[mycell.RowIndex].Cells[mycell.ColumnIndex + 1];

850                     this.NurseGridList.Focus();

851                     this.NurseGridList.BeginEdit(false);

852                     e.Handled = true;

853                     break;

854             }

855         }

856         #endregion

857         #region 获取记录

858         private Nurseinfo FillNurseinfo()

859         {

860             DataGridViewRow selectedRow = NurseGridList.CurrentRow;

861             if (selectedRow == null)

862             {

863                 MessageBox.Show("请选中记录", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);

864                 return null;

865             }

866             Nurseinfo myNurseinfo = new Nurseinfo();

867             if (selectedRow.Cells["jlid"].Value + "" == "")

868             {

869                 this.yzlx = 1;

870                 myNurseinfo.jlid = "0";

871             }

872             else

873             {

874                 this.yzlx = 2;

875                 myNurseinfo.jlid = selectedRow.Cells["jlid"].Value + "";

876             }

877             

878             myNurseinfo.lsh = selectedRow.Cells["lsh"].Value + "";

879             myNurseinfo.jlr = selectedRow.Cells["jlr"].Value + "";

880             myNurseinfo.rqsj = selectedRow.Cells["rqsj"].Value + "";

881             myNurseinfo.s = selectedRow.Cells["s"].Value + "";

882             myNurseinfo.f = selectedRow.Cells["f"].Value + "";

883             myNurseinfo.bbreathingmachine = selectedRow.Cells["bbreathingmachine"].Value + "";

884             myNurseinfo.hx = selectedRow.Cells["hx"].Value + "";

885             myNurseinfo.sz = selectedRow.Cells["sz"].Value + "";

886             myNurseinfo.s = selectedRow.Cells["s"].Value + "";

887             myNurseinfo.xybhd = selectedRow.Cells["xybhd"].Value + "";

888             myNurseinfo.dgfs_z = selectedRow.Cells["dgfs_y"].Value + "";

889             myNurseinfo.tk_z = selectedRow.Cells["tk_z"].Value + "";

890             myNurseinfo.tk_y = selectedRow.Cells["tk_y"].Value + "";

891             myNurseinfo.rl_mc = selectedRow.Cells["rl_mc"].Value + "";

892             myNurseinfo.rllx = selectedRow.Cells["rllx"].Value + "";

893             myNurseinfo.rl_l = selectedRow.Cells["rl_l"].Value + "";

894             myNurseinfo.cl_mc = selectedRow.Cells["cl_mc"].Value + "";

895             myNurseinfo.cllx = selectedRow.Cells["cl_l"].Value + "";

896             return myNurseinfo;

897         }

898         #endregion

899         #region 界面数据打包XML

900         private string PkgCtrlParams(int opKind, Nurseinfo oNurseinfo)

901         {

902             Patientinfo myCurrentPatientinfo = OwnerParentForm.OwnerParentForm.CurrentPatientInfo;

903             if (myCurrentPatientinfo == null || (opKind != 1 && opKind != 2 && opKind != 3)) return string.Empty;

904             XmlDocument myDoc = new XmlDocument();

905             XmlElement root = myDoc.CreateElement("params");

906             myDoc.AppendChild(root);

907             try

908             {

909                 AppendToXml(root, "jlid", oNurseinfo.jlid);//*主键

910                 AppendToXml(root, "lsh", myCurrentPatientinfo.lsh == 0 ? "" : myCurrentPatientinfo.lsh.ToString());//*患者ID

911                 AppendToXml(root, "czzt", opKind.ToString());//*执行保存操作;1:增,2:改,3:删

912                 AppendToXml(root, "jlr", Properties.Settings.Default.iapplication_yhid.ToString());//*操作员ID

913             }

914             catch (Exception e)

915             {

916                 MessageBox.Show(this, e.Message, "出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

917                 return string.Empty;

918             }

919             if ((opKind == 1) || (opKind == 2))

920             {

921                 AppendToXml(root, "rqsj", oNurseinfo.rqsj);      //*护理时间

922                 AppendToXml(root, "s", oNurseinfo.s);            //护理时

923                 AppendToXml(root, "f", oNurseinfo.f);            //护理分

924                 AppendToXml(root, "bbreathingmachine", true? "1" : "0");//*呼吸机

925                 AppendToXml(root, "hx", oNurseinfo.hx);     //*呼吸机速率

926                 AppendToXml(root, "sz", oNurseinfo.sz);          //神志

927                 AppendToXml(root, "xybhd", oNurseinfo.xybhd);    //血氧饱和度

928                 AppendToXml(root, "dgfs_z", oNurseinfo.dgfs_z);  //对光反应左

929                 AppendToXml(root, "dgfs_y", oNurseinfo.dgfs_y);  //对光反应右

930                 AppendToXml(root, "tk_z", oNurseinfo.tk_z);      //瞳孔(左)

931                 AppendToXml(root, "tk_y", oNurseinfo.tk_y);      //瞳孔(右)

932                 AppendToXml(root, "rl_mc ", oNurseinfo.rl_mc);  //入量名称

933                 AppendToXml(root, "rllx", oNurseinfo.rllx);    //入量(单位)

934                 AppendToXml(root, "rl_l", oNurseinfo.rl_l);    //入量(量)

935                 AppendToXml(root, "cl_mc", oNurseinfo.cl_mc);   //出量名称

936                 AppendToXml(root, "cllx", oNurseinfo.cllx);    //出量(单位)

937                 AppendToXml(root, "cl_l", oNurseinfo.cl_l);    //出量(量)

938                 AppendToXml(root, "jlsj", oNurseinfo.rqsj);      //*记录护理时间

939 

940             }

941             return myDoc.OuterXml;

942         }

943         private void AppendToXml(XmlElement root, string name, string text)

944         {

945             if (string.IsNullOrEmpty(text)) return;

946             XMLCommon.CreateChildElement(root, name, true, text);

947         }

948         #endregion

949     }

950 }
View Code

 

你可能感兴趣的:(datagridview)