public bool Save(WashFlow washFlow, out string err) { err = ""; using (var db = new MyDbContext()) { var p = db.WashFlows.Count(); if (washFlow.Id > 0) { db.WashFlows.Update(washFlow); db.SaveChanges(); return(true); } if (p >= 20) { err = "最多只能保存20条记录,请删除不常用记录后在保存"; return(false); } if (db.WashFlows.Count(x => x.Name == washFlow.Name) > 0) { err = "名称已存在,请换个名称"; return(false); } db.WashFlows.Add(washFlow); db.SaveChanges(); return(true); } }
public bool Remove(WashFlow flow) { using (var db = new MyDbContext()) { db.WashFlows.Remove(flow); db.SaveChanges(); return(true); } }
public bool Save(WashFlow flow, DateTime startTime, DateTime endTime) { var record = GetBy(flow, startTime, endTime); using (var db = new MyDbContext()) { db.WashRecords.Add(record); db.SaveChanges(); return(true); } }
public WashRecord GetBy(WashFlow flow, DateTime startTime, DateTime endTime) { return(new WashRecord() { Name = flow.Name, ConcentrateSpeed = flow.ConcentrateSpeed, ConcentrateVolume = flow.ConcentrateVolume, ConcentrateTimes = flow.ConcentrateTimes, CollectSpeed = flow.CollectSpeed, CollectTimes = flow.CollectTimes, CollectVolume = flow.CollectVolume, WashSpeed = flow.WashSpeed, WashVolume = flow.WashVolume, StartTime = startTime, EndTime = endTime }); }
private WashFlow GetWashFlow() { var name = txtName.Text; int washSpeed = int.TryParse(txtWashSpeed.Text, out washSpeed) ? washSpeed : -1; int washVolume = int.TryParse(txtWashVolume.Text, out washVolume) ? washVolume : -1; int conVolume = int.TryParse(txtConVolume.Text, out conVolume) ? conVolume : -1; int conSpeed = int.TryParse(txtConSpeed.Text, out conSpeed) ? conSpeed : -1; int conTimes = int.TryParse(txtConTimes.Text, out conTimes) ? conTimes : -1; int colVolume = int.TryParse(txtColVolume.Text, out colVolume) ? colVolume : -1; int colSpeed = int.TryParse(txtColSpeed.Text, out colSpeed) ? colSpeed : -1; int colTimes = int.TryParse(txtColTimes.Text, out colTimes) ? colTimes : -1; if (string.IsNullOrEmpty(name)) { new TopPopup().Show("流程名称不能为空"); return(null); } if (washSpeed <= 0 || washSpeed > 50) { new TopPopup().Show("加液速度范围为0至50"); return(null); } if (washVolume <= 0) { new TopPopup().Show("加液量必须大于0"); return(null); } if (conVolume <= 0) { new TopPopup().Show("浓缩体积必须大于0"); return(null); } if (conSpeed <= 0 || conSpeed > 50) { new TopPopup().Show("浓缩速度范围为0至50"); return(null); } if (conTimes <= 0) { new TopPopup().Show("浓缩次数必须大于0"); return(null); } if (colVolume <= 0) { new TopPopup().Show("收集体积必须大于0"); return(null); } if (colSpeed <= 0 || colSpeed > 50) { new TopPopup().Show("收集速度范围为0至50"); return(null); } if (colTimes <= 0) { new TopPopup().Show("收集次数必须大于0"); return(null); } var washFlow = new WashFlow(); washFlow.Name = name; washFlow.WashVolume = washVolume; washFlow.WashSpeed = washSpeed; washFlow.ConcentrateSpeed = conSpeed; washFlow.ConcentrateVolume = conVolume; washFlow.ConcentrateTimes = conTimes; washFlow.CollectTimes = colTimes; washFlow.CollectSpeed = colSpeed; washFlow.CollectVolume = colVolume; washFlow.FlowType = FlowEnum.Full; washFlow.WashPumpDirection = tsPump1.IsOn ? DirectionEnum.Out : DirectionEnum.In; washFlow.ConcentratePumpDirection = tsPump2.IsOn ? DirectionEnum.Out : DirectionEnum.In; washFlow.CollectionPumpDirection = tsPump3.IsOn ? DirectionEnum.Out : DirectionEnum.In; var ctx = this.DataContext as WashFlow; if (ctx != null) { washFlow.Id = ctx.Id; } return(washFlow); }