Esempio n. 1
0
        /// <summary>
        /// 分割字符串  空字符串不返回,返回的字符串两端空格被去掉
        /// </summary>
        /// <param name="aList"></param>
        /// <param name="aSplitStr"></param>
        /// <returns></returns>
        public static List <string> SplitStringToList(string aStr, string aSplitStr)
        {
            //此函数只是按第一个字符进行分割
            //return aStr.Split(aSplitStr.ToCharArray());

            List <string> result = new List <string>();

            aStr = aStr.Trim();

            int index = aStr.IndexOf(aSplitStr);

            while (index >= 0)
            {
                string tmp = I3StringUtil.SubString(aStr, 0, index).Trim();
                if (!string.IsNullOrEmpty(tmp))
                {
                    result.Add(tmp);
                }
                aStr  = I3StringUtil.SubString(aStr, index + aSplitStr.Length, aStr.Length - index - aSplitStr.Length).Trim();
                index = aStr.IndexOf(aSplitStr);
            }
            if (!aStr.Equals(string.Empty))
            {
                result.Add(aStr);
            }


            return(result);
        }
        /// <summary>
        /// 注册文件类型
        ///
        /// 错误处理:无
        ///
        /// </summary>
        public static void RegisterFileType(I3FileTypeRegInfo regInfo)
        {
            if (FileTypeRegistered(regInfo.ExtendName))
            {
                return;
            }

            //xcf_FileType
            string relationName = I3StringUtil.SubString(regInfo.ExtendName, 1, regInfo.ExtendName.Length - 1).ToUpper() + "_FileType";

            //指定.xcf文件的关联信息在 xcf_FileType中
            RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey(regInfo.ExtendName); //创建项.xcf

            fileTypeKey.SetValue("", relationName);                                          //在.xcf 中增加一个默认值为  xcf_FileType
            fileTypeKey.Close();

            RegistryKey relationKey = Registry.ClassesRoot.CreateSubKey(relationName); //创建项xcf_FileType

            relationKey.SetValue("", regInfo.Description);                             //写入默认值 文件类型说明

            RegistryKey iconKey = relationKey.CreateSubKey("DefaultIcon");             //添加项,图标路径

            iconKey.SetValue("", regInfo.IcoPath);

            RegistryKey shellKey   = relationKey.CreateSubKey("Shell");
            RegistryKey openKey    = shellKey.CreateSubKey("Open");
            RegistryKey commandKey = openKey.CreateSubKey("Command");

            commandKey.SetValue("", regInfo.ExePath + " \"%1\"");   //让应用程序知道打开了哪个文件

            relationKey.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 返回首字母为大写的字符串
        /// </summary>
        /// <param name="aStr"></param>
        /// <returns></returns>
        public static string ConvertFirstToUpper(string aStr)
        {
            string str1 = I3StringUtil.SubString(aStr, 0, 1);
            string str2 = I3StringUtil.SubString(aStr, 1, aStr.Length - 1);

            return(str1.ToUpper() + str2);
        }
        /// <summary>
        /// 获取指定文件类型关联信息
        /// 类似于 .xlsm ,大小写都可以
        /// 错误处理:无
        /// 注意:返回的ExePath是两头带"的,用File.Exists来判断时会找不到
        /// </summary>
        public static I3FileTypeRegInfo GetFileTypeRegInfo(string extendName)
        {
            if (!FileTypeRegistered(extendName))
            {
                return(null);
            }

            I3FileTypeRegInfo regInfo      = new I3FileTypeRegInfo(extendName);
            RegistryKey       extendKey    = Registry.ClassesRoot.OpenSubKey(extendName);
            string            relationName = extendKey.GetValue("").ToString();

            RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey(relationName);

            regInfo.Description = relationKey.GetValue("").ToString();

            RegistryKey iconKey = relationKey.OpenSubKey("DefaultIcon");

            regInfo.IcoPath = iconKey.GetValue("").ToString();

            RegistryKey shellKey   = relationKey.OpenSubKey("Shell");
            RegistryKey openKey    = shellKey.OpenSubKey("Open");
            RegistryKey commandKey = openKey.OpenSubKey("Command");
            string      temp       = commandKey.GetValue("").ToString();

            regInfo.ExePath = I3StringUtil.SubString(temp, 0, temp.Length - 3);

            return(regInfo);
        }
Esempio n. 5
0
        /// <summary>
        /// 检查服务器名是否本机
        /// </summary>
        /// <returns></returns>
        public static bool CheckServerNameIsLocal(string aServerName)
        {
            aServerName = I3StringUtil.SplitStringToList(aServerName.ToUpper(), "\\")[0];

            if (string.IsNullOrEmpty(aServerName))
            {
                return(true);
            }
            if (string.Equals(aServerName, "."))
            {
                return(true);
            }
            if (string.Equals(aServerName, "127.0.0.1"))
            {
                return(true);
            }
            if (string.Equals(aServerName, "(LOCAL)"))
            {
                return(true);
            }
            if (string.Equals(aServerName, GetMachineName().ToUpper()))
            {
                return(true);
            }
            foreach (string s in GetLocalIP())
            {
                if (string.Equals(aServerName, s.ToUpper()))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取十二生肖
        /// </summary>
        /// <param name="aDateTime"></param>
        /// <returns></returns>
        public static string Get12Lunar(DateTime aDateTime)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander = new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
            int    intYear  = chinseCaleander.GetSexagenaryYear(aDateTime);

            return(I3StringUtil.SubString(TreeYear, chinseCaleander.GetTerrestrialBranch(intYear) - 1, 1));
        }
Esempio n. 7
0
        /// <summary>
        /// 检查目录名的最后是个字符是不是 \ ,不是则加上
        /// </summary>
        /// <param name="aDirtoryName"></param>
        /// <returns></returns>
        public static string CheckDirctoryLastChar(string aDirtoryName)
        {
            string aNewDirtory = aDirtoryName;

            if (!I3StringUtil.SubString(aNewDirtory, aNewDirtory.Length - 1).Equals(@"\"))
            {
                aNewDirtory = aNewDirtory + @"\";
            }

            return(aNewDirtory);
        }
Esempio n. 8
0
        /// <summary>
        /// 由区位码得到汉字
        /// </summary>
        /// <param name="aNum"></param>
        /// <returns></returns>
        public static string ConvertNumToChinese(string aNum)
        {
            byte[] array = new byte[2];
            string str1  = I3StringUtil.SubString(aNum, 0, 2);
            string str2  = I3StringUtil.SubString(aNum, 2, 2);
            int    front = Convert.ToInt32(str1) + 160;
            int    back  = Convert.ToInt32(str2) + 160;

            array[0] = (byte)front;
            array[1] = (byte)back;
            return(Encoding.GetEncoding("GBK").GetString(array));
        }
Esempio n. 9
0
        /// <summary>
        /// 获取子字符串个数
        /// 注意,像 ab我我我我我cc 这样的字符串,获取 我我 的个数时,返回2而不是4
        /// </summary>
        /// <param name="aStr"></param>
        /// <param name="aSub"></param>
        /// <returns></returns>
        public static int GetSubCountInString(string aStr, string aSub)
        {
            int result = 0;

            int index = aStr.IndexOf(aSub);

            while (index >= 0)
            {
                result++;
                aStr  = I3StringUtil.SubString(aStr, index + aSub.Length, aStr.Length - index - aSub.Length);
                index = aStr.IndexOf(aSub);
            }

            return(result);
        }
Esempio n. 10
0
        /// <summary>
        /// 根据控件的Tag设置,自动为控件设置数据绑定
        ///
        /// 注意:Tag的值必须是Text,MU_Name;Items,Mu_Name这样的形式
        /// 注意:自动绑定时,数据源不能有空值,否则会绑定失败
        ///
        /// 特殊配置属性:
        /// Control.Text
        /// ComboBox.Items(DataSource为DataTable类型)
        ///
        /// </summary>
        /// <param name="control"></param>
        /// <param name="dataSource"></param>
        public static void AddDataBingding(Control control, object dataSource)
        {
            if ((control == null) || (control.Tag == null))
            {
                return;
            }
            if (control.Tag.GetType() != typeof(string))
            {
                return;
            }
            if (string.IsNullOrEmpty(control.Tag.ToString()))
            {
                return;
            }

            string        tag     = (string)control.Tag.ToString();
            List <string> setList = I3StringUtil.SplitStringToList(tag, ";");

            foreach (string str in setList)
            {
                List <string> set = I3StringUtil.SplitStringToList(str, ",");
                if (set.Count == 2)
                {
                    string propertyName = (string)set[0];
                    string fieldName    = (string)set[1];
                    if (string.Equals(propertyName, "Items"))
                    {
                        #region ComboBox.Items
                        if (control.GetType() == typeof(ComboBox))
                        {
                            ComboBox comboBox = (ComboBox)control;
                            comboBox.Items.Clear();
                            DataTable dataTable = (DataTable)dataSource;
                            foreach (DataRow row in dataTable.Rows)
                            {
                                comboBox.Items.Add(row[fieldName].ToString());
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        control.DataBindings.Add(propertyName, dataSource, fieldName);
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 校验18位身份证号码是否正确  正确返回false  并在信息中写入类似于 湖北,1983-09-13,男 的字符串
        /// 错误则返回false,并在信息中写入错误信息
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public static bool Check18PersonNO(string cid, out string result)
        {
            string[] aCity = new string[] { null, null, null, null, null, null, null, null, null, null, null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, "台湾", null, null, null, null, null, null, null, null, null, "香港", "澳门", null, null, null, null, null, null, null, null, "国外" };
            double   iSum  = 0;
            Regex    rg    = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|x)$");
            Match    mc    = rg.Match(cid);

            if (!mc.Success)
            {
                result = "";
                return(false);
            }
            cid = cid.ToLower();
            cid = cid.Replace("x", "a");
            if (aCity[int.Parse(I3StringUtil.SubString(cid, 0, 2))] == null)
            {
                result = "非法地区";
                return(false);
            }
            try
            {
                DateTime.Parse(I3StringUtil.SubString(cid, 6, 4) + "-" + I3StringUtil.SubString(cid, 10, 2) + "-" + I3StringUtil.SubString(cid, 12, 2));
            }
            catch
            {
                result = "非法生日";
                return(false);
            }
            for (int i = 17; i >= 0; i--)
            {
                iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
            }
            if (iSum % 11 != 1)
            {
                result = "非法证号";
                return(false);
            }
            result = aCity[int.Parse(I3StringUtil.SubString(cid, 0, 2))]
                     + "," + I3StringUtil.SubString(cid, 6, 4)
                     + "-" + I3StringUtil.SubString(cid, 10, 2)
                     + "-" + I3StringUtil.SubString(cid, 12, 2)
                     + "," + (int.Parse(I3StringUtil.SubString(cid, 16, 1)) % 2 == 1 ? "男" : "女");
            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// 长度必须大于5
        /// 指定获取的英文的长度,截取字符串,多余部分用..替代
        /// </summary>
        /// <param name="source"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string CutString(string source, int length)
        {
            if (string.IsNullOrEmpty(source))
            {
                return("");
            }

            if (length < 5)
            {
                throw new Exception("长度必须大于5");
            }

            string result       = "";
            int    resultLength = 0;
            int    lastLength   = 0;

            for (int i = 0; i <= source.Length - 1; i++)
            {
                string tmp       = source.Substring(i, 1);
                int    tmpLength = I3StringUtil.GetChineseCountInString(tmp) == 1 ? 2 : 1;
                if (resultLength + tmpLength > length)
                {
                    if (lastLength == 2)
                    {
                        result = result.Substring(0, result.Length - 1) + "..";
                    }
                    else
                    {
                        result = result.Substring(0, result.Length - 2) + "..";
                    }
                    return(result);
                }
                result       += tmp;
                resultLength += tmpLength;
                lastLength    = tmpLength;
            }
            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// 检查字段是否存在
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="tableName"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldType"></param>
        /// <param name="fieldLength"></param>
        public static void CheckField(DataTable dataTable, string fieldName, string caption, I3DataTypeEnum dataType, int fieldLength)
        {
            bool       have;
            DataColumn testdataColumn = null;

            try
            {
                testdataColumn = dataTable.Columns[fieldName];
                have           = testdataColumn != null;
            }
            catch (Exception)
            {
                have = false;
            }


            if (!have)
            {
                DataColumn dataColumn = new DataColumn(fieldName);
                CheckFieldInfo(dataColumn, caption, dataType, fieldLength);
                dataTable.Columns.Add(dataColumn);
            }
            else
            {
                testdataColumn.Caption = caption;
                //主键不可修改
                foreach (DataColumn col in dataTable.PrimaryKey)
                {
                    if (col == testdataColumn)
                    {
                        return;
                    }
                }

                //数据类型和长度相同不用修改
                if (CheckFieldInfoEqual(testdataColumn, dataType, fieldLength))
                {
                    return;
                }

                DataColumn dataColumn = new DataColumn(fieldName + "2");
                CheckFieldInfo(dataColumn, caption, dataType, fieldLength);
                dataTable.Columns.Add(dataColumn);
                string errString = "";
                if (!CopyFieldValue(dataTable, testdataColumn, dataColumn, ref errString))
                {
                    dataTable.Columns.Remove(dataColumn);
                    if (errString.Length > 1000)
                    {
                        errString = I3StringUtil.SubString(errString, 0, 1000) + "\r\n.........";
                    }
                    errString = "修改字段" + fieldName + "时出现错误!错误信息:\r\n" + errString;
                    MessageBox.Show(errString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    dataTable.Columns.Remove(testdataColumn);
                    dataColumn.ColumnName = fieldName;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 根据UDL文件中的连接信息和备份文件名,创建或者恢复数据库
        /// runMode:创建,恢复 
        /// </summary>
        /// <param name="udlFileName"></param>
        /// <returns></returns>
        public static bool RestoreSQLServerDataBase(string connectionString, string bakFileName, I3SQLServerRestoreMode restoreMode, I3SQLServerRestoreInfo restoreInfo, string dataFilePath)
        {
            #region 操作关键字
            string runMode = "";
            if (restoreMode == I3SQLServerRestoreMode.rmCreate)
            {
                runMode = "创建";
            }
            else
            {
                runMode = "恢复";
            }
            #endregion


            #region 从udl文件获取连接字符串
            //restoreInfo("一、连接字符串:" + connectionString, false, MessageBoxIcon.Warning);
            restoreInfo("一、获取连接字符串", false, MessageBoxIcon.Warning);
            //MessageBox.Show(connectionString);
            #endregion


            #region 获取服务器名,登录方式,数据库名等信息
            restoreInfo("", false, MessageBoxIcon.Warning);
            restoreInfo("二、解析服务器名,数据库名", false, MessageBoxIcon.Warning);
            //OleDbConnectionStringBuilder ob;
            SqlConnectionStringBuilder sb;
            try
            {
                sb = new SqlConnectionStringBuilder(connectionString);
            }
            catch (Exception ex)
            {
                restoreInfo("数据库连接字符串解析失败,错误消息:\r\n" + ex.Message, true, MessageBoxIcon.Error);
                return false;
            }
            string serverName = sb.DataSource.ToUpper();
            string dataBasename = sb["Initial Catalog"].ToString();
            restoreInfo("即将在服务器" + serverName + "上" + runMode + "数据库" + dataBasename, false, MessageBoxIcon.Warning);
            #endregion


            I3Data masterCon = null;
            try
            {
                #region 登录到master数据库,并检查数据库是否已经存在
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("三、连接数据库引擎", false, MessageBoxIcon.Warning);
                sb["Initial Catalog"] = "master";
                masterCon = I3Data.CreateDataSql(sb.ConnectionString);
                if (!masterCon.Active)
                {
                    restoreInfo("无法启动数据库引擎,错误消息:\r\n" + masterCon.LastErrorInfo, true, MessageBoxIcon.Error);
                    return false;

                    #region 检查是否本机,如果不是本机,则直接返回false
                    //if (!I3PCUtil.CheckServerNameIsLocal(serverName))
                    //{
                    //    restoreInfo("连接数据库引擎失败,但连接字符串中指定的服务器" + serverName + "不是本机,因此无法启动数据库引擎!", true, MessageBoxIcon.Error);
                    //    return false;
                    //}
                    #endregion

                    #region 启动数据库引擎 并重新连接
                    //if (MessageBox.Show("数据库引擎连接失败,需要启动数据库引擎吗?", "连接数据库引擎", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    //{
                    //    //IEFS_PC.RunService("MSSQLServer");
                    //    //为了有提示界面,通过调用SCM.exe来启动服务
                    //    I3MsgInfo msg = I3PCUtil.CreateAndWaitProcess("SCM.exe", " -action 1 -service MSSQLServer -SvcStartType 2 ", false);
                    //    if (msg.State)
                    //    {
                    //        Thread.Sleep(5000);
                    //        masterCon = I3Data.CreateDataOle(sb.ConnectionString);
                    //        if (!masterCon.Active)
                    //        {
                    //            restoreInfo("启动了数据库引擎,但仍然连接失败!请联系技术人员进行检查。", true, MessageBoxIcon.Error);
                    //            return false;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        restoreInfo("无法启动数据库引擎,错误消息:\r\n" + msg.Message, true, MessageBoxIcon.Error);
                    //        return false;
                    //    }
                    //}
                    //else
                    //{
                    //    restoreInfo("数据库引擎连接失败,无法创建默认数据库", true, MessageBoxIcon.Error);
                    //    return false;
                    //}
                    #endregion
                }
                restoreInfo("数据库引擎连接OK", false, MessageBoxIcon.Warning);
                #endregion


                #region 获取系统目录信息
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("四、获取目录信息", false, MessageBoxIcon.Warning);
                string dataRootPath = "";
                if (!string.IsNullOrEmpty(dataFilePath))
                {
                    dataRootPath = dataFilePath;
                    I3DirectoryUtil.CreateDirctory(dataRootPath);
                }
                else
                {
                    using (DataTable tmp = new DataTable("sysdatabases"))
                    {
                        string sqlStr = "select * from sysdatabases where name = 'master'";
                        I3MsgInfo msg = masterCon.FillTable(tmp, true, sqlStr, null, null);
                        if (!msg.State)
                        {
                            restoreInfo("取不到系统目录," + runMode + "操作中止!错误消息:\r\n" + msg.Message, true, MessageBoxIcon.Error);
                            return false;
                        }
                        try
                        {
                            if (tmp.Rows.Count == 0)
                            {
                                restoreInfo("取不到系统目录," + runMode + "操作中止!", true, MessageBoxIcon.Error);
                                return false;
                            }
                            dataRootPath = Path.GetDirectoryName(tmp.Rows[0]["filename"].ToString());
                        }
                        finally
                        {
                            masterCon.DisposeDataTable(tmp);
                        }
                        restoreInfo("系统目录获取成功:" + dataRootPath, false, MessageBoxIcon.Warning);
                    }
                }
                #endregion


                #region 校验备份文件
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("五、校验数据库备份文件", false, MessageBoxIcon.Warning);
                string moveStr = "";
                if (!File.Exists(bakFileName))
                {
                    restoreInfo("数据库备份文件不存在!\r\n文件路径:\r\n" + bakFileName, true, MessageBoxIcon.Error);
                    return false;
                }
                List<string> toDeleteFile = new List<string>();
                using (DataTable tmp = new DataTable("FILELISTONLY"))
                {
                    string sqlStr = " RESTORE FILELISTONLY from disk=" + I3StringUtil.QuotedStr(bakFileName);
                    I3MsgInfo msg = masterCon.FillTable(tmp, true, sqlStr, null, null);
                    if (!msg.State)
                    {
                        restoreInfo("该备份文件不是数据库备份文件!\r\n文件路径:\r\n" + bakFileName + "\r\n错误消息:\r\n" + msg.Message, true, MessageBoxIcon.Error);
                        return false;
                    }
                    try
                    {
                        foreach (DataRow row in tmp.Rows)
                        {
                            if (row["Type"].ToString() == "D")
                            {
                                string fileName = Path.Combine(dataRootPath, dataBasename.Trim() + "_Dat.MDF");
                                toDeleteFile.Add(fileName);
                                moveStr = moveStr + " Move " + I3DBUtil.QuotedStr(row["logicalname"].ToString())
                                        + " To " + I3DBUtil.QuotedStr(fileName) + ",";
                            }
                            else
                            {
                                string fileName = Path.Combine(dataRootPath, dataBasename.Trim() + "_Log.LDF");
                                toDeleteFile.Add(fileName);
                                moveStr = moveStr + " Move " + I3DBUtil.QuotedStr(row["logicalname"].ToString())
                                        + " To " + I3DBUtil.QuotedStr(fileName) + ",";
                            }
                        }
                        moveStr = I3StringUtil.SubString(moveStr, 0, moveStr.Length - 1);
                        //MessageBox.Show(moveStr);
                    }
                    finally
                    {
                        masterCon.DisposeDataTable(tmp);
                    }
                }

                restoreInfo("数据库备份文件校验成功", false, MessageBoxIcon.Warning);
                #endregion

                #region 删除现有数据库
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("六、检查数据库" + dataBasename + "是否已经存在", false, MessageBoxIcon.Warning);
                bool has;
                #region 获取数据库是否已经存在
                using (DataTable tmp = new DataTable("sysdatabases"))
                {
                    string sqlStr = " select * from sysdatabases where name = " + I3DBUtil.QuotedStr(dataBasename);
                    I3MsgInfo msg = masterCon.FillTable(tmp, true, sqlStr, null, null);
                    if (!msg.State)
                    {
                        restoreInfo("出现错误,操作中止!错误消息:\r\n" + msg.Message, true, MessageBoxIcon.Error);
                        return false;
                    }
                    try
                    {
                        has = tmp.Rows.Count > 0;
                    }
                    finally
                    {
                        masterCon.DisposeDataTable(tmp);
                    }
                }
                #endregion
                if (has)
                {
                    if (restoreMode == I3SQLServerRestoreMode.rmCreate)
                    {
                        restoreInfo("数据库" + dataBasename + "已经存在,不能创建数据库!", true, MessageBoxIcon.Error);
                        return false;
                    }

                    #region 删除数据库
                    if (MessageBox.Show("数据库" + dataBasename + "已经存在,是否删除?\r\n警告:进行删除操作前,请确认之前已经备份数据库,否则所有数据将丢失!", "删除数据库", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        restoreInfo("开始删除数据库" + dataBasename, false, MessageBoxIcon.Warning);
                        string sqlStr = " DROP DATABASE " + dataBasename;
                        I3MsgInfo msg = masterCon.Execute(sqlStr, null);
                        if (msg.State)
                        {
                            restoreInfo("数据库" + dataBasename + "删除成功", false, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            restoreInfo("数据库" + dataBasename + "删除失败,错误消息:" + msg.Message, true, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    else
                    {
                        restoreInfo("数据库" + dataBasename + "已经存在,用户放弃删除,不能" + runMode + "数据库!", true, MessageBoxIcon.Error);
                        return false;
                    }
                    #endregion

                }
                #region 再次删除数据库文件 注:确保清空文件
                foreach (string s in toDeleteFile)
                {
                    I3FileUtil.CheckFileNotExists(s);
                }
                #endregion
                restoreInfo("现有数据库删除成功,可以进行下一步操作", false, MessageBoxIcon.Warning);
                #endregion
                
                #region 恢复
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("七、开始" + runMode + "数据库,请耐心等待", false, MessageBoxIcon.Warning);
                string restoreStr = " RESTORE DATABASE " + dataBasename.Trim()
                                  + " From Disk = " + I3DBUtil.QuotedStr(bakFileName)
                                  + " with " + moveStr;
                //MessageBox.Show(restoreStr);
                SqlCommand com = new SqlCommand(restoreStr, (SqlConnection)masterCon.GetConnection());
                try
                {
                    com.CommandTimeout = 600;
                    com.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    restoreInfo("数据库" + dataBasename + runMode + "不成功!错误消息:\r\n" + ex.Message, true, MessageBoxIcon.Error);
                    return false;
                }
                finally
                {
                    com.Dispose();
                }


                restoreInfo("数据库" + runMode + "成功!", true, MessageBoxIcon.Warning);
                restoreInfo("", false, MessageBoxIcon.Warning);
                restoreInfo("", false, MessageBoxIcon.Warning);
                #endregion


                return true;
            }
            finally
            {
                if (masterCon != null && masterCon.Active)
                {
                    masterCon.Close();
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 将金钱转换为大写人民币
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string ConvertMoneyToUpper(decimal num)
        {
            string str1 = "零壹贰叁肆伍陆柒捌玖";                        //0-9所对应的汉字
            string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";                   //数字位所对应的汉字
            string str3 = "";                                  //从原num值中取出的值
            string str4 = "";                                  //数字的字符串形式
            string str5 = "";                                  //人民币大写金额形式
            int    i;                                          //循环变量
            int    j;                                          //num的值乘以100的字符串长度
            string ch1   = "";                                 //数字的汉语读法
            string ch2   = "";                                 //数字位的汉字读法
            int    nzero = 0;                                  //用来计算连续的零值是几个
            int    temp;                                       //从原num值中取出的值

            num  = System.Math.Round(System.Math.Abs(num), 2); //将num取绝对值并四舍五入取2位小数
            str4 = ((long)(num * 100)).ToString();             //将num乘100并转换成字符串形式
            j    = str4.Length;                                //找出最高位
            if (j > 15)
            {
                return("溢出");
            }
            str2 = I3StringUtil.SubString(str2, 15 - j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分

            //循环取出每一位需要转换的值
            for (i = 0; i < j; i++)
            {
                str3 = I3StringUtil.SubString(str4, i, 1); //取出需转换的某一位的值
                temp = Convert.ToInt32(str3);              //转换为数字
                #region 当所取位数不为元、万、亿、万亿上的数字时
                if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                {
                    if (str3 == "0")
                    {
                        ch1   = "";
                        ch2   = "";
                        nzero = nzero + 1;
                    }
                    else
                    {
                        if (str3 != "0" && nzero != 0)
                        {
                            ch1   = "零" + I3StringUtil.SubString(str1, temp * 1, 1);
                            ch2   = I3StringUtil.SubString(str2, i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            ch1   = I3StringUtil.SubString(str1, temp * 1, 1);
                            ch2   = I3StringUtil.SubString(str2, i, 1);
                            nzero = 0;
                        }
                    }
                }
                #endregion
                #region 该位是万亿,亿,万,元位等关键位
                else
                {
                    if (str3 != "0" && nzero != 0)
                    {
                        ch1   = "零" + I3StringUtil.SubString(str1, temp * 1, 1);
                        ch2   = I3StringUtil.SubString(str2, i, 1);
                        nzero = 0;
                    }
                    else
                    {
                        if (str3 != "0" && nzero == 0)
                        {
                            ch1   = I3StringUtil.SubString(str1, temp * 1, 1);
                            ch2   = I3StringUtil.SubString(str2, i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            if (str3 == "0" && nzero >= 3)
                            {
                                ch1   = "";
                                ch2   = "";
                                nzero = nzero + 1;
                            }
                            else
                            {
                                if (j >= 11)
                                {
                                    ch1   = "";
                                    nzero = nzero + 1;
                                }
                                else
                                {
                                    ch1   = "";
                                    ch2   = I3StringUtil.SubString(str2, i, 1);
                                    nzero = nzero + 1;
                                }
                            }
                        }
                    }
                }
                #endregion

                if (i == (j - 11) || i == (j - 3))
                {
                    //如果该位是亿位或元位,则必须写上
                    ch2 = I3StringUtil.SubString(str2, i, 1);
                }

                str5 = str5 + ch1 + ch2;

                if (i == j - 1 && str3 == "0")
                {
                    //最后一位(分)为0时,加上“整”
                    str5 = str5 + '整';
                }
            }

            if (num == 0)
            {
                str5 = "零元整";
            }

            return(str5);
        }
Esempio n. 16
0
 /// <summary>
 /// 在程序运行目录下的tmp临时目录下,获取一个临时目录的路径
 /// 注:路径名是一个guid,永远不重复
 /// 注:仅返回路径名,不生成目录
 ///
 /// 这里不能用IEFS_DateTime.ConvertDateTimeToLongString,因为如果在短时间内执行此代码多次时,返回的目录名会重复,删除时会错误
 /// 因此用一个Guid作为临时目录名,肯定不会重复
 ///
 /// </summary>
 /// <returns></returns>
 public static string GetAppTmpTmpDir()
 {
     return(Path.Combine(I3DirectoryUtil.GetAppTmpDir(), I3StringUtil.GetAGuid()));
 }