Inheritance: DataGrid
 private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
 {
     if (e.Graphic != null && !e.Graphic.Selected && (sender as FeatureLayer).IsUpdateAllowed(e.Graphic))
     {
         Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
         if ((sender as FeatureLayer).IsUpdateAllowed(e.Graphic))
         {
             if (editor.EditVertices.CanExecute(null))
             {
                 editor.EditVertices.Execute(null);
             }
         }
         else
         if (editor.CancelActive.CanExecute(null))
         {
             editor.CancelActive.Execute(null);
         }
     }
     (sender as FeatureLayer).ClearSelection();
     e.Graphic.Select();
     MyDataGrid.ScrollIntoView(e.Graphic, null);
 }
        protected void Page_Load(Object Src, EventArgs E)
        {
            DataSet ds = new DataSet();

            FileStream   fs     = new FileStream(Server.MapPath("schemadata.xml"), FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(fs);

            ds.ReadXml(reader);
            fs.Close();

            DataView Source = new DataView(ds.Tables[0]);
            // Use the LiteralControl constructor to create a new
            // instance of the class.
            LiteralControl myLiteral = new LiteralControl();

            // Set the LiteralControl.Text property to an HTML
            // string and the TableName value of a data source.
            myLiteral.Text        = "<h6><font face=verdana>Caching an XML Table: " + Source.Table.TableName + " </font></h6>";
            MyDataGrid.DataSource = Source;
            MyDataGrid.DataBind();

            TimeMsg.Text = DateTime.Now.ToString("G");
        }
Exemple #3
0
        /// <summary>
        /// Exports the datagrid to an Excel file with the name of the datasheet provided by the passed in parameter
        /// Exports all field visiable = true
        /// </summary>
        /// <param name="reportName">Name of the datasheet.
        /// </param>
        public void Export(string reportName)
        {
            MyDataGrid.AllowPaging = false;
            //MyDataGrid.AllowCustomPaging = false;
            //MyDataGrid.DataBind();
            ClearChildControls(MyDataGrid);
            AddSpaceControls(MyDataGrid);
            MyDataGrid.EnableViewState = false;
            //Gets rid of the viewstate of the control. The viewstate may make an excel file unreadable.

            CurrentPage.Response.Clear();
            CurrentPage.Response.Buffer = true;

            //This will make the browser interpret the output as an Excel file
            //CurrentPage.Response.AddHeader( "Content-Disposition", "filename="+reportName);
            CurrentPage.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + reportName + ".xls\"");
            CurrentPage.Response.ContentType = "application/vnd.ms-excel";

            //Format
            //header
            MyDataGrid.HeaderStyle.Font.Bold = true;
            MyDataGrid.HeaderStyle.ForeColor = System.Drawing.Color.White;
            MyDataGrid.HeaderStyle.BackColor = System.Drawing.Color.DarkGreen;
            MyDataGrid.HeaderStyle.Height    = 26;

            //Prepares the html and write it into a StringWriter
            StringWriter   stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter   = new HtmlTextWriter(stringWriter);

            FrontDecorator(htmlWriter);
            MyDataGrid.RenderControl(htmlWriter);
            RearDecorator(htmlWriter);

            //Write the content to the web browser
            CurrentPage.Response.Write(stringWriter.ToString());
            CurrentPage.Response.End();
        }
 protected void BindGrid()
 {
     if (!this.IsPostBack)
     {
         string constr = ConfigurationManager.ConnectionStrings["WebAppConnString"].ConnectionString;
         using (MySqlConnection con = new MySqlConnection(constr))
         {
             using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM database.email WHERE email.emailFrom='" + (String)(Session["uemail"]) + "' ORDER BY date DESC  "))
             {
                 using (MySqlDataAdapter sda = new MySqlDataAdapter())
                 {
                     cmd.Connection    = con;
                     sda.SelectCommand = cmd;
                     using (DataTable dt = new DataTable())
                     {
                         sda.Fill(dt);
                         MyDataGrid.DataSource = dt;
                         MyDataGrid.DataBind();
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
        private void MyDataGrid_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (MyDataGrid.Items.Count == 0)
            {
                return;
            }

            int firstLine;

            if (MyDataGrid.SelectedIndex <= 10)
            {
                firstLine = 0;
            }
            else if (MyDataGrid.Items.Count - MyDataGrid.SelectedIndex > 30)
            {
                firstLine = MyDataGrid.SelectedIndex - 10;
            }
            else
            {
                firstLine = MyDataGrid.SelectedIndex;
            }

            MyDataGrid.ScrollIntoView(MyDataGrid.Items[firstLine]);
        }
 protected void BindGrid()
 {
     if (!this.IsPostBack)
     {
         string constr = ConfigurationManager.ConnectionStrings["WebAppConnString"].ConnectionString;
         using (MySqlConnection con = new MySqlConnection(constr))
         {
             using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM database.activite WHERE activite.iduser='******' AND activite.nature='Sorties' "))
             {
                 using (MySqlDataAdapter sda = new MySqlDataAdapter())
                 {
                     cmd.Connection    = con;
                     sda.SelectCommand = cmd;
                     using (DataTable dt = new DataTable())
                     {
                         sda.Fill(dt);
                         MyDataGrid.DataSource = dt;
                         MyDataGrid.DataBind();
                     }
                 }
             }
         }
     }
 }
Exemple #7
0
        public DocUIDataGrid(XmlNode xmlNode, XmlSchemaAnnotated xsdNode, Panel contentpanel, Panel overlaypanel, DynamicForm parentForm)
            : base(xmlNode, xsdNode, contentpanel, overlaypanel, parentForm)
        {
            XmlSchemaElement schemaEl = xsdNode as XmlSchemaElement;
            if (schemaEl != null)
            {
                _dgrid = new MyDataGrid() { Margin = new Thickness(5), CanUserReorderColumns = false };
                _dgrid.CellEditEnding += (s, e) => { hasPendingChanges(); };
                _dgrid.SelectionUnit = DataGridSelectionUnit.Cell;

                this.xmlNode = xmlNode;
                XmlSchemaSequence seq1 = XmlSchemaUtilities.tryGetSequence(schemaEl.ElementSchemaType);

                XmlDataProvider provider = new XmlDataProvider();
                provider.Document = xmlNode.OwnerDocument;

                Binding myNewBindDef = new Binding();
                myNewBindDef.Source = provider;
                myNewBindDef.XPath = "//" + xmlNode.Name + "/*";
                _dgrid.SetBinding(DataGrid.ItemsSourceProperty, myNewBindDef);
                _dgrid.AutoGenerateColumns = false;
                if (seq1 != null && seq1.Items.Count > 0)
                {
                    _el = seq1.Items[0] as XmlSchemaElement;
                    XmlSchemaSequence seq2 = XmlSchemaUtilities.tryGetSequence((seq1.Items[0] as XmlSchemaElement).ElementSchemaType);
                    if (seq2 != null)
                    {
                        foreach (XmlSchemaElement child in seq2.Items)
                        {
                            XmlSchemaType type = child.ElementSchemaType;
                            string result1;
                            GetColumn result2;
                            DataGridColumn col;
                            if (DynamicForm.Components.TryGetValue(type.QualifiedName.Name, out result1)
                                && ColDict.TryGetValue(result1, out result2))
                            {

                                var b = new Binding
                                   {
                                       XPath = child.Name
                                   };
                                col = result2(b);

                                if (result1 == "combobox")
                                {
                                    DataGridTemplateColumn col2 = col as DataGridTemplateColumn;
                                    FrameworkElementFactory fact = col2.CellTemplate.VisualTree;
                                    List<string> list = new List<string>();
                                    IEnumerable<XmlSchemaEnumerationFacet> enumFacets = XmlSchemaUtilities.tryGetEnumRestrictions(child.ElementSchemaType);
                                    foreach (var facet in enumFacets)
                                    {
                                        list.Add(facet.Value);
                                    }
                                    fact.SetValue(ComboBox.ItemsSourceProperty, list);
                                    string widthstr = XmlSchemaUtilities.tryGetUnhandledAttribute(child, "width");
                                    int width = 0;
                                    if (widthstr != "")
                                        width = Int32.Parse(widthstr);
                                    else
                                        width = 50;
                                    col2.Width = width;
                                }
                            }
                            else
                            {
                                col = new DataGridTextColumn();
                                DataGridTextColumn textcol = col as DataGridTextColumn;
                                var b = new Binding
                                {
                                    XPath = child.Name
                                };
                                textcol.Binding = b;
                                textcol.Width = new DataGridLength(1, DataGridLengthUnitType.Star);

                            }
                            col.Header = child.Name;
                            _dgrid.Columns.Add(col);
                        }

                        DataTemplate dt = new DataTemplate();

                        FrameworkElementFactory templatebutton = new FrameworkElementFactory(typeof(Button));
                        FrameworkElementFactory img = new FrameworkElementFactory(typeof(Image));


                        Binding bind = new Binding
                        {
                            XPath = ".",
                            Mode = BindingMode.TwoWay
                        };

                        BitmapImage bi3 = EmbeddedResourceTools.GetImage("Com.Xploreplus.DocUI.Resources.Images.component.delete.png");

                        img.SetValue(Image.SourceProperty, bi3);

                        templatebutton.AddHandler(Button.ClickEvent, new RoutedEventHandler(click_Delete));
                        templatebutton.AppendChild(img);
                        templatebutton.SetBinding(Button.TagProperty, bind);
                        dt.VisualTree = templatebutton;

                        DataGridTemplateColumn buttoncol = new DataGridTemplateColumn();
                        buttoncol.CanUserResize = false;
                        buttoncol.CellTemplate = dt;
                        _dgrid.Columns.Add(buttoncol);
                        _dgrid.RowHeight = 25;
                        _dgrid.CanUserResizeRows = false;

                        _dgrid.GotFocus += gotFocus;
                        _dgrid.PreparingCellForEdit += checkEmptyRow;

                        _dgrid.PreparingCellForEdit += (s, e) => { this._isEditing = true; };
                        _dgrid.CellEditEnding += (s, e) => { this._isEditing = false; };
                    }
                }
            }
        }
 private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
 {
     var fl = (sender) as FeatureLayer;
     e.Graphic.Select();
     MyDataGrid.ScrollIntoView(e.Graphic, null);
 }
Exemple #9
0
        /// <summary>
        /// 绑定数据到DataGrid控件MyDataGrid上
        /// </summary>
        private void BindDataGrid()
        {
            //创建操作员记录数据表类实例
            MemCardLevelOperate clsRecord = new MemCardLevelOperate();
            DataTable           dt        = new DataTable();

            //获取记录数据
            //if (Session["UserGroupID"].ToString() != "1")
            //{
            //    dt = clsRecord.BindAgent(Convert.ToDateTime(this.txtBeginDate.Text.Trim()).ToShortDateString(), Convert.ToDateTime(this.txtEndDate.Text.Trim()).AddDays(1).ToShortDateString(), Session["UserGroupId"].ToString(), Session["UserId"].ToString());
            //}
            //else
            //{
            //    dt = clsRecord.BindAgent(Convert.ToDateTime(this.txtBeginDate.Text.Trim()).ToShortDateString(), Convert.ToDateTime(this.txtEndDate.Text.Trim()).AddDays(1).ToShortDateString(),, Session["UserId"].ToString()"");
            //}
            dt = clsRecord.BindAgent(Convert.ToDateTime(this.txtBeginDate.Text.Trim()).ToShortDateString(), Convert.ToDateTime(this.txtEndDate.Text.Trim()).AddDays(1).ToShortDateString(), Session["UserGroupId"].ToString(), Session["UserId"].ToString());

            //获取记录数据
            //DataTable dt = clsRecord.BindAgent(Convert.ToDateTime(this.txtBeginDate.Text.Trim()).ToShortDateString(), Convert.ToDateTime(this.txtEndDate.Text.Trim()).AddDays(1).ToShortDateString(),Session["UserId"].ToString());
            DataView dv = new DataView();

            dt.TableName = "Mem_Log";
            if (dt != null)
            {
                dv.Table = dt;

                if (ViewState["Condition"] != null && ViewState["Condition"].ToString() != "")
                {
                    dv.RowFilter = ViewState["Condition"].ToString();
                }
                else
                {
                    dv = dt.DefaultView;
                }

                //新增ID自增值列绑定
                dt.Columns.Add(new DataColumn("idno", Type.GetType("System.Int32")));
                int intCountRecNum = dv.Count;  //获取数据表记录数

                //double totalAccount = 0.00;
                double totalZongXiaofei  = 0.00;
                double totalZongChongzhi = 0.00;

                for (int i = 0; i < intCountRecNum; i++)
                {
                    dv[i]["idno"] = i + 1;

                    //totalAccount += Convert.ToDouble(dv[i]["Account"]);
                    totalZongXiaofei  += Convert.ToDouble(dv[i]["ZongXiaofei"]);
                    totalZongChongzhi += Convert.ToDouble(dv[i]["ZongCongzhi"]);
                }


                MyDataGrid.DataSource = dv;

                this.lbTotalXiaofei.Text  = totalZongXiaofei.ToString();
                this.lbTotalChongzhi.Text = totalZongChongzhi.ToString();


                int PageCount = 0;
                if (intCountRecNum % MyDataGrid.PageSize == 0)
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize;
                }
                else
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize + 1;
                }

                if (PageCount != 0 && MyDataGrid.CurrentPageIndex >= PageCount)
                {
                    MyDataGrid.CurrentPageIndex = PageCount - 1;
                }

                MyDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString();     //显示总记录数
                ShowStats();                                    //显示页数信息
            }
        }
        ///////////////////////////////////////////////////////////////////////
        protected void Page_Load(Object sender, EventArgs e)
        {
            Util.do_not_cache(Response);
            Master.Menu.SelectedItem = "admin";
            Page.Header.Title        = Util.get_setting("AppTitle", "BugTracker.NET") + " - "
                                       + "edit user";

            if (!User.IsInRole(BtnetRoles.Admin))
            {
                // Check if the current user is an admin for any project
                sql = new SQLString(@"select pu_project
			from project_user_xref
			where pu_user = us
			and pu_admin = 1"            );
                sql = sql.AddParameterWithValue("us", Convert.ToString(User.Identity.GetUserId()));
                DataSet ds_projects = btnet.DbUtil.get_dataset(sql);

                if (ds_projects.Tables[0].Rows.Count == 0)
                {
                    Response.Write("You not allowed to add users.");
                    Response.End();
                }

                admin.Visible               = false;
                admin_label.Visible         = false;
                project_admin_label.Visible = false;
                project_admin.Visible       = false;
                project_admin_help.Visible  = false;
            }

            if (Request["copy"] != null && Request["copy"] == "y")
            {
                copy = true;
            }

            msg.InnerText = "";

            string var = Request.QueryString["id"];

            if (var == null)
            {
                id = 0;
                // MAW -- 2006/01/27 -- Set default settings when adding a new user
                auto_subscribe_own.Checked                 = true;
                auto_subscribe_reported.Checked            = true;
                enable_popups.Checked                      = true;
                reported_notifications.Items[4].Selected   = true;
                assigned_notifications.Items[4].Selected   = true;
                subscribed_notifications.Items[4].Selected = true;
            }
            else
            {
                id = Convert.ToInt32(var);
            }

            if (!IsPostBack)
            {
                if (!User.IsInRole(BtnetRoles.Admin))
                {
                    // logged in user is a project level admin

                    // get values for permissions grid
                    // Table 0
                    sql = new SQLString(@"
				select pj_id, pj_name,
				isnull(a.pu_permission_level,@dpl) [pu_permission_level],
				isnull(a.pu_auto_subscribe,0) [pu_auto_subscribe],
				isnull(a.pu_admin,0) [pu_admin]
				from projects
				inner join project_user_xref project_admin on pj_id = project_admin.pu_project
				and project_admin.pu_user = @this_usid
				and project_admin.pu_admin = 1
				left outer join project_user_xref a on pj_id = a.pu_project
				and a.pu_user = @us
				order by pj_name;"                );


                    sql = sql.AddParameterWithValue("this_usid", Convert.ToString(User.Identity.GetUserId()));
                }
                else // user is a real admin
                {
                    // Table 0

                    // populate permissions grid
                    sql = new SQLString(@"
				select pj_id, pj_name,
				isnull(pu_permission_level,@dpl) [pu_permission_level],
				isnull(pu_auto_subscribe,0) [pu_auto_subscribe],
				isnull(pu_admin,0) [pu_admin]
				from projects
				left outer join project_user_xref on pj_id = pu_project
				and pu_user = @us
				order by pj_name;"                );
                }

                // Table 1

                sql.Append(@"/* populate query dropdown */
		    declare @org int
		    set @org = null
		    select @org = us_org from users where us_id = @us

			select qu_id, qu_desc
			from queries
			where (isnull(qu_user,0) = 0 and isnull(qu_org,0) = 0)
			or isnull(qu_user,0) = @us
			or isnull(qu_org,0) = isnull(@org,-1)
			order by qu_desc;"            );

                // Table 2

                if (User.IsInRole(BtnetRoles.Admin))
                {
                    sql.Append(@"/* populate org dropdown 1 */
				select og_id, og_name
				from orgs
				order by og_name;"                );
                }
                else
                {
                    if (User.Identity.GetOtherOrgsPermissionLevels() == PermissionLevel.All)
                    {
                        sql.Append(@"/* populate org dropdown 2 */
					select og_id, og_name
					from orgs
					where og_non_admins_can_use = 1
					order by og_name;"                    );
                    }
                    else
                    {
                        sql.Append(@"/* populate org dropdown 3 */
					select 1; -- dummy"                    );
                    }
                }


                // Table 3
                if (id != 0)
                {
                    // get existing user values

                    sql.Append(@"
			select
				us_username,
				isnull(us_firstname,'') [us_firstname],
				isnull(us_lastname,'') [us_lastname],
				isnull(us_bugs_per_page,10) [us_bugs_per_page],
				us_use_fckeditor,
				us_enable_bug_list_popups,
				isnull(us_email,'') [us_email],
				us_active,
				us_admin,
				us_enable_notifications,
				us_send_notifications_to_self,
                us_reported_notifications,
                us_assigned_notifications,
                us_subscribed_notifications,
				us_auto_subscribe,
				us_auto_subscribe_own_bugs,
				us_auto_subscribe_reported_bugs,
				us_default_query,
				us_org,
				isnull(us_signature,'') [us_signature],
				isnull(us_forced_project,0) [us_forced_project],
				us_created_user
				from users
				where us_id = @us"                );
                }


                sql = sql.AddParameterWithValue("us", Convert.ToString(id));
                sql = sql.AddParameterWithValue("dpl", Util.get_setting("DefaultPermissionLevel", "2"));

                DataSet ds = btnet.DbUtil.get_dataset(sql);

                // query dropdown
                query.DataSource     = ds.Tables[1].DefaultView;
                query.DataTextField  = "qu_desc";
                query.DataValueField = "qu_id";
                query.DataBind();

                // forced project dropdown
                forced_project.DataSource     = ds.Tables[0].DefaultView;
                forced_project.DataTextField  = "pj_name";
                forced_project.DataValueField = "pj_id";
                forced_project.DataBind();
                forced_project.Items.Insert(0, new ListItem("[no forced project]", "0"));

                // org dropdown
                if (User.IsInRole(BtnetRoles.Admin) ||
                    User.Identity.GetOtherOrgsPermissionLevels() == PermissionLevel.All)
                {
                    org.DataSource     = ds.Tables[2].DefaultView;
                    org.DataTextField  = "og_name";
                    org.DataValueField = "og_id";
                    org.DataBind();
                    org.Items.Insert(0, new ListItem("[select org]", "0"));
                }
                else
                {
                    int organizationId = User.Identity.GetOrganizationId();
                    int orgRow         = ds.Tables[2].DefaultView.Find(organizationId);
                    org.Items.Insert(0, new ListItem((string)ds.Tables[2].Rows[orgRow]["og_name"], Convert.ToString(organizationId)));
                }

                // populate permissions grid
                MyDataGrid.DataSource = ds.Tables[0].DefaultView;
                MyDataGrid.DataBind();

                // subscribe by project dropdown
                project_auto_subscribe.DataSource     = ds.Tables[0].DefaultView;
                project_auto_subscribe.DataTextField  = "pj_name";
                project_auto_subscribe.DataValueField = "pj_id";
                project_auto_subscribe.DataBind();

                // project admin dropdown
                project_admin.DataSource     = ds.Tables[0].DefaultView;
                project_admin.DataTextField  = "pj_name";
                project_admin.DataValueField = "pj_id";
                project_admin.DataBind();


                // add or edit?
                if (id == 0)
                {
                    sub.Value                    = "Create";
                    bugs_per_page.Value          = "10";
                    active.Checked               = true;
                    enable_notifications.Checked = true;
                }
                else
                {
                    sub.Value = "Update";

                    // get the values for this existing user
                    DataRow dr = ds.Tables[3].Rows[0];

                    // check if project admin is allowed to edit this user
                    if (!User.IsInRole(BtnetRoles.Admin))
                    {
                        if (User.Identity.GetUserId() != (int)dr["us_created_user"])
                        {
                            Response.Write("You not allowed to edit this user, because you didn't create it.");
                            Response.End();
                        }
                        else if ((int)dr["us_admin"] == 1)
                        {
                            Response.Write("You not allowed to edit this user, because it is an admin.");
                            Response.End();
                        }
                    }


                    // select values in dropdowns

                    // select forced project
                    int current_forced_project = (int)dr["us_forced_project"];
                    foreach (ListItem li in forced_project.Items)
                    {
                        if (Convert.ToInt32(li.Value) == current_forced_project)
                        {
                            li.Selected = true;
                            break;
                        }
                    }

                    // Fill in this form
                    if (copy)
                    {
                        username.Value      = "Enter username here";
                        firstname.Value     = "";
                        lastname.Value      = "";
                        email.Value         = "";
                        signature.InnerText = "";
                    }
                    else
                    {
                        username.Value      = (string)dr["us_username"];
                        firstname.Value     = (string)dr["us_firstname"];
                        lastname.Value      = (string)dr["us_lastname"];
                        email.Value         = (string)dr["us_email"];
                        signature.InnerText = (string)dr["us_signature"];
                    }

                    bugs_per_page.Value          = Convert.ToString(dr["us_bugs_per_page"]);
                    use_fckeditor.Checked        = Convert.ToBoolean((int)dr["us_use_fckeditor"]);
                    enable_popups.Checked        = Convert.ToBoolean((int)dr["us_enable_bug_list_popups"]);
                    active.Checked               = Convert.ToBoolean((int)dr["us_active"]);
                    admin.Checked                = Convert.ToBoolean((int)dr["us_admin"]);
                    enable_notifications.Checked = Convert.ToBoolean((int)dr["us_enable_notifications"]);
                    send_to_self.Checked         = Convert.ToBoolean((int)dr["us_send_notifications_to_self"]);
                    reported_notifications.Items[(int)dr["us_reported_notifications"]].Selected     = true;
                    assigned_notifications.Items[(int)dr["us_assigned_notifications"]].Selected     = true;
                    subscribed_notifications.Items[(int)dr["us_subscribed_notifications"]].Selected = true;
                    auto_subscribe.Checked          = Convert.ToBoolean((int)dr["us_auto_subscribe"]);
                    auto_subscribe_own.Checked      = Convert.ToBoolean((int)dr["us_auto_subscribe_own_bugs"]);
                    auto_subscribe_reported.Checked = Convert.ToBoolean((int)dr["us_auto_subscribe_reported_bugs"]);


                    // org
                    foreach (ListItem li in org.Items)
                    {
                        if (Convert.ToInt32(li.Value) == (int)dr["us_org"])
                        {
                            li.Selected = true;
                            break;
                        }
                    }

                    // query
                    foreach (ListItem li in query.Items)
                    {
                        if (Convert.ToInt32(li.Value) == (int)dr["us_default_query"])
                        {
                            li.Selected = true;
                            break;
                        }
                    }

                    // select projects
                    foreach (DataRow dr2 in ds.Tables[0].Rows)
                    {
                        foreach (ListItem li in project_auto_subscribe.Items)
                        {
                            if (Convert.ToInt32(li.Value) == (int)dr2["pj_id"])
                            {
                                if ((int)dr2["pu_auto_subscribe"] == 1)
                                {
                                    li.Selected = true;
                                }
                                else
                                {
                                    li.Selected = false;
                                }
                            }
                        }
                    }

                    foreach (DataRow dr3 in ds.Tables[0].Rows)
                    {
                        foreach (ListItem li in project_admin.Items)
                        {
                            if (Convert.ToInt32(li.Value) == (int)dr3["pj_id"])
                            {
                                if ((int)dr3["pu_admin"] == 1)
                                {
                                    li.Selected = true;
                                }
                                else
                                {
                                    li.Selected = false;
                                }
                            }
                        }
                    }
                } // add or edit
            }     // if !postback
            else
            {
                on_update();
            }
        }
Exemple #11
0
        /// <summary>
        /// 绑定数据到DataGrid控件MyDataGrid上
        /// </summary>
        private void BindDataGrid()
        {
            string MemID     = ddlMemID.SelectedItem.Value;
            string Condition = " 1=1 ";

            if (MemID != null && MemID != "---请选择---" && MemID != "")
            {
                Condition += " AND father='" + MemID + "'";
            }
            //			if(txtProgramName.Text.Trim()!="")
            //				Condition += " AND ModuleName = '" + txtProgramName.Text + "'";
            if (this.txtCardId.Text.Trim() != "")
            {
                Condition += " AND cardid like '%" + this.txtCardId.Text.Trim() + "%'";
            }

            if (this.txtMemName.Text.Trim() != "")
            {
                Condition += " and memname like '%" + this.txtMemName.Text.Trim() + "%'";
            }

            ViewState["Condition"] = Condition;

            //创建操作员记录数据表类实例
            MemberOperate clsMem = new MemberOperate();
            //获取记录数据
            DataTable dt = new DataTable();

            if (Session["UserGroupID"].ToString() == "2" || Session["UserGroupID"].ToString() == "3")
            {
                dt = clsMem.Bind(Session["UserID"].ToString());
            }
            else
            {
                dt = clsMem.Bind("");
            }

            DataView dv = new DataView();

            dt.TableName = "Mem";
            if (dt != null)
            {
                dv.Table = dt;
                dv.Sort  = " father DESC";

                if (ViewState["Condition"] != null && ViewState["Condition"].ToString() != "")
                {
                    dv.RowFilter = ViewState["Condition"].ToString();
                }
                else
                {
                    dv = dt.DefaultView;
                }

                //新增ID自增值列绑定
                dt.Columns.Add(new DataColumn("idno", Type.GetType("System.Int32")));
                int intCountRecNum = dv.Count;  //获取数据表记录数
                for (int i = 0; i < intCountRecNum; i++)
                {
                    dv[i]["idno"] = i + 1;
                }
                MyDataGrid.DataSource = dv;
                int PageCount = 0;
                if (intCountRecNum % MyDataGrid.PageSize == 0)
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize;
                }
                else
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize + 1;
                }

                if (PageCount != 0 && MyDataGrid.CurrentPageIndex >= PageCount)
                {
                    MyDataGrid.CurrentPageIndex = PageCount - 1;
                }

                MyDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString();     //显示总记录数
                ShowStats();                                    //显示页数信息
            }
        }
        public void PagerButtonClick(Object sender, EventArgs e)
        {
            string arg = ((LinkButton)sender).CommandArgument;

            switch (arg)
            {
            case ("next"):
            {
                MyDataGrid.DataSource = null;
                DataSet ds = new DataSet();
                ds.Clear();
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();  
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'" + DropDownClass.Text + "'" + " order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();
                    if (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1))
                    {
                        MyDataGrid.CurrentPageIndex++;
                    }
                }
                catch (SqlException ex1)
                {
                    Response.Write("Exception in Main: " + ex1.Message);
                }


                break;
            }

            case ("prev"):
            {
                MyDataGrid.DataSource = null;
                DataSet ds = new DataSet();
                ds.Clear();
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();
                    myCommand.SelectCommand = new SqlCommand("select * from Article where classname=" + "'" + DropDownClass.Text + "'" + " order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();
                    if (MyDataGrid.CurrentPageIndex > 0)
                    {
                        MyDataGrid.CurrentPageIndex--;
                    }
                }
                catch (SqlException ex1)
                {
                    Response.Write("Exception in Main: " + ex1.Message);
                }
                break;
            }

            case ("last"):
            {
                MyDataGrid.DataSource = null;
                DataSet ds = new DataSet();
                ds.Clear();
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();   
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'" + DropDownClass.Text + "'" + " order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();
                    MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
                }
                catch (SqlException ex1)
                {
                    Response.Write("Exception in Main: " + ex1.Message);
                }

                break;
            }

            case ("first"):
            {
                MyDataGrid.DataSource = null;
                DataSet ds = new DataSet();
                ds.Clear();
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();  
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'" + DropDownClass.Text + "'" + " order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();
                    MyDataGrid.CurrentPageIndex = 0;
                }
                catch (SqlException ex1)
                {
                    Response.Write("Exception in Main: " + ex1.Message);
                }

                break;
            }
            }
            getchangeArticle();
        }
        protected void DropDownClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyDataGrid.CurrentPageIndex = 0;
            lblCurrentIndex.Text        = "第1页";
            MyDataGrid.DataSource       = null;
            DataSet ds = new DataSet();

            ds.Clear();
            if (DropDownClass.SelectedIndex == 1)
            {
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();   
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'体育'" + "and checkup=1 order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();

                    SqlCommand cmd = new SqlCommand("select * from Class where classname=" + "'体育'", conn);

                    SqlDataReader rd;
                    rd = cmd.ExecuteReader();
                    if (rd.Read() == true)
                    {
                        NameLabel.Text = "新闻数量:" + rd.GetInt32(2) + " 篇";
                        rd.Close();
                    }
                    SqlCommand cmd1 = new SqlCommand("select classid from Class where className=" + "'体育'", conn);
                    rd = cmd1.ExecuteReader();
                    int id;
                    if (rd.Read() == true)
                    {
                        id = Convert.ToInt32(rd["classid"]);
                        DropDownClass.SelectedIndex = id;
                    }
                    conn.Close();
                }
                catch (SqlException ex)
                {
                    Response.Write("Exception in Main: " + ex.Message);
                }
            }
            if (DropDownClass.SelectedIndex == 0)
            {
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();  
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'新闻'" + "and checkup=1 order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();

                    SqlCommand cmd = new SqlCommand("select * from Class where classname=" + "'新闻'", conn);

                    SqlDataReader rd;
                    rd = cmd.ExecuteReader();
                    if (rd.Read() == true)
                    {
                        NameLabel.Text = "新闻数量:" + rd.GetInt32(2) + " 篇";
                        rd.Close();
                    }
                    SqlCommand cmd1 = new SqlCommand("select classid from Class where className=" + "'新闻'", conn);
                    rd = cmd1.ExecuteReader();
                    int id;
                    if (rd.Read() == true)
                    {
                        id = Convert.ToInt32(rd["classid"]);
                        DropDownClass.SelectedIndex = id;
                    }
                    conn.Close();
                }
                catch (SqlException ex)
                {
                    Response.Write("Exception in Main: " + ex.Message);
                }
            }
            if (DropDownClass.SelectedIndex == 2)
            {
                try
                {
                    string        con  = ConfigurationSettings.AppSettings["np"];
                    SqlConnection conn = new SqlConnection(con);
                    conn.Open();

                    SqlDataAdapter myCommand = new SqlDataAdapter();   
                    myCommand.SelectCommand  = new SqlCommand("select * from Article where classname=" + "'科技'" + "and checkup=1 order by dateandtime desc", conn);
                    myCommand.Fill(ds);

                    MyDataGrid.DataSource = ds;
                    MyDataGrid.DataBind();

                    SqlCommand cmd = new SqlCommand("select * from Class where classname=" + "'科技'", conn);

                    SqlDataReader rd;
                    rd = cmd.ExecuteReader();
                    if (rd.Read() == true)
                    {
                        NameLabel.Text = "新闻数量:" + rd.GetInt32(2) + " 篇";
                        rd.Close();
                    }
                    SqlCommand cmd1 = new SqlCommand("select classid from Class where className=" + "'科技'", conn);
                    rd = cmd1.ExecuteReader();
                    int id;
                    if (rd.Read() == true)
                    {
                        id = Convert.ToInt32(rd["classid"]);
                        DropDownClass.SelectedIndex = id;
                    }
                    conn.Close();
                }
                catch (SqlException ex)
                {
                    Response.Write("Exception in Main: " + ex.Message);
                }
            }
        }
        /// <summary>
        /// 绑定数据到DataGrid控件MyDataGrid上
        /// </summary>
        private void BindDataGrid()
        {
            //创建操作员记录数据表类实例
            GoodsCategory clsGood = new GoodsCategory();

            //获取记录数据
            dt = clsGood.Bind();

            dtTemp.TableName = "GoodsCategory";
            if (dt != null)
            {
                dtTemp.Rows.Clear();
                dtTemp.Columns.Add("GoodsCategoryId");
                dtTemp.Columns.Add("Description");
                dtTemp.Columns.Add("FatherId");
                DataRow[] dRows = dt.Select("fatherid = '0'");
                for (int i = 0; i < dRows.Length; i++)
                {
                    dtTemp.Rows.Add(dRows[i]["GoodsCategoryId"], dRows[i]["Description"], dRows[i]["FatherId"]);
                    InsertdtTemp(dRows[i]["GoodsCategoryId"].ToString(), "—");
                }



                DataView dv = new DataView();
                dv.Table = dtTemp;
                //dv.Sort = " GoodsCategoryId DESC";

                if (ViewState["Condition"] != null && ViewState["Condition"].ToString() != "")
                {
                    dv.RowFilter = ViewState["Condition"].ToString();
                }
                else
                {
                    dv = dtTemp.DefaultView;
                }

                //新增ID自增值列绑定
                dtTemp.Columns.Add(new DataColumn("idno", Type.GetType("System.Int32")));
                int intCountRecNum = dv.Count;  //获取数据表记录数
                for (int i = 0; i < intCountRecNum; i++)
                {
                    dv[i]["idno"] = i + 1;
                }
                MyDataGrid.DataSource = dv;
                int PageCount = 0;
                if (intCountRecNum % MyDataGrid.PageSize == 0)
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize;
                }
                else
                {
                    PageCount = intCountRecNum / MyDataGrid.PageSize + 1;
                }

                if (PageCount != 0 && MyDataGrid.CurrentPageIndex >= PageCount)
                {
                    MyDataGrid.CurrentPageIndex = PageCount - 1;
                }

                MyDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString();     //显示总记录数
                ShowStats();                                    //显示页数信息
            }
        }
 public GridAdorner(MyDataGrid dataGrid)
     : base(dataGrid)
 {
     dataGrid.LayoutUpdated += new EventHandler(dataGrid_LayoutUpdated);
 }
Exemple #16
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     loadGridData();
     MyDataGrid.Focus();
 }
Exemple #17
0
 private void ScrollToSelection()
 {
     MyDataGrid.Items.MoveCurrentTo(MyDataGrid.SelectedItem);
     MyDataGrid.ScrollIntoView(MyDataGrid.SelectedItem);
 }