private void BtnDelete_Click(object sender, RoutedEventArgs e) { if (DGMain.SelectedItems.Count == 0) { MessageBox.Show("请选中一条数据"); return; } else { if (MessageBox.Show("是否确认删除?对应的套料信息和工序监控任务都可能被删除", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { List <StationCache> list = new List <StationCache>(); List <StepTrace> steptrace = new List <StepTrace>(); CutPlan cutplan = new CutPlan(); foreach (var item in DGMain.SelectedItems) { list.Add((StationCache)item); } var ids = list.Select(t => t.Id.Value).ToList(); var stationcachesResult = AppSession.Dal.GetCommonModelByCondition <StationCache>($" where id in ({string.Join(",", ids)})"); if (!stationcachesResult.Success) { MessageBox.Show("管材缓存信息不存在!"); } var stepTraceIds = stationcachesResult.Data.Where(t => t.stepTraceId != null).Select(t => t.stepTraceId).ToList(); using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); connection.DeleteList <CutPlan>("where stationCacheId in @stationCacheIds", new { stationCacheIds = ids }, tran); if (stepTraceIds.Count > 0) { connection.DeleteList <StepTrace>("where id in @ids", new { ids = stepTraceIds }, tran); } connection.DeleteList <StationCache>("where id in @ids", new { ids = ids }, tran); tran?.Commit(); } catch (Exception ex) { tran?.Rollback(); Logger.Log($"删除管材缓存的数据候发生异常,原因:{ex.Message}", LogLevel.Exception, ex); MessageBox.Show("删除失败"); } } Query(); } } }
private void btn_Change_Click(object sender, RoutedEventArgs e) { if (DGDetail.SelectedItem == null) { MessageBox.Show("请先选中一条数据!"); return; } if (DGDetail.SelectedItems.Count > 1) { MessageBox.Show("每次只能选择一条"); return; } else { CutPlan cutplan = (CutPlan)DGDetail.SelectedItem; WinCutPlanAddOrEdit winCpAdd = new WinCutPlanAddOrEdit(cutplan.Id); winCpAdd.ShowDialog(); Query(); } }
private void Init() { var CutPlanStatusList = CommonHelper.EnumListDic <CutPlanStatus>(""); cbx_Status.ItemsSource = CutPlanStatusList; cbx_Status.DisplayMemberPath = "Value"; cbx_Status.SelectedValuePath = "Key"; if (Id == null) { //新增 } else { BllResult <List <CutPlan> > result = AppSession.Dal.GetCommonModelByCondition <CutPlan>($"where id ={Id}"); if (result.Success) { CurrentCutPlan = result.Data[0]; } else { MessageBox.Show($"未能获取到id为{Id},错误消息:{result.Msg}"); } } }
public void send_DataBase(List <OutPutValue> outlist) { if (outlist == null || outlist.Count == 0) { MessageBox.Show("切割尺寸为空,无法导出"); return; } //套料结果 List <CutPlan> cutPlanList = new List <CutPlan>(); //工单表更新语句 List <string> pipeOrderUpdate = new List <string>(); //物料缓存表更新语句 List <string> stationCacheUpdate = new List <string>(); for (int index = 0; index < outlist.Count; index++) { if (!int.TryParse(outlist[index].material.WuLiaoHao, out int stationCacheId)) { MessageBox.Show("物料号转化数字失败,不能存入数据库"); return; } if (!decimal.TryParse(outlist[index].material.WaiJing, out decimal diameter)) { MessageBox.Show("外径转化数字失败,不能存入数据库"); return; } if (!decimal.TryParse(outlist[index].material.BiHou, out decimal thickness)) { MessageBox.Show("壁厚转化数字失败,不能存入数据库"); return; } if (!int.TryParse(outlist[index].material.CaiZhi, out int wcsProductType)) { MessageBox.Show("材质编号转化数字失败,不能存入数据库"); return; } //if (!int.TryParse(outlist[index].material.ZuDui, out int AssemblyStation))//cf //{ // MessageBox.Show("组队工位转化数字失败,不能存入数据库"); // return; //} for (int j = 0; j < outlist[index].productList.Count; j++) { if (!int.TryParse(outlist[index].productList[j].GuanJianBianHao, out int WONumber)) { MessageBox.Show("管件编号转化数字失败,不能存入数据库"); return; } pipeOrderUpdate.Add($" UPDATE pipe_order SET status = {StationCacheStatus.已经套料.GetIndexString()} WHERE id = {WONumber} "); CutPlan cutPlan = new CutPlan(); //cutPlan.WONumber = WONumber.ToString(); cutPlan.stationCacheId = stationCacheId; //原材料ID cutPlan.WONumber = outlist[index].productList[j].Code; //cf cutPlan.AssemblyStation = outlist[index].productList[j].AssemblyStation; //cf cutPlan.WcsProductType = wcsProductType; cutPlan.MaterialLength = outlist[index].material.length; cutPlan.Diameter = diameter; cutPlan.Thickness = thickness; cutPlan.Length = outlist[index].productList[j].length; cutPlan.Status = CutPlanStatus.初始.GetIndexInt(); cutPlanList.Add(cutPlan); } stationCacheUpdate.Add($"UPDATE station_cache SET status = { StationCacheStatus.已经套料.GetIndexString()} WHERE id = { stationCacheId }"); } string where = " where WONumber IN ('" + string.Join(" ','", cutPlanList.Select(t => t.WONumber).ToList()) + "')"; var countResult = AppSession.Dal.GetCommonModelCount <CutPlan>(where); if (!countResult.Success) { MessageBox.Show($"发送套料结果到数据库的时候,查询数据库发生错误,原因:{countResult.Msg}"); return; } if (countResult.Data > 0) { MessageBox.Show($"套料结果在数据库中已存在,不要反复保存!"); return; } using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); foreach (var cutPlan in cutPlanList) { connection.Insert <CutPlan>(cutPlan, transaction: tran); } foreach (var item in pipeOrderUpdate) { connection.Execute(item, transaction: tran); } foreach (var item in stationCacheUpdate) { connection.Execute(item, transaction: tran); } tran.Commit(); } catch (Exception ex) { tran?.Rollback(); MessageBox.Show($"发送套料结果到数据库的时候,发生异常,原因:{ex.Message}"); return; } } MessageBox.Show("套料结果发送到数据库成功!"); }