/// <summary> /// 增加一条数据 /// </summary> public bool Add(InstME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Inst("); strSql.Append("instID,instCode,instObj,vehicleAlloc)"); strSql.Append(" values ("); strSql.Append("@instID,@instCode,@instObj,@vehicleAlloc)"); SqlParameter[] parameters = { new SqlParameter("@instID", SqlDbType.NVarChar,50), new SqlParameter("@instCode", SqlDbType.Int,4), new SqlParameter("@instObj", SqlDbType.Xml,-1), new SqlParameter("@vehicleAlloc", SqlDbType.Int,4)}; parameters[0].Value = model.instID; parameters[1].Value = model.instCode; parameters[2].Value = model.instObj; parameters[3].Value = model.vehicleAlloc; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到分配给指定小车的所有指令 /// </summary> /// <param name="vehicleNo">小车编号</param> /// <returns></returns> public IList<InstME> GetInstList(int vehicleNo) { List<InstME> instList = new List<InstME>(); StringBuilder strSql = new StringBuilder(); strSql.AppendFormat(@"vehicleAlloc = {0} ",vehicleNo); DataSet ds = _instDAL.GetList(strSql.ToString()); if(ds.Tables.Count>0) { foreach(DataRow rw in ds.Tables[0].Rows) { InstME inst = new InstME(); inst.instID = rw["instID"].ToString(); inst.instCode = int.Parse(rw["instCode"].ToString()); inst.vehicleAlloc = int.Parse(rw["vehicleAlloc"].ToString()); inst.instObj = rw["instObj"].ToString(); instList.Add(inst); } } return instList; }
/// <summary> /// 添加指令 /// </summary> /// <param name="instModel"></param> /// <returns></returns> public bool AddInst(InstME instModel) { return _instDAL.Add(instModel); }
private void button6_Click(object sender, EventArgs e) { TaskME taskM = _taskBll.GetFirstUnexeAutoTask(); BaseTaskInfo taskObj = TaskSerializer.Deserialize(taskM.taskCode, taskM.taskObj); if(taskObj != null) { string strXML = TaskSerializer.Serialize(taskObj); this.richTextBox1.AppendText(strXML + "\r\n"); StringBuilder strBuilder = new StringBuilder(); strBuilder.AppendLine("提取任务:"); strBuilder.AppendLine(taskM.taskObj); this.richTextBox1.AppendText(strBuilder.ToString()); InstMovL instMovl = new InstMovL(); instMovl.targetL = 2; instMovl.instComment = "移动到2层"; strXML = InstSerializer.Serialize(instMovl); this.richTextBox1.AppendText(strXML + "\r\n"); IList<BaseInstInfo> instList = null; if(0 == TaskDisptach.ParseTask(true, true, ref taskObj, out instList)) { strBuilder.Clear(); strBuilder.AppendLine("任务分解成功"); this.richTextBox1.AppendText(strBuilder.ToString()+"\r\n"); strBuilder.Clear(); ASRSModel.GetInstance().transVehicleDic[taskObj.machineAllocated].FillInstList(instList, taskObj, taskObj.taskID); foreach(BaseInstInfo inst in instList) { if(inst != null) { InstME instM = new InstME(); instM.instID = _instBll.GenerateNewInstID(); instM.instCode = (int)inst.instCode; instM.instObj = InstSerializer.Serialize(inst); try { BaseInstInfo newInst = InstSerializer.Deserialize(instM.instCode, instM.instObj); richTextBox1.AppendText("指令反序列化:" + newInst.instComment + "\r\n"); } catch (System.Exception e1) { richTextBox1.AppendText("反序列化失败:" + e1.Message); } instM.vehicleAlloc = taskObj.machineAllocated; _instBll.AddInst(instM); strBuilder.AppendLine("插入指令:"); strBuilder.AppendLine(instM.instObj); this.richTextBox1.AppendText(strBuilder.ToString()); strBuilder.Clear(); } } } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(InstME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Inst set "); strSql.Append("instCode=@instCode,"); strSql.Append("instObj=@instObj,"); strSql.Append("vehicleAlloc=@vehicleAlloc"); strSql.Append(" where instID=@instID "); SqlParameter[] parameters = { new SqlParameter("@instCode", SqlDbType.Int,4), new SqlParameter("@instObj", SqlDbType.Xml,-1), new SqlParameter("@vehicleAlloc", SqlDbType.Int,4), new SqlParameter("@instID", SqlDbType.NVarChar,50)}; parameters[0].Value = model.instCode; parameters[1].Value = model.instObj; parameters[2].Value = model.vehicleAlloc; parameters[3].Value = model.instID; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public InstME GetModel(string instID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 instID,instCode,instObj,vehicleAlloc from Inst "); strSql.Append(" where instID=@instID "); SqlParameter[] parameters = { new SqlParameter("@instID", SqlDbType.NVarChar,50) }; parameters[0].Value = instID; InstME model = new InstME(); DataSet ds = _dbAssist.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["instID"] != null && ds.Tables[0].Rows[0]["instID"].ToString() != "") { model.instID = ds.Tables[0].Rows[0]["instID"].ToString(); } if (ds.Tables[0].Rows[0]["instCode"] != null && ds.Tables[0].Rows[0]["instCode"].ToString() != "") { model.instCode = int.Parse(ds.Tables[0].Rows[0]["instCode"].ToString()); } if (ds.Tables[0].Rows[0]["instObj"] != null && ds.Tables[0].Rows[0]["instObj"].ToString() != "") { model.instObj=ds.Tables[0].Rows[0]["instObj"].ToString(); } if (ds.Tables[0].Rows[0]["vehicleAlloc"] != null && ds.Tables[0].Rows[0]["vehicleAlloc"].ToString() != "") { model.vehicleAlloc = int.Parse(ds.Tables[0].Rows[0]["vehicleAlloc"].ToString()); } return model; } else { return null; } }