private void PersonalInfo_Load(object sender, EventArgs e) { treeView1.ExpandAll(); InitTree(this.treeView1.Nodes, "0"); treeView1.ExpandAll(); toolStrip_save.Enabled = false; toolStripButton2.Enabled = false; MySQLConnection1.OpenConn(); }
void initialChart(string type, Boolean showAll) { string sql; chart1.Series.Clear();//清理掉默认的图表 然后重新添加 DataTable ds = new DataTable(); if (showAll) { sql = "select * from statistics"; } else { sql = "SELECT * FROM statistics WHERE DATE BETWEEN '" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "' AND '" + dateTimePicker2.Value.ToString("yyyy-MM-dd") + "'"; } MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection1.SqlCon); MySqlDataAdapter sda = new MySqlDataAdapter(sql, MySqlCon); MySQLConnection1.OpenConn(); sda.Fill(ds); if (type == "line") { Series ss = new Series("income"); //这里 dt1 ,dt2 任意取名称,但要唯一 ss.Points.DataBind(ds.AsEnumerable(), "date", "income", ""); ss.XValueType = ChartValueType.DateTime; //设置X轴 ss.ChartType = SeriesChartType.Spline; //设置Y轴为折线 chart1.Series.Add(ss); if (checkBox_cost.Checked) { Series ss1 = new Series("cost"); //这里 dt1 ,dt2 任意取名称,但要唯一 ss1.Points.DataBind(ds.AsEnumerable(), "date", "cost", ""); ss1.XValueType = ChartValueType.DateTime; //设置X轴 ss1.ChartType = SeriesChartType.Spline; //设置Y轴为折线 chart1.Series.Add(ss1); } } else if (type == "pie") { Series s = chart1.Series.Add("饼图"); // //设置图标名称 //s.ChartArea = "ChartArea" + j; //图表类型 折线 柱状 圆形 s.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie; s.BorderWidth = 3; s.ShadowOffset = 1; s.IsValueShownAsLabel = true; //是否在图表上显示数据的值 s.XValueType = ChartValueType.Int32; s.MarkerStyle = MarkerStyle.Circle; //数据点样式 List <string> xData1 = new List <string>(); //声明两个集合将数据先放在集合中 List <string> yData1 = new List <string>(); for (int i = 0; i < ds.Rows.Count; i++) // { //将数据先放在集合中 xData1.Add(ds.Rows[i]["date"].ToString()); yData1.Add(ds.Rows[i]["income"].ToString()); } //循环结束后,绑定数据源 chart1.Series[0].Points.DataBindXY(xData1, yData1); } // chart2.Series.Add(ss); //第二条数据 ////第三条数据 //string sql2 = "SELECT * FROM APiece WHERE APiece.Piece_PId=3"; //DataTable ds2 = new DataTable(); //SqlDataAdapter sda2 = new SqlDataAdapter(sql2, con); //sda2.Fill(ds2); //Chart1.DataSource = ds2; //Series ss3 = new Series("产品3"); //ss3.Points.DataBind(ds2.AsEnumerable(), "Piece_Time", "Piece_Level", ""); //ss3.XValueType = ChartValueType.DateTime; //设置X轴 //ss3.ChartType = SeriesChartType.Spline; //设置Y轴为折线 //Chart1.Series.Add(ss3); }
private void insertData() { int parentID = 0; if (cmb_position.SelectedIndex == 0) { parentID = 1; } if (cmb_position.SelectedIndex == 1) { parentID = 2; } if (cmb_position.SelectedIndex == 2) { parentID = 3; } if (cmb_position.SelectedIndex == 3) { parentID = 4; } if (!IsEmail(txt_Email.Text)) { MessageBox.Show("the email address is invalid"); } else { string InsertSql = "insert into staff_info(last_name,address_id,phone,parent_id,gender,birthday,ssn,email) " + "values ('" + txt_name.Text + "','" + txt_Address.Text + "','" + txt_Phone.Text + "','" + parentID + "','" + comBox_gender.Text + "','" + dateTimePicker1.Value.Date.ToString("yyyy-MM-dd HH:mm") + "','" + txt_SSN.Text + "','" + txt_Email.Text + "')"; try { if (local) { SqlConnection sqlcon = new SqlConnection(strcon); sqlcon.Open(); SqlCommand com = new SqlCommand(InsertSql, sqlcon); com.ExecuteNonQuery(); SqlDataAdapter ada = new SqlDataAdapter("select * from staff_info", sqlcon); DataSet ds = new DataSet(); ada.Fill(ds, "staff_info"); sqlcon.Close(); } else { MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection1.SqlCon); MySqlCon.Open(); MySQLConnection1.OpenConn(); MySqlCommand com = new MySqlCommand(InsertSql, MySqlCon); com.ExecuteNonQuery(); MySqlDataAdapter ada = new MySqlDataAdapter("select * from staff_info", MySqlCon); DataSet ds = new DataSet(); ada.Fill(ds, "staff_info"); MySQLConnection1.CloseConn(); } MessageBox.Show("successful"); treeView1.Nodes.Clear(); InitTree(this.treeView1.Nodes, "0"); treeView1.ExpandAll(); } catch (Exception ex) { MessageBox.Show(ex.Message); } toolStripButton1.Text = "Add"; toolStripButton1.Image = imageList1.Images[2]; toolStripButton1.Enabled = true; initial(); } }