private List<DB_Talk.Model.m_PRIClock> getModel() { List<DB_Talk.Model.m_PRIClock> lst = new List<DB_Talk.Model.m_PRIClock>(); for (int i = 0; i < this.dgvList.Rows.Count; i++) { DB_Talk.Model.m_PRIClock model = new DB_Talk.Model.m_PRIClock(); DB_Talk.Model.m_PRIClock modelTag = dgvList.Rows[i].Tag as DB_Talk.Model.m_PRIClock; if (modelTag != null) { model.ID = modelTag.ID; model.i_Level = modelTag.i_Level; model.BoxID = modelTag.BoxID; } //时钟源类型 model.i_Type = int.Parse(dgvList.Rows[i].Cells["colType"].Value.ToString()); //时钟源端口 if (model.i_Type == MBoxSDK.ConfigSDK.EnumPriClockType.E1.GetHashCode()) model.i_Port = int.Parse(dgvList.Rows[i].Cells["colE1Number"].Value.ToString()); if(model.i_Type == MBoxSDK.ConfigSDK.EnumPriClockType.E1.GetHashCode() && (model.i_Port==0)) throw new Exception("级别为【" + model.i_Level + "】的时钟源未选择正确的E1端口!"); int portNum = int.Parse(dgvList.Rows[i].Cells["colE1Number"].Value.ToString()); if (portNum>0 && model.i_Type!= MBoxSDK.ConfigSDK.EnumPriClockType.E1.GetHashCode()) throw new Exception("级别为【" + model.i_Level + "】的时钟源未选择正确的时钟源类型!"); lst.Add(model); } List<DB_Talk.Model.m_PRIClock> lstTemp = new List<DB_Talk.Model.m_PRIClock>(); lstTemp = lst.Where(w => w.i_Type ==MBoxSDK.ConfigSDK.EnumPriClockType.无.GetHashCode()).ToList(); if (lstTemp.Count == 4) throw new Exception("4个时钟源类型不能同时为无!"); // CommControl.MessageBoxEx.MessageBoxEx.Show("4个时钟源类型不能同时为无!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return lst; //if(lst) }
/// <summary> /// 获得数据列表 /// </summary> public List<DB_Talk.Model.m_PRIClock> DataTableToList(DataSet ds) { List<DB_Talk.Model.m_PRIClock> modelList = new List<DB_Talk.Model.m_PRIClock>(); if (ds == null) return modelList; DataTable dt = ds.Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DB_Talk.Model.m_PRIClock model; for (int n = 0; n < rowsCount; n++) { model = new DB_Talk.Model.m_PRIClock(); if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="") { model.ID=int.Parse(dt.Rows[n]["ID"].ToString()); } if(dt.Rows[n]["BoxID"]!=null && dt.Rows[n]["BoxID"].ToString()!="") { model.BoxID=int.Parse(dt.Rows[n]["BoxID"].ToString()); } if(dt.Rows[n]["i_Level"]!=null && dt.Rows[n]["i_Level"].ToString()!="") { model.i_Level=int.Parse(dt.Rows[n]["i_Level"].ToString()); } if(dt.Rows[n]["i_Type"]!=null && dt.Rows[n]["i_Type"].ToString()!="") { model.i_Type=int.Parse(dt.Rows[n]["i_Type"].ToString()); } if(dt.Rows[n]["i_Port"]!=null && dt.Rows[n]["i_Port"].ToString()!="") { model.i_Port=int.Parse(dt.Rows[n]["i_Port"].ToString()); } if(dt.Rows[n]["vc_Memo"]!=null && dt.Rows[n]["vc_Memo"].ToString()!="") { model.vc_Memo= dt.Rows[n]["vc_Memo"].ToString(); } if(dt.Rows[n]["i_Flag"]!=null && dt.Rows[n]["i_Flag"].ToString()!="") { model.i_Flag=int.Parse(dt.Rows[n]["i_Flag"].ToString()); } modelList.Add(model); } } return modelList; }
private void AddPRIClolck(DB_Talk.Model.m_Box boxmodel) { DB_Talk.BLL.m_PRIClock BLL=new DB_Talk.BLL.m_PRIClock(); for (int i = 0; i < 4; i++) { List<DB_Talk.Model.m_PRIClock> lst = BLL.GetModelList( string.Format(" i_Flag=0 and BoxID='{0}' and i_Level='{1}'",boxmodel.ID,i)); if (lst.Count == 0) { DB_Talk.Model.m_PRIClock model = new DB_Talk.Model.m_PRIClock(); model.BoxID = boxmodel.ID; model.i_Level = i; model.i_Type = MBoxSDK.ConfigSDK.EnumPriClockType.内部.GetHashCode(); model.i_Port =0; BLL.Add(model); } } }
/// <summary> /// 根据条件得到一个对象实体 /// </summary> public DB_Talk.Model.m_PRIClock GetModel(string strWhere) { StringBuilder strSql=new StringBuilder(); strSql.Append(" select top 1 "); strSql.Append(" ID, BoxID, i_Level, i_Type, i_Port, vc_Memo, i_Flag "); strSql.Append(" from m_PRIClock "); if(strWhere.Trim()!="") { strSql.Append(" where "+strWhere); } DB_Talk.Model.m_PRIClock model=new DB_Talk.Model.m_PRIClock(); DataSet ds=GetDataSet(strSql.ToString()); if(ds!=null && ds.Tables[0].Rows.Count>0) { model=DataTableToList(ds)[0]; return model; } else { return null; } }