private void DocDuLieu() { SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcom2 = new SqlCommand(); try { sqlcon.ConnectionString = conString; sqlcon.Open(); if (sqlcon.State == System.Data.ConnectionState.Open) { sqlcom2.Connection = sqlcon; sqlcom2.CommandType = System.Data.CommandType.Text; sqlcom2.CommandText = "SELECT Player.ID AS 'ID CẦU THỦ',Player.Ten AS 'TÊN CẦU THỦ', Player.NamSinh AS 'NĂM SINH', Player.Tuoi AS 'TUỔI', Player.GiaTri AS 'GIÁ TRỊ', Player.QueQuan 'QUÊ QUÁN', Player.ID_VT 'ID VỊ TRÍ', VItri.VItri AS 'VỊ TRÍ'" + "FROM Player INNER JOIN VItri ON Player.ID_VT = VItri.ID_VT "; DataTable dt = new DataTable("DS"); SqlDataAdapter da = new SqlDataAdapter(sqlcom2); //dt.Rows. da.Fill(dt); Gv1.DataSource = dt; Gv1.DataBind(); } } catch (Exception exc) { } finally { if (sqlcon.State == System.Data.ConnectionState.Open) { sqlcon.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { //we have to add this dynamic control on every load Button b = new Button(); dyncontrol.Controls.Add(b); b.Text = "Back to Home"; b.PostBackUrl = "/"; if (!this.IsPostBack) { USStates s = new USStates(); Dictionary <string, string> L; Literal1.Mode = LiteralMode.PassThrough; Literal1.Text = s.AsHtmlTable(); L = s.AsDictionary(); Ddl1.DataSource = L; Ddl1.DataTextField = "Value"; Ddl1.DataValueField = "Key"; Ddl1.DataBind(); SState.Text = "No State Selected"; Gv1.AllowSorting = true; Gv1.DataSource = s.AsDataTable(); Gv1.DataBind(); } else { } }
protected void btthem_Click(object sender, EventArgs e) { if (them(txtmasp.Text, txttensp.Text, txtgia.Text, txtmota.Text, fulhinhanh.FileName) == 0) { lbthemsanpham.Text = "Mã sản phẩm đã tồn tại"; } else if (them(txtmasp.Text, txttensp.Text, txtgia.Text, txtmota.Text, fulhinhanh.FileName) == 0) { lbthemsanpham.Text = "Thêm thất bại"; } else { lbthemsanpham.Text = "Thêm sản phẩm thành công"; } string folderPath = Server.MapPath("~/hinh/"); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } fulhinhanh.SaveAs(folderPath + Path.GetFileName(fulhinhanh.FileName)); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dl"].ToString()); SqlDataAdapter da = new SqlDataAdapter("select * from sanpham", con); DataSet ds = new DataSet(); da.Fill(ds, "sanpham"); Gv1.DataSource = ds.Tables["sanpham"]; Gv1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { createtable(); Dictionary <int, int> cartItems = (Dictionary <int, int>)Session["ShoppingCart"]; int prodid; int prodqty; decimal grandtotal = 0; // List<cartitem> crtitem = new List<cartitem>(); foreach (KeyValuePair <int, int> productidQty in cartItems) { prodid = productidQty.Key; prodqty = productidQty.Value; EntityManager <ProductListing> pcat = new EntityManager <ProductListing>(); ProductListing procat = new ProductListing(); procat.ProductID = prodid; List <ProductListing> prodcatID = pcat.Search(procat); int ID = prodid; string Name = prodcatID[0].Name; string ProductNumber = prodcatID[0].ProductNumber; string Description = prodcatID[0].Description; string Color = prodcatID[0].Color; decimal ListPrice = prodcatID[0].ListPrice; string CategoryName = prodcatID[0].CategoryName; string ModelName = prodcatID[0].ModelName; int Quantity = prodqty; decimal Totalprice = prodqty * prodcatID[0].ListPrice; grandtotal = grandtotal + Totalprice; tb = (DataTable)ViewState["table1"]; dr = tb.NewRow(); dr["Product Name"] = Name; dr["Number"] = ProductNumber; dr["Description"] = Description; dr["color"] = Color; dr["List Price"] = ListPrice; dr["Category Name"] = CategoryName; dr["Model Name"] = ModelName; dr["Quantity"] = Quantity; dr["Total Price"] = Totalprice; tb.Rows.Add(dr); Gv1.DataSource = tb; Gv1.DataBind(); } lbl_GrandTotal.Text = "Grand Total of your cart Items =" + grandtotal.ToString(); } }
protected void GridViewSortEventHandler(object sender, GridViewSortEventArgs e) { USStates s = new USStates(); DataView v = new DataView(s.AsDataTable()); v.Sort = e.SortExpression + " ASC"; Gv1.DataSource = v; Gv1.DataBind(); }
protected void addNewRow(object sender, EventArgs e) { dbConnect.insertTable(Convert.ToInt16(id.Text), name.Text); //empty the textbox id.Text = ""; name.Text = ""; //refresh the gridviews Gv1.DataBind(); GridView1.DataBind(); }
protected void Gv1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { Gv1.EditIndex = -1; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dl"].ToString()); SqlDataAdapter da = new SqlDataAdapter("select * from sanpham ", con); DataSet ds = new DataSet(); da.Fill(ds, "sanpham"); Gv1.DataSource = ds.Tables["sanpham"]; Gv1.DataBind(); }
protected void PurchTableDataGet() { PurchasingTransaction bid = new PurchasingTransaction(); if (ViewState[Constant.SESSION_USERID] != null) { DataTable dt = bid.QueryPurchasingTable(connstring, ViewState[Constant.SESSION_USERID].ToString().Trim()); DataView dv = new DataView(dt); Gv1.DataSource = dv; Gv1.DataBind(); } }
protected void btTk_Click(object sender, EventArgs e) { if (tbTen.Text.Trim() == "") { Response.Write("<br/><br/>Hãy nhập tối thiểu 1 điều kiện tìm kiếm!!! <br/><br/>"); return; } string where = " WHERE 1=1 "; if (tbTen.Text.Trim() != "") { where = string.Format(" {0} AND Ten LIKE N'%{1}%'", where, tbTen.Text.Trim()); } try { sqlcon.ConnectionString = conString; sqlcon.Open(); if (sqlcon.State == System.Data.ConnectionState.Open) { //Response.Write("</br>Kết nối thành công! </br>"); sqlcom2.Connection = sqlcon; sqlcom2.CommandType = System.Data.CommandType.Text; sqlcom2.CommandText = string.Format("SELECT Player.ID AS 'ID CẦU THỦ',Player.Ten AS 'TÊN CẦU THỦ', Player.NamSinh AS 'NĂM SINH', Player.QueQuan AS 'QUÊ QUÁN', Player.GiaTri AS 'GIÁ TRỊ' , VItri.VItri 'VỊ TRÍ' FROM Player INNER JOIN VItri ON Player.ID_VT = VItri.ID_VT {0}", where); //Response.Write(string.Format("SQL: {0}", sqlcomm4.CommandText)); DataTable dt = new DataTable("DSplayer"); SqlDataAdapter da3 = new SqlDataAdapter(sqlcom2); //dt.Rows. da3.Fill(dt); Gv1.DataSource = dt; //gHangHoa.PageIndex = pageIndex; Gv1.DataBind(); } else { } } catch (Exception exc) { Response.Write(string.Format("<br/>Lỗi: {0}. <br/>Code: {1}", exc.Message, exc.StackTrace)); } finally { sqlcom2.Dispose(); if (sqlcon.State == System.Data.ConnectionState.Open) { sqlcon.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dl"].ToString()); SqlDataAdapter da = new SqlDataAdapter("select * from sanpham", con); DataSet ds = new DataSet(); da.Fill(ds, "sanpham"); DataColumn[] khoachinh = new DataColumn[1]; khoachinh[0] = ds.Tables["sanpham"].Columns[0]; ds.Tables["sanpham"].PrimaryKey = khoachinh; Gv1.DataSource = ds.Tables["sanpham"]; Gv1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["currentUser"] != null && Session["currentUserType"] != null) { if (Session["currentUserType"].ToString() == "user") { helper = new DataHelper(); currentUser = Session["currentUser"].ToString(); if ((Session["cartName"] != null && Session["cartQuantity"] != null) && Session["cartPrice"] != null) { cartName = Session["cartName"] as List <string>; cartQuantity = Session["cartQuantity"] as List <int>; cartPrice = Session["cartPrice"] as List <int>; if (cartName.Count > 0) { table.Columns.Add("Product Name", typeof(string)); table.Columns.Add("Quantity", typeof(string)); table.Columns.Add("Sub Price", typeof(string)); table.Columns.Add("Remove from Cart", typeof(Button)); for (int CTR = 0; CTR < cartName.Count; CTR++) { row = table.NewRow(); row["Product Name"] = cartName[CTR]; row["Quantity"] = cartQuantity[CTR]; row["Sub Price"] = cartPrice[CTR]; row["Remove from Cart"] = NewButton(CTR); table.Rows.Add(row); } Gv1.DataSource = table; Gv1.DataBind(); } } } else { Console.WriteLine("Not a user"); Response.Redirect("~/Base Pages/Login.aspx"); } } else { Console.WriteLine("No one is logged in"); Response.Redirect("~/Base Pages/Login.aspx"); } }
public void createtable() { tb.Columns.Add("Product Name", typeof(string)); tb.Columns.Add("Number", typeof(string)); tb.Columns.Add("Description", typeof(string)); tb.Columns.Add("color", typeof(string)); tb.Columns.Add("List Price", typeof(string)); tb.Columns.Add("Category Name", typeof(string)); tb.Columns.Add("Model Name", typeof(string)); tb.Columns.Add("Quantity", typeof(string)); tb.Columns.Add("Total Price", typeof(string)); Gv1.DataSource = tb; Gv1.DataBind(); ViewState["table1"] = tb; }
public void dataload() { Dictionary <int, int> cartItems1 = (Dictionary <int, int>)Session["ShoppingCart"]; int prodid1; int prodqty1; int i = 0; gtotal = 0; List <cartitem> abccart = new List <cartitem>(); foreach (KeyValuePair <int, int> productidQty in cartItems1) { prodid1 = productidQty.Key; prodqty1 = productidQty.Value; EntityManager <ProductListing> pcat = new EntityManager <ProductListing>(); ProductListing procat = new ProductListing(); procat.ProductID = prodid1; List <ProductListing> prodcatID = pcat.Search(procat); gtotal = gtotal + prodcatID[0].ListPrice; cartitem mycart = new cartitem() { ID = prodid1, Name = prodcatID[0].Name, ProductNumber = prodcatID[0].ProductNumber, Description = prodcatID[0].Description, Color = prodcatID[0].Color, ListPrice = prodcatID[0].ListPrice, CategoryName = prodcatID[0].CategoryName, ModelName = prodcatID[0].ModelName, Quantity = prodqty1, Totalprice = (prodcatID[0].ListPrice * prodqty1) }; abccart.Add(mycart); } Gv1.DataSource = abccart; Gv1.DataBind(); totalAmountLabel.Text = gtotal.ToString(); }
protected void llena_gv() { string conexionest = ConfigurationManager.ConnectionStrings["conexionsql"].ToString(); SqlConnection sqlCon = new SqlConnection(conexionest); SqlDataAdapter da = new SqlDataAdapter(); DataTable dtResult = new DataTable(); SqlCommand sqlCommand = new SqlCommand("select especialidad_desc from cat_especialidad order by especialidad_desc ", sqlCon); sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandTimeout = 4000; da.SelectCommand = (SqlCommand)sqlCommand; sqlCon.Open(); da.Fill(dtResult); Gv1.DataSource = dtResult; Gv1.DataBind(); }
protected void Gv1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string s = Gv1.DataKeys[e.RowIndex].Value.ToString(); if (xoasanpham(s) == 1) { lbthemsanpham.Text = "Xóa thành công "; } else { lbthemsanpham.Text = "Xóa thất bại"; } SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dl"].ToString()); SqlDataAdapter da = new SqlDataAdapter("select * from sanpham ", con); DataSet ds = new DataSet(); da.Fill(ds, "sanpham"); Gv1.DataSource = ds.Tables["sanpham"]; Gv1.DataBind(); }
protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e) { Gv1.PageIndex = e.NewPageIndex; Gv1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection SqlConnection = new SqlConnection(connectionString); { SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(); SqlCommand SqlCommand = new SqlCommand(); SqlConnection.Open(); SqlCommand.CommandText = "select * from MenuGroup"; SqlCommand.Connection = SqlConnection; SqlDataReader dr = SqlCommand.ExecuteReader(CommandBehavior.CloseConnection); var count = new int(); count = 0; int id; string key; Dictionary <string, int> D = new Dictionary <string, int>(); D.Add("Select a Group", 0); while (dr.Read()) { key = dr["MenuGroupText"].ToString(); id = dr.GetInt32(0); // id = dr.["MenuGroupID"].GetInt32(); D.Add(key, id); count += 1; } SqlConnection.Close(); Ddl1.DataSource = D; Ddl1.DataTextField = "Key"; Ddl1.DataValueField = "Value"; Ddl1.DataBind(); } } else { //this is a post back - pull out fresh data according groupd selected value var x = Ddl1.SelectedValue; string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection SqlConnection = new SqlConnection(connectionString); { SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(); SqlCommand SqlCommand = new SqlCommand(); SqlConnection.Open(); SqlCommand.CommandText = "select MenuItemTitle,MenuItemDescriptionText,MenuItemCost from MenuItem where MenuGroupID =" + x.ToString(); SqlCommand.Connection = SqlConnection; SqlDataReader dr = SqlCommand.ExecuteReader(CommandBehavior.CloseConnection); var count = new int(); count = 0; //int id; //string key; Dictionary <string, int> D = new Dictionary <string, int>(); DataTable DT = new DataTable(); DT.Columns.Add("Price", typeof(string)); DT.Columns.Add("Item", typeof(string)); DT.Columns.Add("Description", typeof(string)); while (dr.Read()) { DT.Rows.Add(dr["MenuItemCost"].ToString(), dr["MenuItemTitle"].ToString(), dr["MenuItemDescriptionText"].ToString()); //key = dr["MenuItemTitle"].ToString(); //id = dr.GetInt32(0); // id = dr.["MenuGroupID"].GetInt32(); //D.Add(key, id); count += 1; } SqlConnection.Close(); DataView v = new DataView(DT); v.Sort = "Item ASC"; Gv1.DataSource = v; Gv1.DataBind(); MessageLabel.Text = ""; //Ddl1.DataSource = D; //Ddl1.DataTextField = "Key"; //Ddl1.DataValueField = "Value"; //Ddl1.DataBind(); } } }
private void BtnAdd_Click(object sender, EventArgs e) { try { if (Gv1.RowCount <= 1) { MessageBox.Show("Is Not DFA! ! No Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Sorted DataGridViewColumn gvc = Gv1.Columns[0] as DataGridViewColumn; Gv1.Sort(gvc, ListSortDirection.Ascending); //End Sorted //این حالتی را بررسی میکند که از یک وضعیت به یک وضعیت دیگه ای رفتیم که وضعیت مقصد برایش //a , b // مشخص نشده است. string StateA, StateB; bool IsExistA = false; bool IsExistB = false; for (int i = 0; i < Gv1.RowCount - 1; i++) { StateA = Gv1.Rows[i].Cells[1].Value.ToString(); StateB = Gv1.Rows[i].Cells[2].Value.ToString(); for (int j = 0; j < Gv1.RowCount - 1; j++) { if (Gv1.Rows[j].Cells[0].Value.Equals(StateA)) { IsExistA = true; } if (Gv1.Rows[j].Cells[0].Value.Equals(StateB)) { IsExistB = true; } } if (!IsExistA) { Gv1.Rows[i].Cells[1].ErrorText = "Not Find in State"; } else { Gv1.Rows[i].Cells[1].ErrorText = ""; } if (!IsExistB) { Gv1.Rows[i].Cells[2].ErrorText = "Not Find in State"; } else { Gv1.Rows[i].Cells[2].ErrorText = ""; } IsExistA = IsExistB = false; } //این حلقه اگر قبلا خطایی اعلام شده بود که رفع نشده باشد را مشخص میکند foreach (DataGridViewRow item in Gv1.Rows) { if (!item.ErrorText.Equals("") || !item.Cells[1].ErrorText.Equals("") || !item.Cells[2].ErrorText.Equals("")) { MessageBox.Show("Not DFA!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (ReadString()) { MessageBox.Show("Accepted", "Accept", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Rejected", "Reject", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ee) { MessageBox.Show("Not DFA!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void Submit_Click(object Sender, EventArgs e) { //if (txtGrade.Value == "" || txtName.Value == "" || txtRanking.Value == "") // Label1.Text = "请输入完整信息"; if (txtGrade.Value == "" || txtName.Value == "") { Label1.Text = "请输入完整信息"; } else { int n = 5; int o = 10; int course = int.Parse(ddlCourse.Value); int batch = int.Parse(ddlBatch.Value); int province = int.Parse(ddlPro.SelectedValue); string name = txtName.Value; MySqlParameter paramGa = new MySqlParameter("?grade", MySqlDbType.Int32); MySqlParameter paramCo = new MySqlParameter("?course", MySqlDbType.Int32); paramCo.Value = course; paramGa.Value = txtGrade.Value; string sqlSelectrank = "select rank from grade_rank where grade =?grade and course=?course"; int Rank = Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.Conn, System.Data.CommandType.Text, sqlSelectrank, paramGa, paramCo)); int gradeadd = int.Parse(txtGrade.Value) + n; int gradecut = int.Parse(txtGrade.Value) - o; int rank = Rank; //grade、rank、course、batch、province、name分别记录分数,排名,文/理科,批次,省份,学生姓名 MySqlParameter[] param = new MySqlParameter[] { new MySqlParameter("?gradeadd", MySqlDbType.Int32), new MySqlParameter("?gradecut", MySqlDbType.Int32), new MySqlParameter("?ranku", MySqlDbType.Int32), new MySqlParameter("?rankd", MySqlDbType.Int32), new MySqlParameter("?province", MySqlDbType.Int32), new MySqlParameter("?batch", MySqlDbType.Int32), new MySqlParameter("?course", MySqlDbType.Int32), new MySqlParameter("?name_record", MySqlDbType.String), new MySqlParameter("?course_record", MySqlDbType.String), new MySqlParameter("?grade_record", MySqlDbType.Int32), new MySqlParameter("?rank_record", MySqlDbType.Int32), new MySqlParameter("?batch_record", MySqlDbType.String), new MySqlParameter("?pro_string", MySqlDbType.String), new MySqlParameter("?datatime", MySqlDbType.DateTime), }; param[0].Value = gradeadd; param[1].Value = gradecut; param[6].Value = course; try { string sql1 = "select rank from grade_rank where grade =?gradeadd and course=?course"; int ranku = Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.Conn, System.Data.CommandType.Text, sql1, param[0], param[6])); string sql2 = "select rank from grade_rank where grade = ?gradecut and course=?course"; int rankd = Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.Conn, System.Data.CommandType.Text, sql2, param[1], param[6])); //查询分数上下界对应的名次 param[2].Value = ranku; param[3].Value = rankd; param[4].Value = province; param[5].Value = batch; string sql3 = "select id,university,city,citypoint,level,levelpoint,rank from(select id,university,city,citypoint,level,levelpoint,rank from univers where rank between ?ranku and ?rankd and province = ?province and batch= ?batch and course= ?course)as a order by rank asc"; ds1 = MySqlHelper.GetDataSet(MySqlHelper.Conn, System.Data.CommandType.Text, sql3, param[2], param[3], param[4], param[5], param[6]); //取出推荐数据 } catch { string str = "数据查询失败"; Label1.Text = str; } dt1 = ds1.Tables[0]; if (dt1.Rows.Count == 0) { Label1.CssClass = "lbl"; Label1.Text = "该部分数据暂未录入"; } else { string sql5 = "select province from typed_in where id = ?province"; param[4].Value = province; string pro_string = Convert.ToString(MySqlHelper.ExecuteScalar(MySqlHelper.Conn, System.Data.CommandType.Text, sql5, param[4])); string sql4 = "insert into record(province,name,course,grade,rank,batch,time)values(?pro_string,?name_record,?course_record,?grade_record,?rank_record,?batch_record,?datatime)"; param[12].Value = pro_string; param[7].Value = name; if (course == 0) { param[8].Value = "理科"; } else { param[8].Value = "文科"; } param[9].Value = int.Parse(txtGrade.Value); param[10].Value = rank; param[13].Value = DateTime.Now.ToString(); switch (batch) { case 0: param[11].Value = "一本"; break; case 1: param[11].Value = "二本"; break; case 2: param[11].Value = "三本"; break; } int i = MySqlHelper.ExecuteNonQuery(MySqlHelper.Conn, System.Data.CommandType.Text, sql4, param[12], param[7], param[8], param[9], param[10], param[11], param[13]); string title = "省份:" + pro_string + " " + " " + " " + "姓名:" + name + " " + "报考类别:" + param[8].Value + " " + "分数:" + txtGrade.Value + " " + "位次:" + rank + " " + "批次:" + param[11].Value; dt1 = Write(dt1, rank, title); //向表中写入数据 //DataTable dt2 = dt1; //dt2.Rows.RemoveAt(0); //dt2.Rows.RemoveAt(1); //dt2.Rows.RemoveAt(2); Gv1.DataSource = dt1; //绑定数据 Gv1.DataBind(); GroupCol(Gv1, 0, 3, 8); GroupCol(Gv1, 0, 8, 13); GroupCol(Gv1, 0, 13, 18); GroupCol(Gv1, 0, 18, 23); GroupCol(Gv1, 0, 23, 28); GroupRow(Gv1, 0, 0, 6); GroupRow(Gv1, 28, 0, 6); GroupRow(Gv1, 29, 0, 6); GroupRow(Gv1, 30, 0, 6); GroupRow(Gv1, 31, 0, 6); GroupRow(Gv1, 32, 0, 6); GroupRow(Gv1, 33, 0, 6); GroupRow(Gv1, 34, 0, 6); GroupRow(Gv1, 35, 0, 6); GroupRow(Gv1, 36, 0, 6); btnExport.Visible = true; //显示导出Excel表按钮; } } // } }