private void FillComboBox1() { sqlCmd.Connection = MyDataBase.GetConn(); sqlCmd.CommandType = CommandType.Text; sqlCmd.CommandText = "select MerchandiseName from Merchandise"; OleDbDataReader reader = sqlCmd.ExecuteReader(); while (reader.Read()) { Trace.WriteLine(reader[0].ToString()); comboBox1.Items.Add(reader[0].ToString()); } reader.Close(); comboBox1.Text = comboBox1.Items[0].ToString(); }
private void MerchandiseInfoDisplayDlg_Load(object sender, EventArgs e) { stockCountsText.KeyPress += new KeyPressEventHandler(characterRestrain.IntRestrain_KeyPress); existingCountsText.KeyPress += new KeyPressEventHandler(characterRestrain.IntRestrain_KeyPress); comboBox1.Items.Add(""); sqlCmd.CommandType = CommandType.Text; sqlCmd.Connection = MyDataBase.GetConn(); sqlCmd.CommandText = @"select merchandisename from merchandise"; OleDbDataReader reader = sqlCmd.ExecuteReader(); while (reader.Read()) { comboBox1.Items.Add(reader[0].ToString()); } reader.Close(); comboBox1.Text = comboBox1.Items[0].ToString(); InitCombo(); }
private void UpdateDataGridView() { OleDbConnection objConnection = MyDataBase.GetConn(); sqlcmd.CommandText = @"select MerchandiseName,StockCounts,ExitingCounts from Merchandise"; sqlcmd.Connection = objConnection; sqlcmd.CommandType = CommandType.Text; OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = sqlcmd; DataSet ds = new DataSet(); da.Fill(ds, "table1"); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.Columns[0].HeaderCell.Value = "商品名称"; dataGridView1.Columns[1].HeaderCell.Value = "库存"; dataGridView1.Columns[2].HeaderCell.Value = "现存"; }
private void SaleRecordQueryDlg_Load(object sender, EventArgs e) { toolTip1.SetToolTip(timedateText, "日期格式:2011-01-01"); toolTip1.Active = true; toolTip1.UseAnimation = true; timedateText.KeyPress += new KeyPressEventHandler(characterRestrain.TimedateRestrain_KeyPress); merchandiseNameCombo.Items.Add(""); sqlCmd.CommandType = CommandType.Text; sqlCmd.Connection = MyDataBase.GetConn(); sqlCmd.CommandText = @"select merchandisename from merchandise"; OleDbDataReader reader = sqlCmd.ExecuteReader(); while (reader.Read()) { merchandiseNameCombo.Items.Add(reader[0].ToString()); } reader.Close(); merchandiseNameCombo.Text = merchandiseNameCombo.Items[0].ToString(); }
public void Form1_FormClosed(Object sender, EventArgs e) { MyDataBase.CloseConn(); }
private void AddMerchandise_Click(object sender, EventArgs e) { string strName = listBox1.SelectedItem.ToString(); int stockCounts = System.Convert.ToInt32(textBox2.Text); int extingCounts = System.Convert.ToInt32(ExtingCountText.Text); OleDbConnection conn = MyDataBase.GetConn(); if (AddMerchandise.Text.Equals("添加")) { string strCmd1 = @"update Merchandise set StockCounts=StockCounts+" + stockCounts.ToString(); strCmd1 += @" where MerchandiseName='" + strName + "'"; string strCmd2 = @"update Merchandise set ExitingCounts=ExitingCounts+" + stockCounts.ToString(); strCmd2 += @" where MerchandiseName='" + strName + "'"; int iRows = 0; sqlcmd.CommandText = strCmd1; iRows = sqlcmd.ExecuteNonQuery(); if (iRows == 0) { MessageBox.Show("添加失败,请查证后重新添加。"); return; } sqlcmd.CommandText = strCmd2; iRows = sqlcmd.ExecuteNonQuery(); if (iRows == 0) { MessageBox.Show("添加失败,请查证后重新添加。"); return; } SetText(); ////////////////////////////////////////////////////////////////////////// //添加出售信息 string timeDate = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); string strCmd3 = @"INSERT INTO stockmerchandise ( merchandisename, timedate, stockcounts ) values('" + strName + "','" + timeDate + "'," + stockCounts.ToString() + ")"; sqlcmd.CommandText = strCmd1; iRows = sqlcmd.ExecuteNonQuery(); if (iRows == 0) { MessageBox.Show("添加失败,请查证后重新添加。"); return; } } else if (AddMerchandise.Text.Equals("更新")) { string strCmd1 = @"update Merchandise set StockCounts=" + stockCounts.ToString(); strCmd1 += @" where MerchandiseName='" + strName + "'"; string strCmd2 = @"update Merchandise set ExitingCounts=" + extingCounts.ToString(); strCmd2 += @" where MerchandiseName='" + strName + "'"; int iRows = 0; sqlcmd.CommandText = strCmd1; iRows = sqlcmd.ExecuteNonQuery(); if (iRows == 0) { MessageBox.Show("更新失败,请查证后重新添加。"); return; } sqlcmd.CommandText = strCmd2; iRows = sqlcmd.ExecuteNonQuery(); if (iRows == 0) { MessageBox.Show("更新失败,请查证后重新添加。"); return; } ExtingCountText.Visible = false; ExtingCountLable.Visible = false; AddMerchandise.Text = "添加"; SetText(); } if (dataGridView1.SelectedRows.Count != 0) { if (dataGridView1.SelectedRows[0].Cells.Count > 1) { DataGridViewRow dRow = dataGridView1.SelectedRows[0]; for (int i = 0; i < dataGridView1.RowCount; i++) { string str = dRow.Cells[0].Value.ToString(); Trace.WriteLine(str); if (str.Equals(strName)) { Trace.WriteLine("Enter if :"); dataGridView1.CurrentCell = dataGridView1[0, 1]; } } } } UpdateDataGridView(); }