/// <summary>
        /// 设置最后连接字符串
        /// </summary>
        /// <param name="sqlType">数据库类型 0=mssql 1=mysql</param>
        /// <param name="Host">数据库地址</param>
        /// <param name="isPort">是否需要端口</param>
        /// <param name="Port">端口号</param>
        /// <param name="Database">数据库名</param>
        /// <param name="Username">用户名</param>
        /// <param name="Password">密码</param>
        /// <returns>true/false</returns>
        public static bool setLastConnectionStrings(int sqlType, string Host, bool isPort, string Port, string Database, string Username, string Password)
        {
            string value = sqlType + ";" + Host + ";" + isPort + ";" + Port + ";" + Database + ";" + Username + ";" + Password;

            if (sqlType == 0 || sqlType == 1)//0=mssql,1=mysql
            {
                if (sqlType == 0)
                {
                    RWConfig.SetappSettingsValue("LastConnectionStringsForMSSQL", value, ConfigPath);
                    return(true);
                }
                if (sqlType == 1)
                {
                    RWConfig.SetappSettingsValue("LastConnectionStringsForMySQL", value, ConfigPath);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
 /// <summary>
 /// 根据常用SQL编码删除常用SQL
 /// </summary>
 /// <param name="CommonlyUsedSQLCode">常用SQL编码</param>
 /// <returns>string:删除成功/删除失败/没有匹配项/报错信息</returns>
 public static string delCommonlyUsedSQLCodeNameValue(string CommonlyUsedSQLCode)
 {
     try
     {
         string[] str = getCommonlyUsedSQLAllCodes();
         foreach (var item in str)
         {
             if (item == CommonlyUsedSQLCode)
             {
                 if (RWConfig.DelappSettingsValue(CommonlyUsedSQLCode, ConfigPath) == true)
                 {
                     List <string> list = str.ToList();
                     list.Remove(item);
                     str = list.ToArray();
                     string result = String.Join(";", str);
                     RWConfig.SetappSettingsValue("CommonlyUsedSQL", result, ConfigPath);
                     return(CommonlyUsedSQLCode + " 删除成功!");
                 }
                 else
                 {
                     return(CommonlyUsedSQLCode + " 删除失败!");
                 }
             }
         }
         return("没有匹配项!");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 /// <summary>
 /// 如果配置文件中无常用SQL配置,则新建配置,值默认
 /// </summary>
 public static void setDefaultCommonlyUsedSQLIfIsNullOrEmptyByappSettings()
 {
     if (string.IsNullOrEmpty(CommonlyUsedSQL))
     {
         RWConfig.SetappSettingsValue("CommonlyUsedSQL", "CommonlyUsedSQL_Default", ConfigPath);
     }
     if (string.IsNullOrEmpty(CommonlyUsedSQL_Default))
     {
         RWConfig.SetappSettingsValue("CommonlyUsedSQL_Default", "常用SQL名;select * from xxx", ConfigPath);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 新增appSettings配置
 /// </summary>
 /// <param name="Key">appSettings键</param>
 /// <param name="Value">appSettings值</param>
 /// <returns>true, false</returns>
 public static bool addappSettings(string key, string value)
 {
     try
     {
         RWConfig.SetappSettingsValue(key, value, CONFIGPATH);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 /// <summary>
 /// 设置最后连接数据库类型
 /// </summary>
 /// <param name="sqlType">数据库类型,MSSQL/MySQL</param>
 /// <returns>true/false</returns>
 public static bool setLastConnectionType(string sqlType)
 {
     if (sqlType == "MSSQL" || sqlType == "MySQL")
     {
         RWConfig.SetappSettingsValue("LastConnectionType", sqlType, ConfigPath);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// 根据数据库类型保存数据库连接记录
        /// </summary>
        /// <param name="sqlType">数据库类型 MSSQL MySQL</param>
        /// <param name="Host">数据库地址</param>
        /// <param name="isPort">是否需要端口</param>
        /// <param name="Port">端口号</param>
        /// <param name="Database">数据库名</param>
        /// <param name="Username">用户名</param>
        /// <param name="Password">密码</param>
        /// <returns>返回true/false</returns>
        public static bool saveConnectionStringBySQLType(string sqlType, string Host, bool isPort, string Port, string Database, string Username, string Password)
        {
            try
            {
                int n = getSameValueLenth(sqlType + "_Host", Host); //Host计数
                if (n == 0)                                         //说明没有该记录
                {
                    string[]      array = getConfigValueByKey(sqlType + "_Host");
                    List <string> List  = array.ToList();
                    List.Add(Host);
                    array = List.ToArray();
                    string value;
                    if (array[0] == "")
                    {
                        value = array[array.Length - 1];
                    }
                    else
                    {
                        value = String.Join(";", array);
                    }
                    RWConfig.SetappSettingsValue(sqlType + "_Host", value, ConfigPath);
                }

                n = getSameValueLenth(sqlType + "_DB_" + Host, Database); //DB计数
                if (n == 0)                                               //说明没有该记录
                {
                    string[]      array = getConfigValueByKey(sqlType + "_DB_" + Host);
                    List <string> List  = array.ToList();
                    List.Add(Database);
                    array = List.ToArray();
                    string value;
                    if (array[0] == "")
                    {
                        value = array[array.Length - 1];
                    }
                    else
                    {
                        value = String.Join(";", array);
                    }
                    RWConfig.SetappSettingsValue(sqlType + "_DB_" + Host, value, ConfigPath);
                }

                RWConfig.SetappSettingsValue(sqlType + "_Host_" + Host, isPort + ";" + Port + ";" + Username + ";" + Password, ConfigPath);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 7
0
 private void setDefaultAppSettingsIfIsNullOrEmpty()
 {
     if (string.IsNullOrEmpty(appsetting1))
     {
         RWConfig.SetappSettingsValue("1", "1", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting2))
     {
         RWConfig.SetappSettingsValue("2", "2", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting4))
     {
         RWConfig.SetappSettingsValue("4", "4", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting8))
     {
         RWConfig.SetappSettingsValue("8", "8", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting16))
     {
         RWConfig.SetappSettingsValue("16", "16", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting32))
     {
         RWConfig.SetappSettingsValue("32", "32", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting64))
     {
         RWConfig.SetappSettingsValue("64", "64", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting128))
     {
         RWConfig.SetappSettingsValue("128", "128", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting256))
     {
         RWConfig.SetappSettingsValue("256", "256", "./ANDOperationForBase.exe");
     }
     if (string.IsNullOrEmpty(appsetting512))
     {
         RWConfig.SetappSettingsValue("512", "512", "./ANDOperationForBase.exe");
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 修改appSettings配置
 /// </summary>
 /// <param name="Key">appSettings键</param>
 /// <param name="Value">appSettings值</param>
 /// <returns>true, false</returns>
 public static bool editappSettings(string key, string value)
 {
     try
     {
         if (!string.IsNullOrEmpty(RWConfig.GetappSettingsValue(key, CONFIGPATH)))
         {
             RWConfig.SetappSettingsValue(key, value, CONFIGPATH);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 /// <summary>
 /// 修改常用SQL配置
 /// </summary>
 /// <param name="Code">常用SQL编码</param>
 /// <param name="Name">常用SQL名称</param>
 /// <param name="Value">常用SQL语句</param>
 /// <returns>string:修改成功/修改失败/报错信息</returns>
 public static string editCommonlyUsedSQLCodeNameValue(string Code, string Name, string Value)
 {
     try
     {
         if (string.IsNullOrEmpty(Code) || string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value))
         {
             return("常用SQL编码/名称/语句不能为空!");
         }
         else
         {
             RWConfig.SetappSettingsValue(Code, Name + ";" + Value, ConfigPath);
             return("修改成功");
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 /// <summary>
 /// 修改快捷插入配置
 /// </summary>
 /// <param name="Code">快捷插入配置编码</param>
 /// <param name="Name">快捷插入配置名称</param>
 /// <param name="Value">快捷插入配置值</param>
 /// <returns>string:修改成功/修改失败/报错信息</returns>
 public static string editQuickInsertModelCodeNameValue(string Code, string Name, string Value, string Instruction)
 {
     try
     {
         if (string.IsNullOrEmpty(Code) || string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Instruction))
         {
             return("快捷插入配置编码/名称/值/使用说明不能为空!");
         }
         else
         {
             RWConfig.SetappSettingsValue(Code, Name + ";" + Value + ";" + Instruction, ConfigPath);
             return("修改成功");
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 /// <summary>
 /// 如果配置文件中无右侧常用按钮的配置,则新建配置,值全为“暂无功能”
 /// </summary>
 public static void setDefaultBtnNameIfIsNullOrEmptyByappSettings()
 {
     if (string.IsNullOrEmpty(btnname1))
     {
         RWConfig.SetappSettingsValue("btnname1", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname2))
     {
         RWConfig.SetappSettingsValue("btnname2", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname3))
     {
         RWConfig.SetappSettingsValue("btnname3", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname4))
     {
         RWConfig.SetappSettingsValue("btnname4", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname5))
     {
         RWConfig.SetappSettingsValue("btnname5", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname6))
     {
         RWConfig.SetappSettingsValue("btnname6", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname7))
     {
         RWConfig.SetappSettingsValue("btnname7", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname8))
     {
         RWConfig.SetappSettingsValue("btnname8", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     if (string.IsNullOrEmpty(btnname9))
     {
         RWConfig.SetappSettingsValue("btnname9", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
 }
        /// <summary>
        /// 新增常用SQL配置
        /// </summary>
        /// <param name="Code">常用SQL编码</param>
        /// <param name="Name">常用SQL名称</param>
        /// <param name="Value">常用SQL语句</param>
        /// <returns>string:新增成功/新增失败/新增项已存在,新增失败/报错信息</returns>
        public static string setCommonlyUsedSQLCodeNameValue(string Code, string Name, string Value)
        {
            try
            {
                if (string.IsNullOrEmpty(Code) || string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value))
                {
                    return("常用SQL编码/名称/语句不能为空!");
                }
                else
                {
                    string[] str = getQuickInsertSettingsAllCodes();
                    foreach (var item in str)
                    {
                        if (item == Code)
                        {
                            return("在快捷插入配置编码中已存在相同编码,请确认!");
                        }
                    }

                    str = getCommonlyUsedSQLAllCodes();
                    foreach (var item in str)
                    {
                        if (item == Code)
                        {
                            return("在常用SQL配置编码中已存在相同编码,请确认!");
                        }
                    }

                    CommonlyUsedSQL = RWConfig.GetappSettingsValue("CommonlyUsedSQL", ConfigPath);
                    RWConfig.SetappSettingsValue(Code, Name + ";" + Value, ConfigPath);
                    RWConfig.SetappSettingsValue("CommonlyUsedSQL", CommonlyUsedSQL + ";" + Code, ConfigPath);
                    return("新增成功");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        /// <summary>
        /// 如果配置文件中无快捷插入配置,则新建配置,值默认
        /// </summary>
        public static void setDefaultQuickInsertSettingsIfIsNullOrEmptyByappSettings()
        {
            if (string.IsNullOrEmpty(QuickInsert))
            {
                RWConfig.SetappSettingsValue("QuickInsert", "QuickInsert_IDIncrement;QuickInsert_RandomNum;QuickInsert_NewID;QuickInsert_NewDateTime;QuickInsert_SameNewID;QuickInsert_RandomStr;QuickInsert_IDIncrementPlus", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_IDIncrement))
            {
                RWConfig.SetappSettingsValue("QuickInsert_IDIncrement", "指定id递增;{{id:x}};x替换为开始的序号,从x开始生成(包含x)", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_RandomNum))
            {
                RWConfig.SetappSettingsValue("QuickInsert_RandomNum", "指定范围随机数;{{[1-2]}};-左边开始&#xA;-右边结束&#xA;不带小数点生成的随机数也不带", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_NewID))
            {
                RWConfig.SetappSettingsValue("QuickInsert_NewID", "生成newid/uuid;{{newid}};有匹配项就替换为新uuid", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_NewDateTime))
            {
                RWConfig.SetappSettingsValue("QuickInsert_NewDateTime", "指定时间递增;{{timed+x:yyyy-MM-dd HH:mm:ss}};+左边为时间类型(d|h|m|s 对应 日|时|分|秒)&#xA;+右边为递增/递减值", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_SameNewID))
            {
                RWConfig.SetappSettingsValue("QuickInsert_SameNewID", "生成相同newid/uuid;{{samenewid}};一次执行多条sql,使用相同uuid", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_RandomStr))
            {
                RWConfig.SetappSettingsValue("QuickInsert_RandomStr", "在指定元素中随机选择一项;{{[x;y;z...]}};x、y、z为指定元素,\n能在元素中随机选择一项,\n请将;换成英文分号", ConfigPath);
            }
            if (string.IsNullOrEmpty(QuickInsert_IDIncrementPlus))
            {
                RWConfig.SetappSettingsValue("QuickInsert_IDIncrementPlus", "指定id按指定数递增;{{id+x:y}};从y开始按指定x+-*/,\n(+|-|*|/)x:y,\n{{id-7:77}},\n77、70、63...", ConfigPath);
            }

            //快捷插入中缺失默认配置会自动新增
            getQuickInsertSettingsByappSettings();
            string append = "";

            string[] arrayQuickInsert = QuickInsert.Split(';');
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_IDIncrement") == -1)
            {
                append += ";QuickInsert_IDIncrement";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_RandomNum") == -1)
            {
                append += ";QuickInsert_RandomNum";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_NewID") == -1)
            {
                append += ";QuickInsert_NewID";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_NewDateTime") == -1)
            {
                append += ";QuickInsert_NewDateTime";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_SameNewID") == -1)
            {
                append += ";QuickInsert_SameNewID";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_RandomStr") == -1)
            {
                append += ";QuickInsert_RandomStr";
            }
            if (Array.IndexOf(arrayQuickInsert, "QuickInsert_IDIncrementPlus") == -1)
            {
                append += ";QuickInsert_IDIncrementPlus";
            }
            //不为空才更新,否则每次运行都会更新
            if (!string.IsNullOrEmpty(append))
            {
                RWConfig.SetappSettingsValue("QuickInsert", QuickInsert + append, ConfigPath);
            }
        }
Esempio n. 14
0
 /// <summary>
 /// 保存常用功能按钮配置
 /// </summary>
 public void setCommonFunctionsButtonName()
 {
     if (cmbboxCommonFunctionsButton1.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname1", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname1", cmbboxCommonFunctionsButton1.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton2.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname2", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname2", cmbboxCommonFunctionsButton2.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton3.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname3", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname3", cmbboxCommonFunctionsButton3.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton4.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname4", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname4", cmbboxCommonFunctionsButton4.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton5.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname5", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname5", cmbboxCommonFunctionsButton5.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton6.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname6", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname6", cmbboxCommonFunctionsButton6.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton7.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname7", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname7", cmbboxCommonFunctionsButton7.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton8.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname8", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname8", cmbboxCommonFunctionsButton8.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
     if (cmbboxCommonFunctionsButton9.SelectedIndex == -1)
     {
         RWConfig.SetappSettingsValue("btnname9", "暂无功能", "./ToolsCollectionForProgram.exe");
     }
     else
     {
         RWConfig.SetappSettingsValue("btnname9", cmbboxCommonFunctionsButton9.SelectedItem.ToString(), "./ToolsCollectionForProgram.exe");
     }
 }