public string exportToExcel() { // Step 1. Read data from database if (isStoreNameEmpty()) { return("Store Name is empty"); } if (isReportNameEmpty()) { return("Excel Name id is empty"); } if (isfilePathTemplateFileEmpty()) { return("Template File Doesn't exists"); } if (hasParameterStore) { try { ConnectData cdata = new ConnectData(); // get connectString from Sacombank cdata.ConnectString = System.Configuration.ConfigurationManager.ConnectionStrings["gMVVMConnectionString"].ConnectionString; foreach (KeyValuePair <string, string> pair in this.storeParameterValue) { cdata.Paramerters.Add(pair.Key); cdata.ParamertersValue.Add(pair.Value); cdata.ParametersType.Add(SqlDbType.VarChar); } // get data from database to datatable if (!cdata.Read_Store(StoreName, true)) { return("Gọi Store thất bại"); } //Bat dat export //Khoi tao voi duong dan excel truyen vao ExcelTemplateExportBase excel = new ExcelTemplateExportBase() { TemplatePath = this.FilePath }; //gan du lieu doc tu store do vo excel excel.SmartmarkersObjData = new Dictionary <string, object>(); excel.SmartmarkersObjData.Add("obj", cdata.DataSource.DefaultView); //cac doi so truyen vao foreach (KeyValuePair <string, string> pair in this.ParameterReport) { excel.SmartmarkersObjData.Add(pair.Key, pair.Value); } this.packageStream = excel.ExprortSmartmarkers(); return(null); } catch (Exception ex) { if (ex.Message == "Passed invalid TemplatePath to Excel Template") { return("Chưa có mẫu báo cáo dạng excel."); } return(ex.Message); } } return(null); }
public string exportToExcel() { // Step 1. Read data from database if (isStoreNameEmpty()) return "Store Name is empty"; if (isReportNameEmpty()) return "Excel Name id is empty"; if (isfilePathTemplateFileEmpty()) return "Template File Doesn't exists"; if (hasParameterStore) { try { ConnectData cdata = new ConnectData(); // get connectString from Sacombank cdata.ConnectString = System.Configuration.ConfigurationManager.ConnectionStrings["gMVVMConnectionString"].ConnectionString; foreach (KeyValuePair<string, string> pair in this.storeParameterValue) { cdata.Paramerters.Add(pair.Key); cdata.ParamertersValue.Add(pair.Value); cdata.ParametersType.Add(SqlDbType.VarChar); } // get data from database to datatable if (!cdata.Read_Store(StoreName, true)) return "Gọi Store thất bại"; //Bat dat export //Khoi tao voi duong dan excel truyen vao ExcelTemplateExportBase excel = new ExcelTemplateExportBase() { TemplatePath = this.FilePath }; //gan du lieu doc tu store do vo excel excel.SmartmarkersObjData = new Dictionary<string, object>(); excel.SmartmarkersObjData.Add("obj", cdata.DataSource.DefaultView); //cac doi so truyen vao foreach (KeyValuePair<string, string> pair in this.ParameterReport) { excel.SmartmarkersObjData.Add(pair.Key, pair.Value); } this.packageStream = excel.ExprortSmartmarkers(); return null; } catch (Exception ex) { if (ex.Message == "Passed invalid TemplatePath to Excel Template") return "Chưa có mẫu báo cáo dạng excel."; return ex.Message; } } return null; }