void ca_updatePic(bool topmost) { DataView dv = new DataView(); DataTable dt = MySQLConnection1.GetDataTableValue("select * from staff_info where id = '" + currentID + "'"); dt.TableName = "staff_info"; dv.Table = dt; DataRowView drv = dv[0]; Byte[] Files = (Byte[])drv["pic"]; MemoryStream mysm = new MemoryStream((byte[])drv["pic"]); Image ims = Image.FromStream(mysm); this.pictureBox1.Image = ims; }
private void btn_savpic_Click(object sender, EventArgs e) { string strPath = txt_pic.Text.Trim(); FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read); byte[] byteFile = new byte[fs.Length]; fs.Read(byteFile, 0, (int)fs.Length); fs.Close(); using (MySqlConnection conn = new MySqlConnection(MySQLConnection1.SqlCon)) { string UpdateSql = "update staff_info" + " set pic = @ImgData" + " where id = '" + currentID + "'"; // string sql = "Insert Into picTest Values (@ImgData) "; using (MySqlCommand cmd = new MySqlCommand(UpdateSql)) { MySqlParameter param = new MySqlParameter("ImgData", MySqlDbType.VarBinary, byteFile.Length); param.Value = byteFile; cmd.Parameters.Add(param); cmd.Connection = conn; conn.Open(); int i = cmd.ExecuteNonQuery(); MessageBox.Show("success!"); } } DataView dv = new DataView(); DataTable dt = MySQLConnection1.GetDataTableValue("select * from staff_info where id = '" + currentID + "'"); dt.TableName = "staff_info"; dv.Table = dt; DataRowView drv = dv[0]; Byte[] Files = (Byte[])drv["pic"]; MemoryStream mysm = new MemoryStream((byte[])drv["pic"]); Image ims = Image.FromStream(mysm); this.pictureBox1.Image = ims; }
private void InitTree(TreeNodeCollection Nds, string parentId) { DataView dv = new DataView(); TreeNode tmpNd; string intId; if (local) { DataSet ds = GetDataSet("select * from staff_info"); dv.Table = ds.Tables[0]; } else { DataTable dt = MySQLConnection1.GetDataTableValue("select * from staff_info"); dt.TableName = "staff_info"; dv.Table = dt; } dv.RowFilter = "parent_id='" + parentId + "'"; foreach (DataRowView drv in dv) { tmpNd = new TreeNode(); tmpNd.Tag = drv["id"].ToString(); tmpNd.Text = drv["last_name"].ToString(); if (drv["parent_id"].ToString() == "1") //10 means admin { tmpNd.ImageIndex = tmpNd.SelectedImageIndex = 0; } else { tmpNd.ImageIndex = tmpNd.SelectedImageIndex = 1; } this.treeView1.BeginUpdate(); Nds.Add(tmpNd); this.treeView1.EndUpdate(); intId = drv["parent_id"].ToString(); InitTree(tmpNd.Nodes, tmpNd.Tag.ToString()); } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { currentID = int.Parse(e.Node.Tag.ToString()); if (e.Action == TreeViewAction.ByMouse) { DataView dv = new DataView(); if (local) { DataSet ds = GetDataSet("select * from staff_info where id = '" + e.Node.Tag + "'"); dv.Table = ds.Tables[0]; } else { DataTable dt = MySQLConnection1.GetDataTableValue("select * from staff_info where id = '" + e.Node.Tag + "'"); dt.TableName = "staff_info"; dv.Table = dt; } DataRowView drv = dv[0]; if (e.Node.Parent != null) { txt_name.Text = drv["last_name"].ToString(); if (drv["gender"].ToString() == "Male") { comBox_gender.SelectedIndex = 0; } else { comBox_gender.SelectedIndex = 1; } txt_SSN.Text = drv["ssn"].ToString(); if (drv["parent_id"].ToString() == "1") { cmb_position.SelectedIndex = 0; } if (drv["parent_id"].ToString() == "2") { cmb_position.SelectedIndex = 1; } if (drv["parent_id"].ToString() == "3") { cmb_position.SelectedIndex = 2; } if (drv["parent_id"].ToString() == "4") { cmb_position.SelectedIndex = 3; } txt_Phone.Text = drv["phone"].ToString(); txt_Address.Text = drv["address_id"].ToString(); if (!drv["birthday"].Equals(System.DBNull.Value)) { dateTimePicker1.Value = Convert.ToDateTime(drv["Birthday"]); } else { dateTimePicker1.Value = System.DateTime.Today; } if (!drv["pic"].Equals(System.DBNull.Value)) { Byte[] Files = (Byte[])drv["pic"]; MemoryStream mysm = new MemoryStream((byte[])drv["pic"]); Image ims = Image.FromStream(mysm); this.pictureBox1.Image = ims; } else { this.pictureBox1.Image = null; } txt_Email.Text = drv["email"].ToString(); toolStripButton2.Enabled = true; btn_del.Enabled = true; } else { toolStripButton2.Enabled = false; btn_del.Enabled = false; } } }