コード例 #1
0
ファイル: Member.cs プロジェクト: dtafe/FileTranferSystem
 public Member MemberIDataReader(IDataReader dr)
 {
     Member obj = new Member();
     obj.Account = (dr["Account"] is DBNull) ? string.Empty : dr["Account"].ToString();
     obj.Name = (dr["Name"] is DBNull) ? string.Empty : dr["Name"].ToString();
     obj.Email = (dr["Email"] is DBNull) ? string.Empty : dr["Email"].ToString();
     obj.Pw = (dr["Pw"] is DBNull) ? string.Empty : dr["Pw"].ToString();
     obj.Permission = (dr["Permission"] is DBNull) ? string.Empty : dr["Permission"].ToString();
     return obj;
 }
コード例 #2
0
        private void FillDataToGridview()
        {
            List<Member> listobj = new List<Member>();
            using (SqlConnection Conn = new SqlConnection(Common.GetConnectString()))
            {
                Conn.Open();
                using (SqlCommand cmd = new SqlCommand("DDV_SearchMember", Conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    Member obj = new Member();
                    SqlDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            listobj.Add(obj.MemberIDataReader(dr));
                        }
                    }
                    dr.Close();
                    obj = null;
                    #region Check list member Null
                    if (listobj.Count < 1)
                    {

                        Member member = new Member();
                        member.Account = "";
                        member.Name = "";
                        member.Email = "";
                        member.Pw = "";
                        member.Permission = null;

                        listobj.Add(member);
                        GridViewMember.DataSource = listobj;
                        GridViewMember.DataBind();
                        if (listobj.Count == 1 && member.Account == "")
                        {
                            //LabelNoRecord.Visible = true;
                            GridViewMember.Rows[0].Visible = false;
                            return;
                        }
                    }
                    #endregion
                    else
                    {
                        listobj = listobj.Where(c => (TextBoxAccount.Text == string.Empty || c.Account.ToLower().Contains(TextBoxAccount.Text.ToLower()))
                        && (TextBoxEmail.Text == string.Empty || c.Email.ToLower().Contains(TextBoxEmail.Text.ToLower()))
                        && (DropDownListRole.SelectedValue == "0" || c.Permission.ToString() == (DropDownListRole.SelectedValue))).ToList();
                        #region Check list member Null
                        if (listobj.Count < 1)
                        {

                            Member member = new Member();
                            member.Account = "";
                            member.Name = "";
                            member.Email = "";
                            member.Pw = "";
                            member.Permission = null;

                            listobj.Add(member);
                            GridViewMember.DataSource = listobj;
                            GridViewMember.DataBind();
                            if (listobj.Count == 1 && member.Account == "")
                            {
                                //LabelNoRecord.Visible = true;
                                GridViewMember.Rows[0].Visible = false;
                                return;
                            }
                        }
                        #endregion
                        GridViewMember.DataSource = listobj;
                        GridViewMember.DataBind();
                        foreach (GridViewRow row in GridViewMember.Rows)
                        {
                            if (row.Cells[4].Text == "1")
                                row.Cells[4].Text = GetResource("Admin");
                            else if (row.Cells[4].Text == "2")
                                row.Cells[4].Text = GetResource("User");
                            else if (Common.GetRowString(row.Cells[4].Text) == "")
                                row.Cells[4].Text = GetResource("Waiting");
                        }

                    }
                }
            }
        }