public FrmView() { theController = new Controller(this, "sqlite"); InitializeComponent(); dgvRecord.EditMode = DataGridViewEditMode.EditOnEnter; theController.TakeQuery("SELECT COUNT(A_ID) FROM acquisition");//, "get amount"); c = Convert.ToInt32(theController.getOutcome(0)); dgvRecord.Rows.Add((++c).ToString()); refreshDropDowns(); }
private void btnSend_Click(object sender, EventArgs e) { foreach (DataGridViewRow y in dgvRecord.Rows) { ++rows; if (y.Cells[6].Value == null) { MessageBox.Show("Wähle eine Kategorie aus."); rows = 0; return; } if (y.Cells[8].Value == null) { MessageBox.Show("Wähle einen Ort aus."); rows = 0; return; } if (y.Cells[7].Value == null) { MessageBox.Show("Wähle einen Shop aus."); rows = 0; return; } foreach (DataGridViewCell x in y.Cells) { if (x.Value == null || x.Value.Equals("")) { x.Value = "none"; } dgvData.Add(x.Value.ToString()); } } for (int i = 0; i < rows; i++) { switch (record) { case "exp": theController.TakeQuery("SELECT catID FROM categories WHERE catName = '" + dgvData[6 + (i * 9)] + "' "); //, "Get Category ID"); string cat = theController.getOutcome(0); theController.TakeQuery("SELECT L_ID FROM locations WHERE L_name = '" + dgvData[8 + (i * 9)] + "' "); //, "Get Location ID"); string loc = theController.getOutcome(0); theController.TakeQuery("SELECT C_ID FROM company WHERE C_name = '" + dgvData[7 + (i * 9)] + "' "); //, "Get Company ID"); string shop = theController.getOutcome(0); string myPrice = dgvData[4 + (i * 9)].ToString(); myPrice = myPrice.Replace(',', '.'); theController.TakeInsert("INSERT INTO product(P_amount, P_name, P_description, P_price, P_category) VALUES('" + dgvData[1 + (i * 9)] + "','" + dgvData[2 + (i * 9)] + "','" + dgvData[3 + (i * 9)] + "','" + myPrice + "', '" + cat + "')"); //, "insert product"); string lastID = theController.getSQLiteLastInsert(); theController.TakeInsert("INSERT INTO acquisition(A_product, A_date, A_shop, A_loc) VALUES('" + lastID + "', '" + convertDate(dgvData[5 + (i * 9)].ToString()) + "', '" + shop + "', '" + loc + "')"); //, "insert acquisition"); break; case "ear": break; case "deb": break; case "bor": break; } } rows = 0; for (int p = dgvRecord.Rows.Count - 1; p >= 0; p--) { dgvRecord.Rows.RemoveAt(p); } theController.TakeQuery("SELECT COUNT(A_ID) FROM acquisition");//, "get amount"); c = Convert.ToInt32(theController.getOutcome(0)); dgvRecord.Rows.Add((++c).ToString()); dgvData.Clear(); }