int IdCount = 0; //已删除的归档号数量 public ConfidentialMembers_EquipmentFiling() { InitializeComponent(); InitTable(); Initttalbm(); TableToArmsData.DataTableSelect(SQLStr, "更新"); TableToArmsData.dataGrid.SelectionChanged += TableToArmsData_SelectionChanged; dt = TableToArmsData.Getdt(); DateOftotal.Content = dt.Rows.Count;//获取总行数 }
private void SubmitToadd_Click(object sender, RoutedEventArgs e) { bool TempBool = true; if (Convert.ToInt32(ICount.Text) < 0) { MessageBox.Show("错误:数量不能为负数!"); return; } else if (Memo.Text.Length > 100) { MessageBox.Show("错误:说明不能超过一百字!"); return; } string GreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToLongTimeString().ToString();; //获取当前时间 string SQL1 = "insert into ArmsData values ('" + DataNo.Text + "','" + DataName.Text + "'," + Convert.ToInt32(Typeld.Text) + "," + Convert.ToInt32(ICount.Text) + "," + Convert.ToDecimal(IPrice.Text) + ",'" + Memo.Text + "','" + GreateDate + "')"; string SQL2 = "insert into Types values ('" + Typeld.Text + "','" + TypeName.Text + "',1)";//插入到类型表 string SQL3 = "select * from Types where TypeId = '" + Typeld.Text + "'"; string SQL4 = "select * from ArmsData where DataNo = '" + DataNo.Text + "'"; try { SqlCommand CMD_1 = new SqlCommand(SQL4, Temp.GetConn()); SqlDataReader Sdr_1 = CMD_1.ExecuteReader(); if (Sdr_1.Read()) { Sdr_1.Close(); MessageBox.Show("已有编号为 " + Typeld.Text + " 的资料!", "警告"); return; } Sdr_1.Close(); CMD_1.CommandText = SQL3; Sdr_1 = CMD_1.ExecuteReader(); if (Sdr_1.Read()) { Sdr_1.Close(); MessageBoxResult dr = MessageBox.Show("已有编号为 " + Typeld.Text + " 的分类,你确定要挂载到此分类编号下吗?", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (dr == MessageBoxResult.Cancel) { return; } TempBool = false; } if (TempBool) { CMD_1.CommandText = SQL2; CMD_1.ExecuteNonQuery(); } CMD_1.CommandText = SQL1; CMD_1.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("错误:类型编号重复,或不可重复添加!" + ex); return; } TableToArmsData.DataTableSelect(SQLStr, "更新"); dt = TableToArmsData.Getdt(); DateOftotal.Content = dt.Rows.Count;//获取总行数 }