private void btnUpdate_Click(object sender, EventArgs e) { List <String> myContents = new List <String>(); // ghi lại nội dung trên file int r = dgvData.RowCount; int c = dgvData.ColumnCount; for (int i = 0; i < r - 1; i++) { String lineContents = ""; for (int j = 0; j < c; j++) { // lineContents = lineContents+ '\'' + hash.Encrypt(dgvData.Rows[i].Cells[j].Value.ToString()); lineContents = lineContents + '\'' + dgvData.Rows[i].Cells[j].Value.ToString(); } myContents.Add(lineContents); } wF.write_Table_Contents(myContents, tb, db); MessageBox.Show("Đã updates dữ liệu"); isUpdate = true; }
private void btnHoanThanh_Click(object sender, EventArgs e) { if (txtTableName.Text.Trim().Equals("")) { MessageBox.Show("Tên bảng không được để trống"); txtTableName.Focus(); return; } List <Field> myField_1 = new List <Field>(); if (isAlter == 1) { myField_1 = rF.read_File_Infor(cmbTables.SelectedValue.ToString(), cmbDatabase.SelectedValue.ToString()); } List <int> delete_index = new List <int>(); List <Field> myField = new List <Field>(); for (int i = 0; i <= colCount; i++) { String text1 = getText("txtColName" + i.ToString()); String text2 = getText("txtColPro" + i.ToString()); bool text3 = isCheck("chk" + i.ToString()); if (!text1.Trim().Equals("") && !text2.Trim().Equals("")) { Field fi = new Field(text1, text2, text3); myField.Add(fi); } else { if (isAlter == 1) { delete_index.Add(i); } } } if (isAlter == 1) { try { rF.delete_file("database/" + cmbDatabase.SelectedValue.ToString() + "/" + cmbTables.SelectedValue.ToString() + "inf_.txt"); } catch { } } wF.write_Table_Infor(myField, txtTableName.Text.Trim(), cmbDatabase.SelectedValue.ToString()); if (isAlter == 1) { if (isSameField(myField, myField_1)) { return; } // lấy myField ra trước myField = rF.read_File_Infor(cmbTables.SelectedValue.ToString(), cmbDatabase.SelectedValue.ToString()); //Xóa file cũ. //backup file mới. List <String[]> my_Table_Contents = rF.read_Table_Contents(cmbTables.SelectedValue.ToString(), cmbDatabase.SelectedValue.ToString(), myField_1); List <String> myContents = new List <String>(); foreach (String[] str in my_Table_Contents) { String temp = ""; for (int i = 0; i < str.Length; i++) { if (!isInDelete(i, delete_index)) { temp += '\'' + str[i]; } } myContents.Add(temp); } if (isAlter == 1) { try { rF.delete_file("database/" + cmbDatabase.SelectedValue.ToString() + "/" + cmbTables.SelectedValue.ToString() + ".txt"); } catch { } } wF.write_Table_Contents(myContents, txtTableName.Text.ToString(), cmbDatabase.SelectedValue.ToString()); } if (isAlter == 1) { MessageBox.Show("Đã update table thành công"); } resetTable(); isAlter = 0; }