/// <summary> /// 根据参数实体查询数据 /// </summary> /// <param name="data">检索不为空的数据</param> /// <returns>返回查询到的数据</returns> public IEnumerable <View_ZPX_CVTRepairInfo> GetViewData(View_ZPX_CVTRepairInfo data) { DepotManagementDataContext context = CommentParameter.DepotDataContext; IEnumerable <View_ZPX_CVTRepairInfo> result = null; if (data.序号 > 0) { result = from r in context.View_ZPX_CVTRepairInfo where r.序号 == data.序号 select r; } else { result = from r in context.View_ZPX_CVTRepairInfo where r.产品型号 == data.产品型号 select r; if (!GlobalObject.GeneralFunction.IsNullOrEmpty(data.新箱号) || !GlobalObject.GeneralFunction.IsNullOrEmpty(data.旧箱号)) { result = from r in result where r.新箱号.Contains(data.新箱号) select r; } } return(result); }
/// <summary> /// 检索实体数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSearchProduct_Click(object sender, EventArgs e) { View_ZPX_CVTRepairInfo data = new View_ZPX_CVTRepairInfo(); data.产品型号 = cmbProductCode.Text; data.新箱号 = GlobalObject.GeneralFunction.IsNullOrEmpty(txtProductNumber.Text) ? null : txtProductNumber.Text; data.旧箱号 = GlobalObject.GeneralFunction.IsNullOrEmpty(txtProductNumber.Text) ? null : txtProductNumber.Text; RefreshDataGridView(m_testServer.GetViewData(data)); }
/// <summary> /// 更新数据 /// </summary> /// <param name="data">要更新的数据</param> /// <returns>操作是否成功的标志</returns> public bool Update(View_ZPX_CVTRepairInfo data) { DepotManagementDataContext context = CommentParameter.DepotDataContext; var result = from r in context.ZPX_CVTRepairInfo where r.ID == data.序号 select r; if (result.Count() == 0) { throw new Exception("找不到要更新的记录,无法进行此操作"); } ZPX_CVTRepairInfo updateData = result.Single(); if (updateData.Recorder != GlobalObject.BasicInfo.LoginID) { throw new Exception("不是记录创建人员不允许进行此操作"); } if (updateData.Status == "已完成") { throw new Exception("返修已完成,不允许进行此操作"); } View_ZPX_CVTRepairInfo old = (from r in context.View_ZPX_CVTRepairInfo where r.序号 == data.序号 select r).Single(); if (GlobalObject.StapleFunction.SimpleEqual <View_ZPX_CVTRepairInfo>(old, data)) { throw new Exception("数据没有任何变化,不需要进行此操作"); } updateData.ProductType = data.产品型号; updateData.Assembler = data.返修人员; updateData.AssociateBillNo = data.关联单号; updateData.AssociateType = data.关联单据类别; updateData.BonnetNumber = data.阀块编号; updateData.Fault = data.故障现象; updateData.Duty = data.责任判定; updateData.Hours = data.工时; updateData.IsTest = data.是否需要重新跑试验 == "需要" ? true : false; updateData.ProductNewNumber = data.新箱号; updateData.ProductOldNumber = data.旧箱号; updateData.RepairType = data.返修类型; updateData.Scheme = data.返修方案及明细; updateData.Status = data.单据状态; context.SubmitChanges(); return(true); }
/// <summary> /// 从dataGridView中获取选择的数据 /// </summary> /// <returns>返回获取到的数据</returns> private View_ZPX_CVTRepairInfo GetSelectedData() { List <View_ZPX_CVTRepairInfo> result = dataGridView1.DataSource as List <View_ZPX_CVTRepairInfo>; DataGridViewCellCollection cells = dataGridView1.SelectedRows[0].Cells; View_ZPX_CVTRepairInfo data = null; if (result == null) { data = new View_ZPX_CVTRepairInfo(); data.序号 = (int)cells["序号"].Value; data.产品型号 = (string)cells["产品型号"].Value; data.旧箱号 = (string)cells["旧箱号"].Value; data.新箱号 = (string)cells["新箱号"].Value; data.返修人员 = (string)cells["返修人员"].Value; data.故障现象 = (string)cells["故障现象"].Value; data.返修方案及明细 = (string)cells["返修方案及明细"].Value; data.是否需要重新跑试验 = (string)cells["是否需要重新跑试验"].Value; data.记录时间 = (DateTime)cells["记录时间"].Value; data.记录人员 = (string)cells["记录人员"].Value; data.返修类型 = (string)cells["返修类型"].Value; data.单据状态 = (string)cells["单据状态"].Value; data.阀块编号 = (string)cells["阀块编号"].Value; data.工时 = (decimal)cells["工时"].Value; data.关联单号 = (string)cells["关联单号"].Value; data.关联单据类别 = (string)cells["关联单据类别"].Value; data.试验状态 = (string)cells["试验状态"].Value; data.责任判定 = (string)cells["责任判定"].Value; } else { data = result.Single(p => p.序号 == (int)cells["序号"].Value); } return(data); }
private void 审核toolStripButton_Click(object sender, EventArgs e) { if (lbStatus.Text.Trim() == "等待审核") { if (BasicInfo.LoginName == dataGridView1.CurrentRow.Cells["记录人员"].Value.ToString()) { if (!CheckData()) { return; } if (dataGridView1.SelectedRows.Count == 0) { MessageDialog.ShowPromptMessage("请选择要操作的记录后再进行此操作"); return; } View_ZPX_CVTRepairInfo data = GetSelectedData(); data.产品型号 = cmbProductCode.Text; if (cmbRepairType.SelectedIndex != 3) { data.旧箱号 = txtProductNumber.Text; } else { data.旧箱号 = txtOldProductCode.Text; data.新箱号 = txtNewProductCode.Text; data.阀块编号 = txtBonnetCode.Text; } data.返修人员 = txtAssembler.Text.ToString(); data.故障现象 = txtFault.Text; data.返修方案及明细 = txtScheme.Text.Trim(); data.是否需要重新跑试验 = cbTest.Checked == true ? "需要" : "不需要"; data.工时 = numTaskTime.Value; data.返修类型 = cmbRepairType.Text; data.单据状态 = "等待质检判定"; if (cmbAssociateType.SelectedIndex != -1) { data.关联单据类别 = cmbAssociateType.Text; if (cmbAssociateType.SelectedIndex == 0) { data.关联单号 = txtAssociateBillNoBF.Text; } else { data.关联单号 = txtAssociaBillNoTK.Text; } } try { m_testServer.Update(data); MessageDialog.ShowPromptMessage("执行成功"); RefreshDataGridView(m_testServer.GetViewData(new View_ZPX_CVTRepairInfo() { 序号 = data.序号 })); } catch (Exception exce) { MessageDialog.ShowErrorMessage(exce.Message); } } else { MessageDialog.ShowPromptMessage("您不是记录人员不能审核!"); return; } } }