Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                using (FIOContext db = new FIOContext())
                {
                    DataTable T_fio = new DataTable();
                    if (T_fio.Columns.Count == 0)
                    {
                        T_fio.Columns.Add("Id", typeof(int));
                        T_fio.Columns.Add("Fio", typeof(string));
                    }
                    foreach (FIO p in db.FIO)
                    {
                        DataRow row = T_fio.NewRow();
                        row[0] = p.Id;
                        row[1] = p.Fio;
                        T_fio.Rows.Add(row);
                    }
                    DropDownList2.DataSource     = T_fio;
                    DropDownList2.DataTextField  = "Fio";
                    DropDownList2.DataValueField = "Id";
                    DropDownList2.DataBind();
                }

                using (BookContext db = new BookContext())
                {
                    DataTable T_book = new DataTable();
                    if (T_book.Columns.Count == 0)
                    {
                        T_book.Columns.Add("Id", typeof(int));
                        T_book.Columns.Add("Name_book", typeof(string));
                    }
                    foreach (Book s in db.Book)
                    {
                        DataRow row = T_book.NewRow();
                        row[0] = s.Id;
                        row[1] = s.Name_book;
                        T_book.Rows.Add(row);
                    }
                    DropDownList1.DataSource     = T_book;
                    DropDownList1.DataTextField  = "Name_book";
                    DropDownList1.DataValueField = "Id";
                    DropDownList1.DataBind();
                }
            }
        }
Example #2
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == "" || TextBox2.Text == "")
            {
                DataTable T_A_book = new DataTable();
                if (T_A_book.Columns.Count == 0)
                {
                    T_A_book.Columns.Add("Код", typeof(int));
                    T_A_book.Columns.Add("Книга", typeof(string));
                    T_A_book.Columns.Add("ФИО", typeof(string));
                    T_A_book.Columns.Add("Дата взятия", typeof(DateTime));
                    T_A_book.Columns.Add("Дата возрата", typeof(DateTime));
                }

                using (Arenda_bookContext db = new Arenda_bookContext())
                {
                    foreach (Arenda_book app in db.Arenda_book)
                    {
                        DataRow row = T_A_book.NewRow();
                        row[0] = app.Id;

                        using (BookContext db1 = new BookContext())
                        {
                            row[1] = db1.Book.Where(s => s.Id == app.id_book).FirstOrDefault().Name_book;
                        }

                        using (FIOContext db2 = new FIOContext())
                        {
                            row[2] = db2.FIO.Where(p => p.Id == app.id_fio).FirstOrDefault().Fio;
                        }
                        string[] d  = app.Data_1.ToString().Split(' ');
                        string[] dd = app.Data_2.ToString().Split(' ');
                        row[3] = d[0];
                        row[4] = dd[0];
                        T_A_book.Rows.Add(row);
                    }
                    GridView1.DataSource = T_A_book;
                    GridView1.DataBind();
                }
            }
            else if (TextBox1.Text != "" || TextBox2.Text != "")
            {
                DateTime  data_1   = DateTime.Parse(TextBox1.Text);
                DateTime  data_2   = DateTime.Parse(TextBox2.Text);
                DataTable T_A_book = new DataTable();
                if (T_A_book.Columns.Count == 0)
                {
                    T_A_book.Columns.Add("Код", typeof(int));
                    T_A_book.Columns.Add("Книга", typeof(string));
                    T_A_book.Columns.Add("ФИО", typeof(string));
                    T_A_book.Columns.Add("Дата взятия", typeof(DateTime));
                    T_A_book.Columns.Add("Дата возрата", typeof(DateTime));
                }

                using (Arenda_bookContext db = new Arenda_bookContext())
                {
                    foreach (Arenda_book app in db.Arenda_book)
                    {
                        if ((app.Data_1 >= data_1 && app.Data_1 <= data_2) || (app.Data_2 >= data_1 && app.Data_2 <= data_2))
                        {
                            DataRow row = T_A_book.NewRow();
                            row[0] = app.Id;

                            using (BookContext db1 = new BookContext())
                            {
                                row[1] = db1.Book.Where(s => s.Id == app.id_book).FirstOrDefault().Name_book;
                            }

                            using (FIOContext db2 = new FIOContext())
                            {
                                row[2] = db2.FIO.Where(p => p.Id == app.id_fio).FirstOrDefault().Fio;
                            }
                            string[] date_1 = app.Data_1.ToString().Split(' ');
                            string[] date_2 = app.Data_2.ToString().Split(' ');
                            row[3] = date_1[0];
                            row[4] = date_2[0];
                            T_A_book.Rows.Add(row);
                        }
                    }
                    GridView1.DataSource = T_A_book;
                    GridView1.DataBind();
                }
            }
        }