Пример #1
0
        private static string SumFormat(string format, string key1, string key2)
        {
            if (format.Contains(key1) && format.Contains(key2))
            {
                string[] array1 = format.Split('/');

                if (array1.Length == 2)
                {
                    string[] array = array1[0].Split('x');

                    if (array.Length == 3)
                    {
                        decimal value = Convert.ToDecimal(CommonFun.GetNum(array[1])) * Convert.ToDecimal(CommonFun.GetNum(array[2]));

                        return(array[0] + "x" + value + key1 + "/" + array1[1]);
                    }
                }
                else
                {
                    string[] array = format.Split('x');
                    if (array.Length == 3)
                    {
                        decimal value = Convert.ToDecimal(CommonFun.GetNum(array[1])) * Convert.ToDecimal(CommonFun.GetNum(array[2]));

                        return(array[0] + "x" + value + key1);
                    }
                }
            }

            return(format);
        }
Пример #2
0
        public static bool IsSameItem(string id1, string id2, string format1, string format2, string name1, string name2)
        {
            id1 = CommonFun.GetNum(id1);
            id2 = CommonFun.GetNum(id2);
            if (id1.Contains(id2) || id2.Contains(id1))
            {
                if (IsSameFormat(format1, format2) || IsSameFormat(format1, format2, name1, name2))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public static string FormatStr(string format, string name)
        {
            try
            {
                if (format.Contains('+'))
                {
                }

                if ((format.Contains('(') && format.Contains(')')) || (format.Contains('(') && format.Contains(')')))
                {
                    if ((format.Contains('(') && format.Contains(')')))
                    {
                        format = format.Substring(0, format.IndexOf('(')) + format.Substring(format.IndexOf(')') + 1, format.Length - format.IndexOf(')') - 1);
                    }
                    else
                    {
                        format = format.Substring(0, format.IndexOf('(')) + format.Substring(format.IndexOf(')') + 1, format.Length - format.IndexOf(')') - 1);
                    }
                }

                format = format.Replace("/盒/盒", "/盒");
                format = format.Replace("(", "");
                format = format.Replace(")", "");
                format = format.Replace("(", "");
                format = format.Replace(")", "");
                format = format.Replace("毫克", "mg");
                format = format.Replace('克', 'g');
                format = format.Replace('G', 'g');
                format = format.Replace('*', 'x');
                format = format.Replace('×', 'x');
                format = format.Replace(':', ':');
                format = format.Replace('∶', ':');
                format = format.Replace("..", ".");
                format = format.Replace("毫升", "ml");
                format = format.Replace("丸", "粒");
                format = format.Replace("张", "贴");
                format = format.Replace("瓶/盒", "/瓶");
                format = format.Replace("g/袋", "g");
                format = format.Replace("万单位", "IU");

                if (!string.IsNullOrEmpty(name))
                {
                    if (name.Contains("片"))
                    {
                        format = format.Replace('s', '片');
                        format = format.Replace('粒', '片');
                    }
                    else
                    {
                        format = format.Replace('s', '粒');
                    }
                }
                if (format.Contains("mg") || format.Contains("g"))
                {
                    string[] values = format.Split('x');

                    if (values[0].Contains(':'))
                    {
                        values[0] = values[0].Substring(0, values[0].IndexOf(':'));
                    }

                    decimal value1 = format.Contains("mg") ? (Convert.ToDecimal(CommonFun.GetNum(values[0])) / 1000) : Convert.ToDecimal(CommonFun.GetNum(values[0]));

                    format = "";

                    format += value1 + "g" + "x";

                    for (int i = 1; i < values.Length; i++)
                    {
                        format += values[i] + "x";
                    }

                    format = format.Substring(0, format.LastIndexOf('x'));
                }

                if (format.Contains("片") && format.Contains("板"))
                {
                    return(SumFormat(format, "片", "板"));
                }
                else if (format.Contains("粒") && format.Contains("板"))
                {
                    return(SumFormat(format, "粒", "板"));
                }
                else if (format.Contains("粒") && format.Contains("瓶"))
                {
                    return(SumFormat(format, "粒", "瓶"));
                }
                else if (format.Contains("片") && format.Contains("瓶"))
                {
                    return(SumFormat(format, "片", "瓶"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(format + ex.ToString());
            }
            return(format);
        }
Пример #4
0
        public static bool IsSameFormat(string format1, string format2, string name1, string name2)
        {
            string pFormat = FormatStr(format1, name1);

            string sFormat = FormatStr(format2, name2);

            string[] array1 = pFormat.Split('/');

            string[] array2 = sFormat.Split('/');

            try
            {
                if (array1[0].Contains('x'))
                {
                    string[] values = array1[0].Split('x');
                    decimal  format = 1;
                    foreach (string value in values)
                    {
                        if (value.Contains(":"))
                        {
                            string[] sValues = value.Split(':');
                            foreach (string sValue in sValues)
                            {
                                string num = CommonFun.GetNum(sValue);
                                format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                            }
                        }
                        else
                        {
                            string num = CommonFun.GetNum(value);
                            format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                        }
                    }
                    string info = Regex.Replace(values[0], @"[\d.\d]", "");
                    if (string.IsNullOrEmpty(info) && !string.IsNullOrEmpty(values[1]))
                    {
                        info = Regex.Replace(values[1], @"[\d.\d]", "");
                    }

                    array1[0] = format + info;
                }

                if (array2[0].Contains('x'))
                {
                    string[] values = array2[0].Split('x');
                    decimal  format = 1;
                    foreach (string value in values)
                    {
                        if (value.Contains(":"))
                        {
                            string[] sValues = value.Split(':');
                            foreach (string sValue in sValues)
                            {
                                string num = CommonFun.GetNum(sValue);
                                format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                            }
                        }
                        else
                        {
                            string num = CommonFun.GetNum(value);
                            format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                        }
                    }
                    string info = Regex.Replace(values[0], @"[\d.\d]", "");
                    array2[0] = format + info;
                }

                if (array1.Length == 2 && array2.Length == 2)
                {
                    if (array1[1].Contains('x'))
                    {
                        string[] values = array1[1].Split('x');
                        string   info   = Regex.Replace(array1[0], @"[\d.\d]", "");
                        array1[0] = Convert.ToDecimal(CommonFun.GetNum(values[1])) * Convert.ToDecimal(CommonFun.GetNum(array1[0])) + info;
                    }

                    if (array2[1].Contains('x'))
                    {
                        string[] values = array2[1].Split('x');
                        string   info   = Regex.Replace(array2[0], @"[\d.\d]", "");
                        array2[0] = Convert.ToDecimal(CommonFun.GetNum(values[1])) * Convert.ToDecimal(CommonFun.GetNum(array2[0])) + info;
                    }

                    if (array1[0] == array2[0])
                    {
                        return(true);
                    }
                }
                else
                {
                    if (array1[0] == array2[0])
                    {
                        return(true);
                    }
                    else
                    {
                        string[] value1 = array1[0].Split('x');
                        string[] value2 = array2[0].Split('x');

                        if (value1.Length != value2.Length)
                        {
                            if (value1[0] == value2[0])
                            {
                                return(true);
                            }
                            //List<decimal> lValue1 = new List<decimal>();
                            //foreach(string value in value1)
                            //{
                            //    lValue1.Add(Convert.ToDecimal(CommonFun.GetNum(value)));
                            //}

                            //foreach (string value in value2)
                            //{
                            //    if(lValue1.Contains(Convert.ToDecimal(CommonFun.GetNum(value))))
                            //    {
                            //        return true;
                            //    }
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// 获取非数字部分
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        //public static string GetUnNum(string value)
        //{
        //    return Regex.Replace(value, @"[\d.\d]", "");
        //}

        public static double GetFormatValue(string format)
        {
            double result = 0;

            try
            {
                format = format.Replace("毫克", "mg");
                format = format.Replace('克', 'g');
                format = format.Replace('G', 'g');
                format = format.Replace('*', 'x');
                format = format.Replace('×', 'x');
                format = format.Replace(':', ':');
                format = format.Replace('∶', ':');
                format = format.Replace("..", ".");
                format = format.Replace("毫升", "ml");

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

                string[] aFormat = format.Split('/');

                foreach (string iformat in aFormat)
                {
                    if (iformat.Contains('x'))
                    {
                        string[] aFormat1 = iformat.Split('x');

                        foreach (string iformat1 in aFormat1)
                        {
                            if (iformat1.Contains(':'))
                            {
                                valueList.AddRange(iformat1.Split(':'));
                            }
                            else
                            {
                                valueList.Add(iformat1);
                            }
                        }
                    }
                    else
                    {
                        valueList.Add(iformat);
                    }
                }

                foreach (string value in valueList)
                {
                    string numStr = CommonFun.GetNum(value);
                    double num    = string.IsNullOrEmpty(numStr) ? 1 : Convert.ToDouble(numStr);

                    if (result == 0)
                    {
                        result = num * 100000;
                    }
                    else
                    {
                        result *= num;
                    }
                }

                if (format.Contains("mg"))
                {
                    result /= 1000;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }