public static void ImportQuestion(string Path, DataGridView gridView) { Microsoft.Office.Interop.Excel.Application xlApp; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; Microsoft.Office.Interop.Excel.Range xlRange; if (Path != string.Empty) { xlApp = new Microsoft.Office.Interop.Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Path); xlWorkSheet = xlWorkBook.Worksheets["Sheet1"]; xlRange = xlWorkSheet.UsedRange; gridView.ColumnCount = xlRange.Columns.Count; int n = 0; for (int i = 1; i < gridView.ColumnCount; i++) { gridView.Columns[n].Name = xlRange.Cells[1, i].Text; n++; } for (int i = 2; i <= xlRange.Rows.Count; i++) { gridView.Rows.Add(xlRange.Cells[i, 1].Text, xlRange.Cells[i, 2].Text, xlRange.Cells[i, 3].Text, xlRange.Cells[i, 4].Text, xlRange.Cells[i, 5].Text, xlRange.Cells[i, 6].Text, xlRange.Cells[i, 7].Text, xlRange.Cells[i, 8].Text, xlRange.Cells[i, 9].Text, xlRange.Cells[i, 10].Text, xlRange.Cells[i, 11].Text, xlRange.Cells[i, 12].Text); DAO_Cau_Hoi.InsertQuestionWithExcel(xlRange, i); } xlWorkBook.Close(); xlApp.Quit(); } }
static public string tuDongTangKhoaCauHoi() { int ma = 1; if (DAO_Cau_Hoi.getAllListQuestion().Count > 0) { string Temp = DAO_Cau_Hoi.getAllListQuestion().Last().ma_CH.Substring(2); ma = int.Parse(Temp) + 1; } string maCH = "CH" + ma.ToString("D6") + " "; return(maCH); }
public static void insertQuestion(Cau_Hoi ch) { DAO_Cau_Hoi.AddNewQuestion(ch); }
public static void deleteQuestionByID(string mach) { DAO_Cau_Hoi.deleteQuestion(mach); }
//public static Table<Cau_Hoi> getQuestion() // { // QLTTNDataContext db = new QLTTNDataContext(); // return db.GetTable<Cau_Hoi>(); // } public static List <Cau_Hoi> getListQuestion() { return(DAO_Cau_Hoi.getListQuestion().ToList()); }