using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Action.ChemicalWeighing.FreeDb.DBEntity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.LjPlanning { public class DownToDatabase { public DownToDatabase() { } public DownToDatabase(DbMCControl _materialGridControl) { DataGridView clientGridView = _materialGridControl.BaseControl as DataGridView; //验证是否选中某物料 if (clientGridView.SelectedRows.Count != 1) { //MessageBox.Show("请选择要修改的数据", Mesnac.Basic.LanguageHelper.Caption, // MessageBoxButtons.OK, MessageBoxIcon.Information); //this._runtime.IsReturn = true; return; } var dataGridViewRow = clientGridView.SelectedRows[0]; var id = Convert.ToInt32(dataGridViewRow.Cells["Id"].Value); LjPlanningEntity ljPlanningEntity = FreeSqlUnit.Instance.Select().Where(x => x.Id == id).ToOne(); LjFormulaEntity ljFormulaEntity = FreeSqlUnit.Instance.Select().Where(x => x.Id == ljPlanningEntity.FormulaId).ToOne(); List ljFormulaDetailEntity = FreeSqlUnit.Instance.Select().Where(x => x.FormulaId == ljFormulaEntity.Id).ToList(); FreeSqlUnit.Instance.Delete().Where(x => x.PlanId == ljPlanningEntity.Id && x.FormulaId == ljFormulaEntity.Id).ExecuteDeleted(); LjFormulaDownEntity ljFormulaDownEntity = new LjFormulaDownEntity() { CbSiloC = ljFormulaEntity.CbSiloC, CbSiloH = ljFormulaEntity.CbSiloH, CbWeterH = ljFormulaEntity.CbWeterH, CreateTime = ljFormulaEntity.CreateTime, FormulaId = ljFormulaEntity.Id, FormulaName = ljFormulaEntity.FormulaName, FormulaNo = ljFormulaEntity.FormulaNo, FormulaVersion = ljFormulaEntity.FormulaVersion, IsEnable = ljFormulaEntity.IsEnable, PlanId = ljPlanningEntity.Id, RecipeTypeId = ljFormulaEntity.RecipeTypeId, RecipeTypeName = ljFormulaEntity.RecipeTypeName, Status = ljFormulaEntity.Status, Unit = ljFormulaEntity.Unit, UpdateTime = ljFormulaEntity.UpdateTime }; FreeSqlUnit.Instance.Insert(ljFormulaDownEntity).ExecuteIdentity(); List ljFormulaDetailDownEntity = new List(); LjFormulaDetailDownEntity singleEntity; foreach (LjFormulaDetailEntity Entity in ljFormulaDetailEntity) { singleEntity = new LjFormulaDetailDownEntity() { ActionCode = Entity.ActionCode, ActionId = Entity.ActionId, ActionName = Entity.ActionName, BinNo = Entity.BinNo, CbCopyC = Entity.CbCopyC, CbCopyH = Entity.CbCopyH, CpSiloH = Entity.CpSiloH, FormulaId = Entity.FormulaId, FormulaType = Entity.FormulaType, Machine = Entity.Machine, MachineType = Entity.MachineType, MId = Entity.MId, MName = Entity.MName, SetTolerance = Entity.SetTolerance, SetValue = Entity.SetValue, Speed = Entity.Speed, StockMaterialId = Entity.StockMaterialId, Temp = Entity.Temp, TimeInfo = Entity.TimeInfo, Tolerance = Entity.Tolerance, Weight = Entity.Weight }; ljFormulaDetailDownEntity.Add(singleEntity); } FreeSqlUnit.Instance.Insert(ljFormulaDetailDownEntity).ExecuteIdentity(); } } }