Ejemplo n.º 1
0
    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();
        }
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
 public static void insertQuestion(Cau_Hoi ch)
 {
     DAO_Cau_Hoi.AddNewQuestion(ch);
 }
Ejemplo n.º 4
0
 public static void deleteQuestionByID(string mach)
 {
     DAO_Cau_Hoi.deleteQuestion(mach);
 }
Ejemplo n.º 5
0
 //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());
 }