private void updatestock(int new_stock) { DataGridViewRow newData = dataitem.Rows[indexRow]; newData.Cells[0].Value = isiCode.Text; newData.Cells[1].Value = isiitems.Text; newData.Cells[2].Value = isiprice.Text; newData.Cells[3].Value = new_stock.ToString(); string sLine = ""; dataitem.Refresh(); int count = dataitem.Rows.Count; File.WriteAllText("items.txt", String.Empty); for (int r = 0; r < count; r++) { int colCount = dataitem.Rows[r].Cells.Count; for (int c = 0; c < colCount; c++) { sLine = sLine + dataitem.Rows[r].Cells[c].Value; if (c != dataitem.Columns.Count - 1) { sLine = sLine + ";"; } } sLine += "\r\n"; } Cmanipulation objManipulation = new Cmanipulation(); objManipulation.UpdateItem("items.txt", sLine); }
private void btndel_Click(object sender, EventArgs e) { DialogResult result; if (this.datatotal.SelectedRows.Count > 0) { result = MessageBox.Show("Are you sure you want to delete:", "Insert new data", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); int new_stock = 0; if (result == DialogResult.OK) { new_stock = Convert.ToInt32(stock); updatestock(new_stock); datatotal.Rows.RemoveAt(this.datatotal.SelectedRows[0].Index); string sLine = ""; datatotal.Refresh(); dataitem.Refresh(); int count = datatotal.Rows.Count; File.WriteAllText("datatest.txt", String.Empty); for (int r = 0; r < count; r++) { int colCount = datatotal.Rows[r].Cells.Count; for (int c = 0; c < colCount; c++) { sLine = sLine + datatotal.Rows[r].Cells[c].Value; if (c != datatotal.Columns.Count - 1) { sLine = sLine + ";"; } } sLine += "\r\n"; } Cmanipulation k = new Cmanipulation(); k.UpdateItem("datatest.txt", sLine); MessageBox.Show("Your data successfully deleted! :)"); totalbarang -= Convert.ToInt32(price) * Convert.ToInt32(qty2); isitotal2.Text = Convert.ToString(totalbarang); } } else { MessageBox.Show("You must select one row!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }