private void Form1_Load(object sender, EventArgs e) { MDataRow row = new MDataRow(); row.LoadFrom("{name:'现在是夜里快3点了!'}"); row.SetToAll(this);//第三方控件,注册类名和属性之后,也能用自动赋值了。 }
private void Form1_Load(object sender, EventArgs e) { MDataRow row = new MDataRow(); row.LoadFrom("{name:'妹子你在哪?'}"); row.SetToAll(this);//继承自IUIValue的接口的控件,都可以用自动取值或赋值功能。 }
private void btnInsert_Click(object sender, EventArgs e) { MDataRow row = MDataRow.CreateFrom(new UsersBean()); row.LoadFrom(false, this); DBFast.Insert <UsersBean>(row.ToEntity <UsersBean>(), InsertOp.ID, chbInsertID.Checked); LoadData(); OutMsg(); }
public bool Insert(bool isOpenTrans) { MDataCell cell = _Row.PrimaryCell; if (IsCanDoInsertCheck((cell.IsNullOrEmpty || cell.Struct.IsAutoIncrement || cell.Struct.IsPrimaryKey) ? 1 : 0)) { //判断是否需要增加自增加id if (!cell.Struct.IsCanNull && (cell.Struct.IsAutoIncrement || cell.Struct.IsPrimaryKey)) { #region 给主键赋值 DataGroupType group = DataType.GetGroup(cell.Struct.SqlType); string existWhere = cell.ColumnName + (group == DataGroupType.Number ? "={0}" : "='{0}'"); if (cell.IsNull || cell.State == 0 || cell.StringValue == "0" || Exists(string.Format(existWhere, cell.Value)))//这里检测存在,避免id重复 { switch (group) { case DataGroupType.Number: cell.Value = NextID; break; case DataGroupType.Guid: cell.Value = Guid.NewGuid(); break; case DataGroupType.Text: cell.Value = Guid.NewGuid().ToString(); break; default: return((bool)Error.Throw("first column value can't be null")); } } if (group == DataGroupType.Number || group == DataGroupType.Guid) //再检测是否已存在 { if (!isOpenTrans && Exists(string.Format(existWhere, cell.Value))) //事务时,由于自动补id,避开检测,提升性能 { Error.Throw("first column value must be unique:(" + cell.ColumnName + ":" + cell.Value + ")"); } else if (group == DataGroupType.Number) { maxID = (int)cell.Value; } } #endregion } CheckFileChanged(true); _Row.SetState(0);//状态重置,避免重复使用插入! MDataRow newRow = Table.NewRow(true); newRow.LoadFrom(_Row); _insertRows.Add(newRow);//插入引用,内存表有数据,还没写文章! needToSaveState = needToSaveState > 1 ? 2 : 1; return(true); } return(false); }
private void btnUpdate_Click(object sender, EventArgs e) { MDataRow row = MDataRow.CreateFrom(new UsersBean()); row.LoadFrom(false, this); DBFast.Update <UsersBean>(row.ToEntity <UsersBean>()); LoadData(); OutMsg(); }
private void btnUpdate_Click(object sender, EventArgs e) { using (UsersBean ub = new UsersBean()) { MDataRow row = MDataRow.CreateFrom(ub); row.LoadFrom(false, this); row.SetToEntity(ub); ub.Update(); } LoadData(); OutMsg(); }
public bool Fill(object where) { CheckFileChanged(true); MDataRow row = Table.FindRow(where); if (row != null) { _Row.LoadFrom(row); _Row.SetState(0);//查询时,后续会定位状态为1 return(true); } return(false); }
private void btnInsert_Click(object sender, EventArgs e) { using (UsersBean ub = new UsersBean()) { MDataRow row = MDataRow.CreateFrom(ub); row.LoadFrom(false, this); row.SetToEntity(ub); if (ub.Insert(InsertOp.ID, chbInsertID.Checked)) { row.SetToAll(this); } } LoadData(); OutMsg(); }
private void Form1_Load(object sender, EventArgs e) { MDataRow row = new MDataRow(); row.LoadFrom("{id:1,name:'hello'}"); MDataCell cell = row[0]; StringBuilder sb = new StringBuilder(); sb.AppendLine("ColumnName:" + cell.ColumnName); sb.AppendLine("Struct.SqlType:" + cell.Struct.SqlType); sb.AppendLine("IsNull:" + cell.IsNull); sb.AppendLine("IsNullOrEmpty:" + cell.IsNullOrEmpty); sb.AppendLine("State:" + cell.State + " (0:不可插入和更新;1:仅可以插入;2:可插入可更新)"); sb.AppendLine("Value:" + cell.Value); sb.AppendLine("------------"); cell = row[1]; sb.AppendLine("ColumnName:" + cell.ColumnName); sb.AppendLine("Struct.SqlType:" + cell.Struct.SqlType); sb.AppendLine("Value:" + cell.Value); cell.Struct.SqlType = SqlDbType.Int;//修改数据类型 sb.AppendLine("修改结构:Struct.SqlType:" + cell.Struct.SqlType); sb.Append("FixValue():"); try { // AppConfig.Log.IsWriteLog = true; Exception err; if (!cell.FixValue(out err)) //修改该值 { sb.AppendLine(err.Message); } } catch (Exception er) { sb.AppendLine(er.Message); } sb.AppendLine("修正后Value:" + cell.Value); rtxtText.Text = sb.ToString(); }
private void btnGetFromAll_Click(object sender, EventArgs e) { row.SetState(0); row.LoadFrom(false, this);//该方法可以从各式各样的场景中批量获得值,如Json,entity,xml,dictionary等 row.ToTable().Bind(dgvRow); }