private bool validate() { ComboBoxItem selectedItem = (ComboBoxItem)liquidType_comboBox.SelectedItem; if (selectedItem == null || string.IsNullOrEmpty(selectedItem.Content.ToString())) { MessageBox.Show("请选择设置类型", "系统提示"); return(false); } IList <DataGridCellInfo> cellsList = dataGrid1.SelectedCells; if (cellsList == null || cellsList.Count == 0) { MessageBox.Show("请选择采血管区域", "系统提示"); return(false); } foreach (DataGridCellInfo cell in cellsList) { int columnIndex = CommFuntion.GetDataGridCellColumnIndex(cell); int rowIndex = CommFuntion.GetDataGridCellRowIndex(cell); if (dTable.Rows[rowIndex - 1]["type" + columnIndex] != null && dTable.Rows[rowIndex - 1]["type" + columnIndex].ToString() == "hasRecord") { MessageBox.Show("不能选择已被其他类型保存的区域", "系统提示"); return(false); } } LiquidType type = (LiquidType)selectedItem.DataContext; if (type != null) { if (!type.CanSelectedMultiCell && cellsList.Count > 1) { MessageBox.Show("不能选择多个采血管区域", "系统提示"); return(false); } if (type.HasVolume && volume_TextBox.IsVisible) { double volume_out = 0; if (string.IsNullOrEmpty(volume_TextBox.Text) || !double.TryParse(volume_TextBox.Text, out volume_out)) { MessageBox.Show("容量输入不合法,必须为数字", "系统提示"); volume_TextBox.Focus(); return(false); } } } return(true); }
private void edit_Button_Click(object sender, RoutedEventArgs e) { if (!validate()) { return; } ComboBoxItem selectedItem = (ComboBoxItem)liquidType_comboBox.SelectedItem; List <SystemFluidConfiguration> recordList = new List <SystemFluidConfiguration>(); short typeId = ((LiquidType)selectedItem.DataContext).TypeId; foreach (DataGridCellInfo cell in dataGrid1.SelectedCells) { int columnIndex = CommFuntion.GetDataGridCellColumnIndex(cell); int rowIndex = CommFuntion.GetDataGridCellRowIndex(cell); SystemFluidConfiguration liquidConfiguration = new SystemFluidConfiguration(); liquidConfiguration.Position = rowIndex; liquidConfiguration.Grid = columnIndex; liquidConfiguration.ItemType = typeId; if (volume_TextBox.IsVisible) { liquidConfiguration.Volume = double.Parse(volume_TextBox.Text); } recordList.Add(liquidConfiguration); } bool result = controller.EditByTypeId(recordList, typeId); WanTai.Controller.LogInfoController.AddLogInfo(LogInfoLevelEnum.Operate, "修改:" + ((LiquidType)selectedItem.DataContext).TypeName + " " + (result == true ? "成功" : "失败"), SessionInfo.LoginName, this.GetType().ToString(), null); if (result) { MessageBox.Show("保存成功!", "系统提示"); } else { MessageBox.Show("保存失败!", "系统提示"); } this.Close(); }
private void save_Click(object sender, System.Windows.RoutedEventArgs e) { if (!validate()) { return; } bool result = false; ComboBoxItem selectedItem = (ComboBoxItem)liquidType_comboBox.SelectedItem; foreach (DataGridCellInfo cell in dataGrid1.SelectedCells) { int columnIndex = CommFuntion.GetDataGridCellColumnIndex(cell); int rowIndex = CommFuntion.GetDataGridCellRowIndex(cell); SystemFluidConfiguration liquidConfiguration = new SystemFluidConfiguration(); liquidConfiguration.ItemID = WanTaiObjectService.NewSequentialGuid(); liquidConfiguration.Position = rowIndex; liquidConfiguration.Grid = columnIndex; liquidConfiguration.ItemType = ((LiquidType)selectedItem.DataContext).TypeId; if (volume_TextBox.IsVisible) { liquidConfiguration.Volume = double.Parse(volume_TextBox.Text); } result = controller.Create(liquidConfiguration); if (!result) { WanTai.Controller.LogInfoController.AddLogInfo(LogInfoLevelEnum.Operate, "新建:" + ((LiquidType)selectedItem.DataContext).TypeName + " 失败", SessionInfo.LoginName, this.GetType().ToString(), null); MessageBox.Show("保存失败!", "系统提示"); break; } } if (result) { WanTai.Controller.LogInfoController.AddLogInfo(LogInfoLevelEnum.Operate, "新建:" + ((LiquidType)selectedItem.DataContext).TypeName + " 成功", SessionInfo.LoginName, this.GetType().ToString(), null); MessageBox.Show("保存成功!", "系统提示"); } this.Close(); }