Beispiel #1
0
        public static string SqlScriptString(IExportable iExportable)
        {
            //INSERT INTO table_name (column1,column2,column3,...)
            //VALUES (value1,value2,value3,...);
            StringBuilder sb     = new StringBuilder();
            string        colums = "";

            colums = Generate(iExportable.GetAllFields());
            foreach (var item in iExportable.GetAllItems())
            {
                var values = Generate(item);
                sb.AppendLine(string.Format("INSERT INTO \"{0}\" ({1}) VALUES({2});", iExportable.TableName, colums, values));
            }
            return(sb.ToString());
        }
Beispiel #2
0
        public static IEnumerable <string> SqlScript(IExportable iExportable)
        {
            //INSERT INTO table_name (column1,column2,column3,...)
            //VALUES (value1,value2,value3,...);
            List <string> result = new List <string>();
            string        colums = "";

            colums = Generate(iExportable.GetAllFields());
            foreach (var item in iExportable.GetAllItems())
            {
                var values = Generate(item);
                result.Add(string.Format("INSERT INTO \"{0}\" ({1}) VALUES({2});", iExportable.TableName, colums, values));
            }
            return(result);
        }
Beispiel #3
0
        public static bool GenerateExportCSV(IExportable iExportable)
        {
            //INSERT INTO table_name (column1,column2,column3,...)
            //VALUES (value1,value2,value3,...);
            bool          result = true;
            StringBuilder sb     = new StringBuilder();

            try
            {
                sb.AppendLine(Generate(iExportable.GetAllFields(), false));
                foreach (var item in iExportable.GetAllItems())
                {
                    var values = Generate(item, false);
                    sb.AppendLine(values);
                }
                SaveFile(sb.ToString(), iExportable.FileName);
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }