private void buttonX2_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbbThang.Text == "" || dtipNam.Text == "" || dtipNgayLap.Text == "")
                {
                    MessageBox.Show("Chưa nhập đủ thông tin . nhập lại !", "LỖI ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                DataTable _dtdanhsach = _objlopbus.BaoCaoTongHocPhi(cbbThang.Text, dtipNam.Text);
                if (_dtdanhsach.Rows.Count > 0)
                {
                    string     ngaythang = "Tháng " + cbbThang.Text + " năm " + dtipNam.Text;
                    string     ngaylap   = dtipNgayLap.Value.ToLongDateString();
                    DataColumn colstt    = new DataColumn("STT", typeof(int));
                    _dtdanhsach.Columns.Add(colstt);
                    colstt.SetOrdinal(0);
                    DataColumn colsoluong = new DataColumn("SoLuong", typeof(int));
                    _dtdanhsach.Columns.Add(colsoluong);
                    colsoluong.SetOrdinal(8);
                    DataColumn coltongtien = new DataColumn("TongTien", typeof(int));
                    _dtdanhsach.Columns.Add(coltongtien);
                    coltongtien.SetOrdinal(9);

                    int len = _dtdanhsach.Rows.Count;
                    for (int i = 0; i < len; ++i)
                    {
                        _dtdanhsach.Rows[i]["STT"]      = i + 1;
                        _dtdanhsach.Rows[i]["SoLuong"]  = _objlopbus.GetSoLuongHocVien(_dtdanhsach.Rows[i]["MaLop"].ToString());
                        _dtdanhsach.Rows[i]["TongTien"] = _objlopbus.TongTien_LopHoc(_dtdanhsach.Rows[i]["MaLop"].ToString());
                    }
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("ThangNam", ngaythang);
                    dic.Add("NgayLap", ngaylap);
                    WordUltil wd = new WordUltil(Application.StartupPath + "/BaoCaoHocPhi.dotx", true);
                    wd.WriteFields(dic);
                    wd.WriteTable(_dtdanhsach, 1);
                }
                else
                {
                    MessageBox.Show("Không có dữ liệu để xuất file .", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("In thất bại! \nThực hiện lại ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void buttonX2_Click(object sender, EventArgs e)
 {
     try
     {
         if (cbbThang.Text == "" || dtipNam.Text == "" || dtipNgayLap.Text == "")
         {
             MessageBox.Show("Chưa nhập đủ thông tin . nhập lại !", "LỖI ", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         DataTable _dtdanhsach = _objhocvienbus.GetAll_HocVienBaoCao(cbbThang.Text, dtipNam.Text);
         if (_dtdanhsach.Rows.Count > 0)
         {
             string     ngaythang = "Tháng " + cbbThang.Text + " năm " + dtipNam.Text;
             DataColumn col       = new DataColumn("STT", typeof(int));
             _dtdanhsach.Columns.Add(col);
             col.SetOrdinal(0);
             int len = _dtdanhsach.Rows.Count;
             for (int i = 0; i < len; ++i)
             {
                 _dtdanhsach.Rows[i]["STT"] = i + 1;
             }
             Dictionary <string, string> dic = new Dictionary <string, string>();
             dic.Add("ThangNam", ngaythang);
             WordUltil wd = new WordUltil(Application.StartupPath + "/Baocaodanhsach.dotx", true);
             wd.WriteFields(dic);
             wd.WriteTable(_dtdanhsach, 1);
         }
         else
         {
             MessageBox.Show("Không có dữ liệu để xuất file .", "Thông báo ", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("In thất bại! \nThực hiện lại ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        // POST: api/CreateFile_Word
        public string Post(exportWord value)
        {
            try
            {
                Dictionary <string, string> dicAppSet;
                general gn = new general();
                dicAppSet = gn.ReadAppseting();
                if (dicAppSet == null || dicAppSet.Count == 0)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Đọc appsetting lỗi\"}]}");
                }


                var dicPara   = gn.ParaConvertDicPara(value.para);
                var dicConfig = gn.ConfigConvertToDicConfig(value.config);
                if (dicPara == null && dicConfig == null)
                {
                    return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"Kiểm tra lại định dạng json đầu vào\"}]}");
                }


                var       filemau = dicAppSet["hddt_path_filetemplate"] + dicConfig["filemau"];
                WordUltil word    = new WordUltil(filemau, false);
                word.WriteFields(dicPara);

                var pathcreat = dicAppSet["path_saveonserver"];

                var filecreat = pathcreat + dicConfig["filecreat"];

                //try
                //{
                //    if (value.dt1 != null)
                //    {
                //        var dt1 = JObject.Parse(value.dt1);
                //        if (dt1 != null)
                //            foreach (var val in dt1)
                //            {
                //                var dt = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);
                //                if (dt != null && dt.Rows.Count > 0)
                //                    word.WriteTable(dt, Convert.ToInt32(dicConfig["dt1index"]));
                //            }
                //    }
                //}
                //catch { }


                //try
                //{
                //    if (value.dt2 != null)
                //    {
                //        var dt1 = JObject.Parse(value.dt2);
                //        if (dt1 != null)
                //            foreach (var val in dt1)
                //            {
                //                var dt = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);
                //                if (dt != null && dt.Rows.Count > 0)
                //                    word.WriteTable(dt, Convert.ToInt32(dicConfig["dt2index"]));
                //            }
                //    }
                //}
                //catch { }

                //try
                //{
                //    if (value.dt3 != null)
                //    {
                //        var dt1 = JObject.Parse(value.dt3);
                //        if (dt1 != null)
                //            foreach (var val in dt1)
                //            {
                //                var dt = gn.ConvertJsonToDataTable(val.Value.ToString(), val.Key);
                //                if (dt != null && dt.Rows.Count > 0)
                //                    word.WriteTable(dt, Convert.ToInt32(dicConfig["dt3index"]));
                //            }
                //    }
                //}
                //catch { }
                word.SaveToFile(filecreat);
                return("{\"result\":\"ok\",\"data\":\"" + filecreat + "\"}");
            }
            catch (Exception ex) { return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}"); }
        }