MySqlConnection conn = new MySqlConnection(GetConn.connection); //连接对象 private void button1_Click_1(object sender, EventArgs e) //添加样机按钮 { string PhoneStatus = "在库"; string PhoneCode = this.txtPhoneCode.Text; //PhoneID作为主键,可以在程序中自动生成,此处无需添加 string PhoneName = this.txtPhoneName.Text; string PhoneStage = this.cbbPhoneStage.Text; string PhoneNum = this.txtPhoneNum.Value.ToString(); string PhoneOwner = this.cbbPhoneOwner.Text; string PhoneInf1 = this.cbbInf1.Text; string PhoneInf2 = this.cbbInf2.Text; string PhoneInf3 = this.cbbInf3.Text; string PhoneInf4 = this.cbbInf4.Text; string PhoneNote = PhoneInf1 + "_" + PhoneInf2 + "_" + PhoneInf3 + "_" + PhoneInf4; PhoneBLL phonebll = new PhoneBLL(); //建立对象 if (this.txtPhoneName.Text == "" || this.cbbPhoneStage.Text == "" || this.txtPhoneNum.Value.ToString() == "" || this.cbbPhoneOwner.Text == "") { MessageBox.Show("样机名称,样机阶段,接口人信息必填", "提示"); return; } else if (phonebll.AddPhone(PhoneCode, PhoneName, PhoneStage, PhoneNum, PhoneStatus, PhoneNote, PhoneOwner, LoginForm.usrName)) { MessageBox.Show("数据上传成功!"); } phones = phonebll.getAllPhones(); //刷新选项内容 PhoneDataGrid.DataSource = phones; this.txtPhoneCode.Clear(); }
private void button1_Click(object sender, EventArgs e) //将不需要显示的样机字段改变 { PhoneBLL phonebll = new PhoneBLL(); string PhoneNameD = this.cbbPhoneNameD.Text; string PhoneStageD = this.cbbPhoneStageD.Text; string PhoneDisplay = this.cbbPhoneDisplay.Text; if (cbbPhoneNameD.Text == "" || cbbPhoneStageD.Text == "" || cbbPhoneDisplay.Text == "") { MessageBox.Show("请通过样机名称 与 样机阶段 进行选择", "提示"); return; } if (MessageBox.Show("确定对选中的样机名称与样机阶段进行操作?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (phonebll.updatePhoneDisplay(PhoneNameD, PhoneStageD, PhoneDisplay)) { MessageBox.Show("更新样机状态成功", "提示"); } else { MessageBox.Show("更新失败,请检查信息是否正确", "提示"); } } else { //不执行任务 } phones = phonebll.getAllPhones(); PhoneDataGrid.DataSource = phones; //将数据库中的数据提到列表中,再通过 DataGrid控件显示; }
private void button1_Click(object sender, EventArgs e) //显示全部 { PhoneBLL phonebll = new PhoneBLL(); phones = phonebll.getAllPhones(); phoneDataGrid.DataSource = phones; this.txtPhoneNum.Clear(); this.cbbPhoneName.Text = ""; this.cbbPhoneStage.Text = ""; this.cbbPhoneStatus.Text = ""; }
private void btnDelete_Click(object sender, EventArgs e) //根据样机码删除样机 { string phoneCode = this.txtPhoneCode.Text; PhoneBLL phonebll = new PhoneBLL(); if (txtPhoneCode.Text == "") { MessageBox.Show("请通过输入样机码进行样机删除", "提示"); return; } if (MessageBox.Show("确定要删除该条样机信息吗?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (phonebll.delByPhoneCode(phoneCode)) { MessageBox.Show("删除成功!", "提示"); } else { MessageBox.Show("删除失败,请检查信息是否正确", "提示"); } } else { //不执行任务 } phones = phonebll.getAllPhones(); PhoneDataGrid.DataSource = phones; this.txtPhoneCode.Clear(); this.txtPhoneName.Clear(); this.cbbPhoneStage.Text = ""; this.cbbInf1.Text = ""; this.cbbInf2.Text = ""; this.cbbInf3.Text = ""; this.cbbInf4.Text = ""; this.cbbPhoneOwner.Text = ""; }
private void PhoneInfoForm_Load(object sender, EventArgs e) { cbbPhoneDisplay.DropDownStyle = ComboBoxStyle.DropDownList; cbbPhoneNameD.DropDownStyle = ComboBoxStyle.DropDownList; cbbPhoneStageD.DropDownStyle = ComboBoxStyle.DropDownList; cbbPhoneOwner.DropDownStyle = ComboBoxStyle.DropDown; cbbPhoneStage.DropDownStyle = ComboBoxStyle.DropDown; this.Width = Fuctions.winFormWidth; this.Height = Fuctions.winFormHeight; PhoneBLL phonebll = new PhoneBLL(); phones = phonebll.getAllPhones(); PhoneDataGrid.DataSource = phones; //将数据库中的数据提到列表中,再通过 DataGrid控件显示; PhoneDataGrid.ReadOnly = true; PhoneDataGrid.Width = Fuctions.dataGridViewWidth; //PhoneDataGrid.Height = 300; PhoneDataGrid.Location = new Point(Fuctions.dataGridViewLocationX, Fuctions.dataGridViewLocationY); PhoneDataGrid.Columns[0].HeaderText = "主键"; //修改显示的列名 PhoneDataGrid.Columns[0].Visible = false; PhoneDataGrid.Columns[1].HeaderText = "Phone ID"; PhoneDataGrid.Columns[2].HeaderText = "名称"; PhoneDataGrid.Columns[3].HeaderText = "阶段"; PhoneDataGrid.Columns[4].HeaderText = "编号"; PhoneDataGrid.Columns[5].HeaderText = "状态"; PhoneDataGrid.Columns[6].HeaderText = "备注"; PhoneDataGrid.Columns[7].HeaderText = "接口人"; PhoneDataGrid.Columns[8].HeaderText = "显示"; PhoneDataGrid.Columns[8].Visible = false; PhoneDataGrid.Columns[9].HeaderText = "主管"; PhoneDataGrid.Columns[10].HeaderText = "启用时间"; PhoneDataGrid.Columns[1].Width = 80; PhoneDataGrid.Columns[2].Width = Fuctions.dataGridViewPhoneName; PhoneDataGrid.Columns[3].Width = 80; PhoneDataGrid.Columns[4].Width = Fuctions.dataGridViewPhoneNum;; PhoneDataGrid.Columns[5].Width = 50; PhoneDataGrid.Columns[6].Width = Fuctions.dataGridViewNote; PhoneDataGrid.Columns[7].Width = 50; PhoneDataGrid.Columns[8].Width = 50; PhoneDataGrid.Columns[9].Width = 50; PhoneDataGrid.Columns[10].Width = 120; Fuctions.AutoSize(PhoneDataGrid); //StageBLL stagebll = new StageBLL(); //从数据库中读出状态信息,显示于CBB中。 //stages = stagebll.getAllStages(); //cbbPhoneStage.DataSource = stages; //cbbPhoneStage.DisplayMember = "StageName"; //cbbPhoneStage.ValueMember = "StageName"; //cbbPhoneStage.SelectedIndex = -1; //cbbPhoneStage.Text = ""; //***********************************************样机是否显示 cbb内容更新 string strSql = "select distinct PhoneName from PmPhone order by PhoneName asc"; //样机名称cbbD内容加载 MySqlCommand cmd = new MySqlCommand(strSql, conn); MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); conn.Open(); da.Fill(ds, "PmPhone"); conn.Close(); cbbPhoneNameD.DisplayMember = "PhoneName"; cbbPhoneNameD.ValueMember = "PhoneName"; cbbPhoneNameD.DataSource = ds.Tables["PmPhone"]; cbbPhoneNameD.SelectedIndex = -1; //cbbPhoneNameD.Text = ""; }
MySqlConnection conn = new MySqlConnection(GetConn.connection); //连接对象 private void PhoneQueryForm_Load(object sender, EventArgs e) //窗体出现时加载所有样机 { this.Width = 1070; this.Height = 760; //通过列表方法获取数据,有点不方便 PhoneBLL phonebll = new PhoneBLL(); phones = phonebll.getAllPhones(); phoneDataGrid.DataSource = phones; phoneDataGrid.ClearSelection(); phoneDataGrid.ReadOnly = true; //phoneDataGrid.Width = Fuctions.dataGridViewWidth; //phoneDataGrid.Height = Fuctions.dataGridViewHeight; //phoneDataGrid.Location = new Point(43, 12); phoneDataGrid.Columns[0].HeaderText = "主键"; //修改显示的列名 phoneDataGrid.Columns[0].Visible = false; phoneDataGrid.Columns[1].HeaderText = "序列号"; phoneDataGrid.Columns[2].HeaderText = "名称"; phoneDataGrid.Columns[3].HeaderText = "阶段"; phoneDataGrid.Columns[4].HeaderText = "编号"; phoneDataGrid.Columns[5].HeaderText = "状态"; phoneDataGrid.Columns[6].HeaderText = "备注"; phoneDataGrid.Columns[7].HeaderText = "接口人"; phoneDataGrid.Columns[8].HeaderText = "显示"; phoneDataGrid.Columns[8].Visible = false; phoneDataGrid.Columns[9].HeaderText = "主管"; phoneDataGrid.Columns[10].HeaderText = "启用时间"; phoneDataGrid.Columns[1].Width = 80; phoneDataGrid.Columns[2].Width = Fuctions.dataGridViewPhoneName; phoneDataGrid.Columns[3].Width = 80; phoneDataGrid.Columns[4].Width = Fuctions.dataGridViewPhoneNum; phoneDataGrid.Columns[5].Width = 50; phoneDataGrid.Columns[6].Width = Fuctions.dataGridViewNote; phoneDataGrid.Columns[7].Width = 50; phoneDataGrid.Columns[8].Width = 50; phoneDataGrid.Columns[9].Width = 50; phoneDataGrid.Columns[10].Width = 120; //Fuctions.AutoSize(phoneDataGrid); //获取数据库中 pmstage表中的 值,但是后来没在用,因为其中的数据不全,测试主管一直在改 //StageBLL stagebll = new StageBLL(); //stages = stagebll.getAllStages(); //cbbPhoneStage.DataSource = stages; //cbbPhoneStage.DisplayMember = "StageName"; //cbbPhoneStage.ValueMember = "StageName"; //cbbPhoneStage.Text = ""; //说明:一个dataSet中可以放多个dataTable。 string strSql = "select distinct PhoneName from PmPhone where PhoneStatus = '在库' and PhoneDisplay = 'TRUE'"; //样机名称combobox内容加载 MySqlCommand cmd = new MySqlCommand(strSql, conn); MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); conn.Open(); da.Fill(ds, "PmPhone"); conn.Close(); cbbPhoneName.DisplayMember = "PhoneName"; cbbPhoneName.ValueMember = "PhoneName"; cbbPhoneName.DataSource = ds.Tables["PmPhone"]; cbbPhoneName.Text = ""; /**************************************************************************************************************************** * 目的:显示产线数据库中数据信息 * 方法:将mysql中样机的Phoneid作为条件向产线sql server数据库申请数据,两个数据显示于一个datagridview中 * 结果:失败 * 原因分析:从两个数据库中获取的信息各存放于一个datatable中,这两个datatable无法实现拼接 * try * { * //测试用的datagridview 测试用 此数据库使用 mysql * string strSqlTry = "select PhoneId from PmPhone where PhoneStatus = '在库' and PhoneDisplay = 'TRUE'"; //样机名称combobox内容加载 * MySqlCommand cmdTry = new MySqlCommand(strSqlTry, conn); * * MySqlDataAdapter daTry = new MySqlDataAdapter(cmdTry); * DataSet dsTry = new DataSet(); * conn.Open(); * daTry.Fill(dsTry, "PmPhoneTry"); * * conn.Close(); * * DataTable dtsource = new DataTable(); * * SqlConnection connSql = new SqlConnection(GetConn.sqlConn); //连接对象 * for (int i = 0; i < dsTry.Tables["PmPhoneTry"].Rows.Count; i++) * { * string id = dsTry.Tables["PmPhoneTry"].Rows[i]["PhoneId"].ToString(); * * * //测试用 sql server数据库 通过datatable获取数据 * * string strSqlTry1 = "SELECT distinct PhoneID FROM [Hts2007].[dbo].[ESNRecord] where PhoneID= "+ "'"+id+"'"; //样机名称combobox内容加载 * SqlCommand cmdTry1 = new SqlCommand(strSqlTry1, connSql); * * SqlDataAdapter daTry1 = new SqlDataAdapter(cmdTry1); * * connSql.Open(); * daTry1.Fill(dsTry, "PmPhoneTry1"); * connSql.Close(); * * dtsource.Merge(dsTry.Tables["PmPhoneTry1"]); * * } * * * TryDataGrid.DataSource = dtsource; * * * //测试用的datagridview * string strSqlTry1 = "select PhoneName from PmPhone where PhoneStatus = '在库' and PhoneDisplay = 'TRUE'"; //样机名称combobox内容加载 * MySqlCommand cmdTry1 = new MySqlCommand(strSqlTry1, conn); * * MySqlDataAdapter daTry1 = new MySqlDataAdapter(cmdTry1); * conn.Open(); * * daTry1.Fill(dsTry, "PmPhoneTry1"); * * conn.Close(); * * * DataTable dtLast = new DataTable(); * dtLast.Columns.Add("phoneNa", typeof(string)); * dtLast.Columns.Add("PhoneNa1", typeof(string)); * * var results = (from d1 in dsTry.Tables[0].AsEnumerable() * join d2 in dsTry.Tables[1].AsEnumerable() * on d1.Field<string>("PhoneName") equals d2.Field<string>("PhoneName") * select dtLast.LoadDataRow(new object[] {d1.Field<string>("PhoneName"),d2.Field<string>("PhoneName")},true)); * * dtLast = results.CopyToDataTable<DataRow>(); * * * ////绑定数据源 * TryDataGrid.DataSource = dtLast; * * * //测试用 sql server数据库 通过datatable获取数据 * SqlConnection connSql = new SqlConnection(GetConn.sqlConn); //连接对象 * string strSqlTry1 = "SELECT distinct PhoneID FROM [Hts2007].[dbo].[ESNRecord] "; //样机名称combobox内容加载 * SqlCommand cmdTry1 = new SqlCommand(strSqlTry1, connSql); * * SqlDataAdapter daTry1 = new SqlDataAdapter(cmdTry1); * * connSql.Open(); * daTry1.Fill(dsTry, "PmPhoneTry1"); * connSql.Close(); * * TryDataGrid.DataSource = dsTry.Tables["PmPhoneTry1"]; * } * * catch (System.Exception ex) * { * MessageBox.Show(ex.Message); * } * */ //方法2:分别将mysql数据库 与 sql server数据库提取的信息放于两个datagridview中。 }