Beispiel #1
0
        private void BindGrid()
        {
            ConfigModel configModel = ConfigOperater.GetConfigModel();

            SqlConnectionString.Text = configModel.SqlConnectionString;
            TableName.Text           = configModel.TableName;
            UploadPath.Text          = configModel.UploadPath;
            StartRow.Text            = configModel.StartRow.ToString();
        }
Beispiel #2
0
        protected void UploadExcel(object sender, EventArgs e)
        {
            if (ExcelFile.HasFile)
            {
                string   fileName = ExcelFile.FileName;
                FileInfo fileInfo = new FileInfo(fileName);

                if (fileInfo.Extension == ".xls" || fileInfo.Extension == ".xlsx")
                {
                    fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileName;

                    ConfigModel modelConfig = ConfigOperater.GetConfigModel();

                    string filePath = Server.MapPath("/" + modelConfig.UploadPath + "/" + fileName);

                    ExcelFile.SaveAs(filePath);

                    try
                    {
                        DataTable dt = ExcelHelper.GetExcelToDataTable(url: filePath, startRow: (modelConfig.StartRow > 0?modelConfig.StartRow - 1:0));

                        string errorStr = "";

                        string result = SetExcelToSQL.RenderDataTableToSQLResult(dt, modelConfig, ref errorStr);

                        if (errorStr != "")
                        {
                            RegisterScript("alert('导入错误!" + errorStr.Replace("\n", "").Replace("\r", "").Replace("'", "\"") + "')");
                        }
                        else
                        {
                            Context.Items.Add("ResultSQL", result);
                            Context.Items.Add("SQLConnection", modelConfig.SqlConnectionString);

                            Server.Transfer("/Excel/Result.aspx");
                        }
                    }
                    catch (Exception ex)
                    {
                        RegisterScript("alert('导入错误!" + ex.ToString().Replace("\n", "").Replace("\r", "").Replace("'", "\"") + "')");
                    }
                    finally
                    {
                        File.Delete(filePath);
                    }
                }
                else
                {
                    RegisterScript("alert('错误的文件!')");
                }
            }
            else
            {
                RegisterScript("alert('请选择文件!')");
            }
        }
Beispiel #3
0
        private void BindGrid()
        {
            ConfigModel configModel = ConfigOperater.GetConfigModel();

            SqlConnectionString.Text = configModel.SqlConnectionString;
            TableName.Text           = configModel.TableName;
            UploadPath.Text          = configModel.UploadPath;
            StartRow.Text            = configModel.StartRow.ToString();

            RepeaterItem.DataSource = configModel.ListField;
            RepeaterItem.DataBind();
        }
Beispiel #4
0
        protected void UploadExcel(object sender, EventArgs e)
        {
            if (ExcelFile.HasFile)
            {
                string   fileName = ExcelFile.FileName;
                FileInfo fileInfo = new FileInfo(fileName);

                if (fileInfo.Extension == ".xls" || fileInfo.Extension == ".xlsx")
                {
                    fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileName;

                    ConfigModel modelConfig = ConfigOperater.GetConfigModel();

                    string filePath = Server.MapPath("/" + modelConfig.UploadPath + "/" + fileName);

                    ExcelFile.SaveAs(filePath);

                    try
                    {
                        DataTable dt = ExcelHelper.GetExcelToDataTable(url: filePath, startRow: (modelConfig.StartRow > 0 ? modelConfig.StartRow - 1 : 0));

                        Session["DataTable"] = dt;

                        //Context.Items.Add("SQLConnection", modelConfig.SqlConnectionString);

                        Response.Redirect("/Excel/StepOne.aspx");
                    }
                    catch (Exception ex)
                    {
                        RegisterScript("alert('导入错误!" + ex.ToString().Replace("\n", "").Replace("\r", "").Replace("'", "\"") + "')");
                    }
                    finally
                    {
                        File.Delete(filePath);
                    }
                }
                else
                {
                    RegisterScript("alert('错误的文件!')");
                }
            }
            else
            {
                RegisterScript("alert('请选择文件!')");
            }
        }
Beispiel #5
0
        protected void SaveForm(object sender, EventArgs e)
        {
            try
            {
                ConfigModel configModel = ConfigOperater.GetConfigModel();
                configModel.SqlConnectionString = SqlConnectionString.Text;
                configModel.TableName           = TableName.Text;
                configModel.UploadPath          = UploadPath.Text;
                configModel.StartRow            = Convert.ToInt32(StartRow.Text);

                ConfigOperater.UpdateConfigModel(configModel);
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigModel model = ConfigOperater.GetConfigModel();

            if (SqlField != "")
            {
                FieldModel modelField = model.ListField.Find(u => u.SQLField == SqlField);
                if (modelField != null)
                {
                    model.ListField.Remove(modelField);

                    ConfigOperater.UpdateConfigModel(model);
                }
            }

            Response.Redirect("/excel/excelimport.aspx");
        }
Beispiel #7
0
        private void BindData()
        {
            if (SqlField != "")
            {
                ConfigModel confModel  = ConfigOperater.GetConfigModel();
                FieldModel  modelField = confModel.ListField.Find(u => u.SQLField == SqlField);
                if (modelField != null)
                {
                    FieldName.Text               = modelField.FieldName;
                    ExcelColomn.Text             = modelField.ExcelColomn.ToString();
                    ExcelFieldType.SelectedValue = ((int)modelField.ExcelFieldType).ToString();

                    SQLField.Text = modelField.SQLField.ToString();
                    SQLFieldType.SelectedValue = ((int)modelField.SQLFieldType).ToString();
                    IsForeignKey.SelectedValue = (modelField.IsForeignKey == false?0:1).ToString();
                    ForeignTable.Text          = modelField.ForeignTable;
                    ForeignKey.Text            = modelField.ForeignKey.ToString();
                    LinkField.Text             = modelField.LinkField.ToString();
                }
            }
        }