public Message saveToFile(string pathToSave, List <UserStruct> data) { this.createWordApplication(); Message msg = new Message(); if (WordApp != null && doc != null) { UserStruct last = data[data.Count - 1]; foreach (UserStruct user in data) { newTable.Cell(newTable.Rows.Count, 1).Range.Text = user.name; newTable.Cell(newTable.Rows.Count, 2).Range.Text = user.bal.ToString(); newTable.Cell(newTable.Rows.Count, 3).Range.Text = user.numberSchool.ToString(); if (last != user) { newTable.Rows.Add(); } } doc.SaveAs(@pathToSave, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); msg.userMessage = "Файл збережено!"; msg.code = true; this.closeWordApp(); return(msg); } else { msg.userMessage = "Неможливо записати у документ.\nПрограму буде завершено!"; msg.logMessage = "Cannot write to word file"; msg.code = false; return(msg); } }
public List <UserStruct> readDataFromTable() { DataSet ds = this.ReadTables(); foreach (DataRow myRow in ds.Tables[0].Rows) { UserStruct user = new UserStruct(); int columnNumber = 1; foreach (DataColumn myCol in ds.Tables[0].Columns) { if (myRow[myCol] != System.DBNull.Value) { if (columnNumber == 1) { user.name = myRow[myCol].ToString(); } if (columnNumber == 2) { user.bal = Convert.ToInt32(myRow[myCol]); } if (columnNumber == 3) { user.numberSchool = Convert.ToInt32(myRow[myCol]); } } columnNumber++; } this.userData.Add(user); } return(this.userData); }