示例#1
0
        public static void BindTable(IDialogVisualizerService windowService, MDataTable dt, string title)
        {
            if (dt == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(title))
            {
                title = string.Format("TableName : {0}    Rows: {1}    Columns: {2}", dt.TableName, dt.Rows.Count, dt.Columns.Count);
            }
            Form         form = FormCreate.CreateForm(title);
            DataGridView dg   = FormCreate.CreateGrid(form);

            try
            {
                if (dt.Rows.Count > 200)
                {
                    dt = dt.Select(200, null);
                }
                //插入行号
                dt.Columns.Insert(0, new MCellStruct("[No.]", System.Data.SqlDbType.Int));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i][0].Value = i + 1;
                }
                dt.Bind(dg);
                AutoSizeColumn(dg);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

            windowService.ShowDialog(form);
        }
示例#2
0
        private void LoadData()
        {
            MDataRow row;

            using (MAction action = new MAction(tableName))
            {
                row = action.Data;
                dt  = action.Select(Pager.PageIndex, Pager.PageSize, "order by " + action.Data.PrimaryCell.ColumnName + " desc");
                OutDebugSql(action.DebugInfo, true);
                dt.Columns["UserID"].Description = "用户标识";//增加这一行,是想说明:Winform下通过修改描述可以改变显示的列名
            }
            using (MAction action = new MAction(row))
            {
            }
            if (dt != null && dt.Rows.Count > 0)
            {
                if (txtUserID.Text == "")
                {
                    dt.Rows[0].SetToAll(this);
                }
            }
            //   dgView.DataSource = dt.ToDataTable();
            //
            dt.Bind(dgView);
            Pager.DrawControl(dt.RecordsAffected);
        }
示例#3
0
        //protected override void BeforeInvoke(string methodName)
        //{
        //    if(methodName=="About")
        //    {
        //        Write("非法请示");
        //        CancelInvoke = true;
        //        CancelLoadHtml = true;
        //    }
        //    base.BeforeInvoke(methodName);
        //}
        #region Controller方法
        public override void Default()
        {
            if (IsHttpGet)
            {
                InitData();
                MDataTable utTable = null;
                using (UserType ut = new UserType())
                {
                    utTable = ut.Select();
                }

                // View.OnForeach += new XHtmlAction.SetForeachEventHandler(View_OnForeach);
                // utTable.Bind(View);//取usertypeView或defaultView节点。

                utTable.Bind(View, "ddl" + utTable.TableName);//绑定下拉框,指定节点名称。(用表名,是为了不写死ddlUserType)

                MDataTable dt;
                //UI 操作View
                using (Users demo = new Users())
                {
                    if (demo.Fill())
                    {
                        demo.UI.SetToAll(View);

                        View.LoadData(demo, "");
                    }
                    Pager pager = new Pager(View);
                    //demo.SetSelectColumns("id", "count(id) as c");
                    //dt = demo.Select(2, 3);
                    dt = demo.Select(pager.PageIndex, pager.PageSize);
                    pager.Bind(dt.RecordsAffected);//绑定分页控件。
                }
                #region 表关联
                dt.JoinOnName = "UserType";
                dt.Conn       = Connection.XmlConn;//这里玩的花了一点(Users表是txt数据库,UserType是xml数据库)
                dt            = dt.Join("UserType", "ID", "TypeName");
                #endregion
                View.OnForeach += new XHtmlAction.SetForeachEventHandler(View_OnForeach); //formater
                dt.Bind(View);                                                            //取UsersView或defaultView节点。
            }
            //if (IsHttpPost)
            //{
            //    BtnEvent();
            //}

            //View 操作 UI
            //View.LoadData(ut.Select<UserType>());
            //View.SetForeach();

            // View.LoadData(dt.Rows[dt.Rows.Count - 1], "txt");// 自动格式化标签。

            //View.LoadData(dt);//装载数据
            //
            //View.SetForeach("divView2", SetType.InnerXml);
            //View.SetForeach("divView3", "自定义:{0} -${Name} -{2}<br />");
        }
示例#4
0
 void LoadData()
 {
     using (MAction action = new MAction("Users"))
     {
         dt = action.Select();
     }
     // dt.Columns[0].Description = "用户ID";
     // dt.Columns[1].Description = "用户名";
     dt.Bind(dgvTable);
     OutProperty();
 }
示例#5
0
        private void btnGetUpdate_Click(object sender, EventArgs e)
        {
            MDataTable dt2 = dt.GetChanges();

            if (dt2 != null && dt2.Rows.Count > 0)
            {
                dt2.Bind(dgvTable);
            }
            else
            {
                rtxtText.Text = "没有修改的数据!";
            }
        }
示例#6
0
        private void btnCreateData_Click(object sender, EventArgs e)
        {
            MDataTable dt = new MDataTable("MyTable");

            dt.Columns.Add("ID", SqlDbType.Int, true, false, 11, true, null);
            dt.Columns.Add("Name");
            dt.Columns.Add("Password");
            mdc = dt.Columns;
            for (int i = 0; i < 10; i++)
            {
                dt.NewRow(true).Set(0, i + 1).Set(1, "Name" + i).Set(2, i);
            }
            dt.Bind(dgvData);
        }
示例#7
0
 private void btnSetOrdinal_Click(object sender, EventArgs e)
 {
     //把第二位的列移前
     mdc.SetOrdinal(mdc[1].ColumnName, 0);
     if (mdc.Table != null && mdc.Table.Rows.Count > 1)
     {
         new MDataTable().Bind(dgvData);
         MDataTable dt = mdc.Table.Clone();
         dt.Bind(dgvData);
     }
     else
     {
         mdc.ToTable().Bind(dgvData);
     }
 }
示例#8
0
        private void btnTransation_Click(object sender, EventArgs e)
        {
            //for (int i = 0; i < 100; i++)
            //{


            MDataTable dt   = null;
            string     guid = Guid.NewGuid().ToString();

            using (MAction action = new MAction("Users"))
            {
                bool result = false;
                action.SetTransLevel(IsolationLevel.ReadCommitted); //可设置的事务级别,一般可以不用设置
                action.BeginTransation();                           //设置开启事务标识
                action.Set("Name", guid.Substring(1, 5));
                action.Set("Password", "123456");
                int id = 0;
                if (action.Insert())    //第一个执行时,事务才被加载
                {
                    id = action.Get <int>(0);
                    action.ResetTable("Article");
                    action.Set("UserID", id);
                    action.Set("Title", guid.Substring(3, 5));
                    action.Set("Content", guid.Substring(5, 5));
                    action.Set("PubTime", DateTime.Now);
                    result = action.Insert(InsertOp.None);
                }
                else
                {
                    action.RollBack();    //手工回滚
                }
                action.EndTransation();   //提交事务
                if (result)
                {
                    LoadData("UserID=" + id);
                }
                OutSql(action.DebugInfo);
            }
            if (dt != null)
            {
                dt.Bind(dgvView);
            }
            //}
        }
示例#9
0
        private void btnShowInfo_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            MDataTable    dt = null;

            using (MAction action = new MAction("Article"))
            {
                sb.Append("AllowInsertID:");
                sb.AppendLine(action.AllowInsertID.ToString());

                sb.Append("ConnectionString:");
                sb.AppendLine(action.ConnectionString);

                sb.Append("DalType:");
                sb.AppendLine(action.DalType.ToString());

                sb.Append("DalVersion:");
                sb.AppendLine(action.DalVersion);

                sb.Append("DebugInfo:");
                sb.AppendLine(action.DebugInfo);

                sb.Append("RecordsAffected:(通常在执行一个命令后,返回受影响的行数)");
                sb.AppendLine(action.RecordsAffected.ToString());

                sb.Append("TableName:");
                sb.AppendLine(action.TableName);

                sb.Append("TimeOut:");
                sb.AppendLine(action.TimeOut.ToString());

                sb.Append("UI对象:");
                sb.AppendLine(action.UI.ToString());

                dt = action.Data.Columns.ToTable();
            }
            dt.Bind(dgvView);
            rtxtSql.Text = sb.ToString();
        }
示例#10
0
 public void LoadData()
 {
     dt = BH.GetNovels();
     dt.Bind(dgvList);
 }