Beispiel #1
0
        public static Dictionary<int, PixelClass> GetSigns(ImgInfo info)
        {
            var dict = info.Classes;
            var labels = info.Labels;
            for (int i = 0; i < labels.GetLength(0); i++)
                for (int j = 0; j < labels.GetLength(1); j++)
                {
                    if (labels[i, j] == 0) continue;
                    var pclass = dict[labels[i, j]];
                    if (pclass.Angles.Bottom.Y < j)
                        pclass.Angles.Bottom = new Point(i, j);
                    if (pclass.Angles.Top.Y > j)
                        pclass.Angles.Top = new Point(i, j);
                    if (pclass.Angles.Left.X > i)
                        pclass.Angles.Left = new Point(i, j);
                    if (pclass.Angles.Right.X < i)
                        pclass.Angles.Right = new Point(i, j);
                }

            foreach (var v in dict)
            {
                v.Value.Width = v.Value.Angles.Right.X - v.Value.Angles.Left.X;
                v.Value.Height = v.Value.Angles.Bottom.Y - v.Value.Angles.Top.Y;
                v.Value.Ratio = (float)v.Value.Weight / (v.Value.Height * v.Value.Width);
                v.Value.Center = new Point(v.Value.Angles.Left.X + v.Value.Width / 2, v.Value.Angles.Top.Y + v.Value.Height / 2);
            }
            return dict;
        }
Beispiel #2
0
        public static Bitmap Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);

            if (imgInfo.numOfComponents != 1 && imgInfo.numOfComponents != 3)
                throw new Exception("Unsupported number of components (" +
                    imgInfo.numOfComponents + ")");

            ushort length = reader.ReadBEUInt16();
            byte componentsInScan = reader.ReadByte();

            for (int i = 0; i < componentsInScan; i++)
            {
                byte componentId = (byte)(reader.ReadByte() - 1);
                byte huffmanTables = reader.ReadByte();

                byte acTable = (byte)(huffmanTables & 0xf);
                byte dcTable = (byte)(huffmanTables >> 4);

                imgInfo.components[componentId].dcHuffmanTable = dcTable;
                imgInfo.components[componentId].acHuffmanTable = acTable;
            }

            reader.ReadBytes(3); // "Unused" bytes

            return ImageDecoder.DecodeImage(reader, imgInfo);
        }
Beispiel #3
0
        public static Bitmap DrawClasses(ImgInfo imgInfo, Designer designer)
        {
            var labels = imgInfo.Labels;
            List<int> classesToRemove = new List<int>();
            Bitmap result = new Bitmap(imgInfo.OldPicture.Width, imgInfo.OldPicture.Height);
            for (int i = 0; i < result.Height; i++)
                for (int j = 0; j < result.Width; j++)
                    if (labels[j, i] != 0)
                    {
                        //var cl = imgInfo.Classes[labels[j, i]];
                        result.SetPixel(j, i, labels[j, i] < 0 ? Color.FromArgb(Math.Abs((labels[j, i]*15)%255), 
                                              Math.Abs(labels[j, i] * 12 + labels[j, i] * labels[j, i]) % 255,
                                              Math.Abs((labels[j, i] * 5 + labels[j, i]) % 255 * labels[j, i]) % 255)
                            : Color.Brown);
                        // Color.FromArgb(Math.Abs((labels[j, i]*15)%255), Color.AliceBlue));
                        //Math.Abs(labels[j, i] * 12 + labels[j, i] * labels[j, i]) % 255,
                        //Math.Abs((labels[j, i] * 5 + labels[j, i]) % 255 * labels[j, i]) % 255));
                        //else
                        //{
                        //   classesToRemove.Add(labels[j, i]);
                        //    labels[j, i] = 0;
                        //}
                    }

            foreach (var r in classesToRemove)
            {
                imgInfo.Classes.Remove(r);
            }
            return result;
        }
Beispiel #4
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);

            ushort length = reader.ReadBEUInt16();
            Logger.WriteLine("Length: " + length.ToString());

            reader.BaseStream.Seek(length - 2, SeekOrigin.Current);
        }
Beispiel #5
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);
            int markerLength = reader.ReadBEUInt16() - 2;

            while (markerLength > 0)
            {
                int length = ReadTable(reader, imgInfo);
                markerLength -= length;
            }
        }
Beispiel #6
0
        public void ReceiveScreenshots(Dictionary<int, byte[]> screenshots, HttpContext context)
        {
            foreach (var kv in screenshots)
            {
                var file = Path.GetRandomFileName() + ".png";
                var vPathName = @"~\img\" + file;
                var url = new System.Uri(context.Request.Url, @"img\" + file).AbsoluteUri;
                var physPathName = Path.Combine(context.Server.MapPath("~"), "img", file);

                var imgInfo = new ImgInfo { PhysPath = physPathName, VPath = vPathName, url = url };
              
                File.WriteAllBytes(physPathName, kv.Value);
                _screenshotFiles.Add(kv.Key, imgInfo);
            }
        }
Beispiel #7
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);

            int length = reader.ReadBEUInt16();

            ushort restartInterval = reader.ReadBEUInt16();

            if (restartInterval == 0)
                throw new Exception("Invalid restart interval (0)");

            imgInfo.restartInterval = restartInterval;
            imgInfo.hasRestartMarkers = true;

            Log(reader, imgInfo.restartInterval);
        }
Beispiel #8
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);
            ushort markerLength = reader.ReadBEUInt16();

            reader.ReadBytes(11);

            imgInfo.app14MarkerFound = true;
            imgInfo.colorMode = (App14ColorMode)reader.ReadByte();

            if ((int)imgInfo.colorMode > 2)
                throw new Exception("Invalid Adobe colorspace");

            Logger.WriteLine("Transform Flag: " + imgInfo.colorMode);
            Logger.WriteLine();
        }
        public static Designer GetConfiguration(ImgInfo imgInfo )
        {
            var result = new Designer();
            result.Add(new DesignExpression(cl=>  cl.Ratio > LowThreshold));
            result.Add(new DesignExpression(cl => cl.Ratio < HighThreshold));
            
            result.Add(new DesignExpression(cl => (float)cl.Width / cl.Height > 0.1));
            result.Add(new DesignExpression(cl => (float)cl.Width / cl.Height < 10));
            result.Add(new DesignExpression(cl => cl.MaxDiff < cl.Weight / 3.33));
            //result.Add(new DesignExpression(cl => cl.Height > 20));
            //result.Add(new DesignExpression(cl => cl.Width > 20)); 
            result.Add(new DesignExpression(cl => cl.Weight > 70));
            result.Add(new DesignExpression(cl=> !(cl.Angles.Left.X == 0 && cl.Angles.Right.X ==  imgInfo.OldPicture.Width-1) ));

            return result;
        }
Beispiel #10
0
        public static PixelClass GetFourWeight(PixelClass pclass, ImgInfo inf)
        {
            int[] foutWeight = { 0, 0, 0, 0 };
            Point[] fourPoints = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                fourPoints[i] = new Point(pclass.Center.X, pclass.Center.Y);
            }
            for (int i = pclass.Angles.Left.X; i < pclass.Angles.Right.X; i++)
                for (int j = pclass.Angles.Top.Y; j < pclass.Angles.Bottom.Y; j++)
                {
                    int index = 0;
                    if (i > pclass.Center.X)
                        index = 1;
                    if (j > pclass.Center.Y)
                        index += 2;
                    if (inf.Labels[i, j] == pclass.Class)
                    {
                        var olppoint = Math.Pow(fourPoints[index].X - pclass.Center.X, 2) +
                        Math.Pow(fourPoints[index].Y - pclass.Center.Y, 2);

                        var newp = Math.Pow(i - pclass.Center.X, 2) +
                        Math.Pow(j - pclass.Center.Y, 2);

                        if (olppoint < newp)
                            fourPoints[index] = new Point(i, j);
                        foutWeight[index] += 1;
                    }
                }


            int maxDiff = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = i; j < 4; j++)
                {
                    if (maxDiff < Math.Abs(foutWeight[i] - foutWeight[j]))
                        maxDiff = Math.Abs(foutWeight[i] - foutWeight[j]);
                }
            }
            pclass.FourPoints = fourPoints;
            pclass.FourWeights = foutWeight;
            pclass.MaxDiff = maxDiff;
            return pclass;
        }
Beispiel #11
0
        static void Log(BinaryReader reader, ImgInfo imgInfo)
        {
            Logger.WriteLine("Length: " + imgInfo.length);
            Logger.WriteLine("Width: " + imgInfo.width + " Height: " + imgInfo.height);

            Logger.WriteLine("Number of components: " + imgInfo.numOfComponents);
            Logger.WriteLine("Data precision: " + imgInfo.dataPrecision);
            Logger.WriteLine();

            for (int i = 0; i < imgInfo.numOfComponents; i++)
            {
                Logger.WriteLine("Component " + i);
                Logger.WriteLine("ID: " + imgInfo.components[i].id);
                Logger.WriteLine("Sampling Factor X: " + imgInfo.components[i].samplingFactorX);
                Logger.WriteLine("Sampling Factor Y: " + imgInfo.components[i].samplingFactorY);
            }

            Logger.WriteLine();
        }
Beispiel #12
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            LogMarker(reader, name);

            imgInfo.length = reader.ReadBEUInt16();
            imgInfo.dataPrecision = reader.ReadByte();
            imgInfo.height = reader.ReadBEUInt16();
            imgInfo.width = reader.ReadBEUInt16();
            imgInfo.numOfComponents = reader.ReadByte();

            if (imgInfo.length < 8)
                throw new Exception("Invalid length of Sof0");

            if (imgInfo.height == 0 || imgInfo.width == 0)
                throw new Exception("Invalid image size");

            if (imgInfo.dataPrecision != 8)
                throw new Exception("Unsupported data precision");

            if (imgInfo.numOfComponents != 1 && imgInfo.numOfComponents != 3)
                throw new Exception("Invalid number of components");

            imgInfo.components = new ComponentInfo[imgInfo.numOfComponents];

            for (int i = 0; i < imgInfo.numOfComponents; i++)
            {
                byte id = reader.ReadByte();

                if (id > 3)
                    throw new Exception("Invalid component type");

                byte samplingFactor = reader.ReadByte();

                imgInfo.components[i].id = id;
                imgInfo.components[i].samplingFactorX = (byte)(samplingFactor >> 4);
                imgInfo.components[i].samplingFactorY = (byte)(samplingFactor & 0x0f);

                imgInfo.components[i].quantTableId = reader.ReadByte();
            }

            Log(reader, imgInfo);
        }
Beispiel #13
0
        public static void Rectangles(Bitmap bitmap, ImgInfo info)
        {
            foreach (var c in info.Classes)
            {
                if (c.Value.FourPoints != null)
                {
                    foreach (var v in c.Value.FourPoints)
                    {
                        Rect(bitmap, v, Color.Green);
                    }
                    //Rect(bitmap, imgInfo.Value.Angles.Right);
                    //Rect(bitmap, imgInfo.Value.Angles.Left);
                    //Rect(bitmap, imgInfo.Value.Angles.Top);
                    //Rect(bitmap, imgInfo.Value.Angles.Bottom);
                    Rect(bitmap, c.Value.Center, Color.Red);
                }
                                    
            }

        }
Beispiel #14
0
        public static int ReadTable(BinaryReader reader, ImgInfo imgInfo)
        {
            byte tableInfo = reader.ReadByte();
            byte tableId = (byte)(tableInfo & 0xf); // Low 4 bits of tableInfo

            if (tableId > 3)
                throw new Exception("Invalid ID for quantization table");

            var quantTable = new QuantTable();

            quantTable.id = tableId;
            quantTable.precision = (byte)(tableInfo >> 4); // High 4 bits of tableInfo
            quantTable.valid = true;
            quantTable.table = new ushort[64];

            int sizeOfElement = quantTable.precision == 0 ? 1: 2;

            var tabla = FileOps.tablasZigzag[8];

            // Quantizer tables are in zigzag too!
            if (quantTable.precision == 0)
            {
                for (int i = 0; i < 64; i++)
                {
                    quantTable.table[tabla[i].Y * 8 + tabla[i].X] = reader.ReadByte();
                }
            }
            else
            {
                for (int i = 0; i < 64; i++)
                {
                    quantTable.table[tabla[i].Y * 8 + tabla[i].X] = reader.ReadBEUInt16();
                }
            }

            imgInfo.quantTables[tableId] = quantTable;

            Log(reader, quantTable);

            return 1 + 64 * sizeOfElement;
        }
Beispiel #15
0
        static void ResampleScreenshotOfFinalScene(ImgInfo imgInfo)
        {
            var screenshotStream = new FileStream(imgInfo.PhysPath, FileMode.Open);
            var bmp = new Bitmap(screenshotStream);
            screenshotStream.Close();

            int newWidth;
            int newHeight;
            if (bmp.Width > 2024)
            {
                newWidth = 2024;
                newHeight = newWidth * bmp.Height / bmp.Width;
            }
            else
            {
                newWidth  = bmp.Width;
                newHeight = bmp.Height;
            }
            var resized = ImageUtilities.ResizeImage(bmp, newWidth, newHeight);
            resized.Save(imgInfo.PhysPath, ImageFormat.Png);
        }
Beispiel #16
0
        public static int ReadTable(BinaryReader reader, ImgInfo imgInfo)
        {
            byte tableInfo = reader.ReadByte();
            byte tableId = (byte)(tableInfo & 0x7); // Low 3 bits of tableInfo
            int numCodes = 0;

            if (tableId > 3)
                throw new Exception("Invalid ID for huffman table");

            if ((tableInfo & 0xe0) != 0)  // High 3 bits of tableInfo must be zero
                throw new Exception("Invalid huffman table");

            var huffmanTable = new HuffmanTable();

            huffmanTable.id = tableId;
            huffmanTable.type = (byte)((tableInfo >> 4) & 0x1); // Bit 4 of tableInfo
            huffmanTable.valid = true;
            huffmanTable.numSymbols = new byte[16];

            for (int i = 0; i < 16; i++)
            {
                huffmanTable.numSymbols[i] = reader.ReadByte();
                numCodes += huffmanTable.numSymbols[i];
            }

            huffmanTable.codes = new byte[numCodes];

            for (int i = 0; i < numCodes; i++)
            {
                huffmanTable.codes[i] = reader.ReadByte();
            }

            Huffman.CreateTable(ref huffmanTable);

            imgInfo.huffmanTables[huffmanTable.type, huffmanTable.id] = huffmanTable;

            Log(reader, huffmanTable);

            return 1 + 16 + numCodes;
        }
Beispiel #17
0
        public static void Read(BinaryReader reader, ImgInfo imgInfo, Pixz.Markers markerId)
        {
            Logger.Write("Unknown marker (" + markerId.ToString("X") + ")");

            if (!imgInfo.startOfImageFound)
            {
                Logger.Write(" found outside of image");
            }

            Logger.WriteLine(" at: " + (reader.BaseStream.Position - 2).ToString("X"));

            // Check if marker is not followed by a length argument
            if (markerId >= Pixz.Markers.Rs0 && markerId <= Pixz.Markers.Rs7)
                return;
            if (markerId == Pixz.Markers.LiteralFF)
                return;

            if (!imgInfo.startOfImageFound) return;

            ushort length = reader.ReadBEUInt16();
            Logger.WriteLine("Length: " + length.ToString());

            reader.BaseStream.Seek(length - 2, SeekOrigin.Current);
        }
Beispiel #18
0
        /// <summary>
        /// 楼层数据整理
        /// </summary>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <param name="entId"></param>
        /// <param name="landing"></param>
        /// <param name="staleDated"></param>
        /// <param name="jgjb"></param>
        /// <returns></returns>
        private List <IndexFloor> FillFloor(DataTable t1, DataTable t2, string entId, bool landing, bool staleDated, string jgjb, string userId)
        {
            ///获取网站ip
            string            web_url = BaseConfiguration.SercerIp;
            List <IndexFloor> list    = new List <IndexFloor>();

            foreach (DataRow dr in t1.Rows)
            {
                IndexFloor lc = new IndexFloor
                {
                    Entid           = dr["entid"].ToString().Trim(),
                    FloorId         = dr["FloorId"].ToString().Trim(),
                    FloorTitle      = dr["FloorTitle"].ToString().Trim(),
                    Link_Url        = dr["Floor_Link"].ToString().Trim(),
                    TypeName        = dr["TypeName"].ToString().Trim(),
                    Type            = dr["imgTypeS"].ToString().Trim(),
                    AndroidLinkType = int.Parse(dr["androidlinktype"].ToString()),
                    AndroidLinkUrl  = dr["androidlinkurl"].ToString().Trim()
                };
                if (dr["Floor_Img"].ToString().Trim() != "")
                {
                    lc.Floor_Img = web_url + dr["Floor_Img"].ToString().Trim();
                }
                else
                {
                    lc.Floor_Img = "";
                }
                List <ImgInfo> imgList = new List <ImgInfo>();
                if (t2.Rows.Count > 0)
                {
                    DataRow[] imgDr = t2.Select("EntId='" + entId + "' and FloorId='" + lc.FloorId + "'", "sort_Id asc");
                    //楼层详细数据
                    foreach (DataRow drI in imgDr)
                    {
                        ImgInfo img = new ImgInfo
                        {
                            Entid           = drI["entid"].ToString().Trim(),
                            Title           = drI["FloorTitle"].ToString().Trim(),
                            ArticleId       = drI["Article_Id"].ToString().Trim(),
                            SortId          = int.Parse(drI["sort_Id"].ToString().Trim()),
                            IsBrand         = drI["Is_Brand"].ToString().Trim(),
                            BrandCode       = drI["BrandCode"].ToString().Trim(),
                            LinkUrl         = drI["link_url"].ToString().Trim(),
                            AndroidLinkType = int.Parse(dr["androidlinktype"].ToString()),
                            AndroidLinkUrl  = drI["androidlinkurl"].ToString().Trim()
                        };
                        if (drI["img_url"].ToString().Trim() != "")
                        {
                            img.ImgUrl = web_url + drI["img_url"].ToString().Trim();
                        }
                        else
                        {
                            img.ImgUrl = "";
                        }
                        if (drI["left_pic"].ToString().Trim() != "")
                        {
                            img.LeftPic = web_url + drI["left_pic"].ToString().Trim();
                        }
                        if (drI["brand_img_url"].ToString().Trim() != "")
                        {
                            img.BrandImgUrl = web_url + drI["brand_img_url"].ToString().Trim();
                        }
                        else
                        {
                            img.BrandImgUrl = "";
                        }
                        img.SubTitle    = drI["sub_title"].ToString().Trim();
                        img.DrugSpec    = drI["drug_spec"].ToString().Trim();
                        img.DrugFactory = drI["drug_factory"].ToString().Trim();
                        if (landing && !staleDated)
                        {
                            img.Price = BasisConfig.ObjToDecimal(drI["price"].ToString(), BaseConfiguration.PricePlace, 0.00M).ToString();
                        }
                        else
                        {
                            img.Price = "会员可见";
                        }
                        img.Cxbs = drI["cxbs"].ToString().Trim();
                        img.Fabh = drI["fabh"].ToString().Trim();
                        imgList.Add(img);
                    }
                    //LogQueue.Write(LogType.Debug, "FillFloor", $"Type:{lc.Type},len:{imgDr.Length}");
                    //品牌推荐  最少12 不足补位
                    if (lc.Type == "Brand" && imgDr.Length < 12)
                    {
                        imgList = BrandParatope(imgList, entId, web_url, landing, staleDated, 12 - imgDr.Length, userId);
                    }
                    else if (lc.Type == "Weekly" && imgDr.Length < 4)
                    {
                        imgList = GoodsParatope(imgList, entId, web_url, landing, staleDated, 4 - imgDr.Length, jgjb, lc.FloorTitle, userId);
                    }
                    else if ((lc.Type == "Family" || lc.Type == "Product" || lc.Type == "InSeason" || lc.Type == "Health") && imgDr.Length < 7)
                    {
                        imgList = GoodsParatope(imgList, entId, web_url, landing, staleDated, 7 - imgDr.Length, jgjb, lc.FloorTitle, userId);
                    }
                }
                lc.FloorDetail = imgList;
                list.Add(lc);
            }

            return(list);
        }
 public static Designer GetSecondConfiguration(ImgInfo imgInfo)
 {
     var result = new Designer();
     result.Add(new DesignExpression(cl => imgInfo.LincedLaters.Contains(cl.Class)));
     return result;
 }
Beispiel #20
0
        public List <ImgInfo> BrandParatope(List <ImgInfo> imgList, string entId, string webUrl, bool landing, bool staleDated, int len, string userId)
        {
            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@type", "BrandParatope"),
                new SqlParameter("@EntId", entId),
                new SqlParameter("@userId", userId)
            };
            SqlRun         sql    = new SqlRun(SqlRun.sqlstr);
            var            dt     = sql.RunProcedureDR("Proc_GoodsList", param);
            List <ImgInfo> source = new List <ImgInfo>();
            List <ImgInfo> back   = new List <ImgInfo>();

            if (dt.Rows.Count > 0)
            {
                //补位数据
                foreach (DataRow item in dt.Rows)
                {
                    ImgInfo img = new ImgInfo
                    {
                        Entid     = item["entid"].ToString().Trim(),
                        Title     = item["FloorTitle"].ToString().Trim(),
                        ArticleId = item["Article_Id"].ToString().Trim(),
                        SortId    = int.Parse(item["sort_Id"].ToString().Trim()),
                        IsBrand   = item["Is_Brand"].ToString().Trim(),
                        BrandCode = item["BrandCode"].ToString().Trim(),
                        LinkUrl   = item["link_url"].ToString().Trim()
                    };
                    if (item["img_url"].ToString().Trim() != "")
                    {
                        img.ImgUrl = webUrl + item["img_url"].ToString().Trim();
                    }
                    else
                    {
                        img.ImgUrl = "";
                    }
                    if (item["left_pic"].ToString().Trim() != "")
                    {
                        img.LeftPic = webUrl + item["left_pic"].ToString().Trim();
                    }
                    if (item["brand_img_url"].ToString().Trim() != "")
                    {
                        img.BrandImgUrl = webUrl + item["brand_img_url"].ToString().Trim();
                    }
                    else
                    {
                        img.BrandImgUrl = "";
                    }
                    img.SubTitle    = item["sub_title"].ToString().Trim();
                    img.DrugSpec    = item["drug_spec"].ToString().Trim();
                    img.DrugFactory = item["drug_factory"].ToString().Trim();
                    if (landing && !staleDated)
                    {
                        img.Price = BasisConfig.ObjToDecimal(item["price"].ToString(), BaseConfiguration.PricePlace, 0.00M).ToString();
                    }
                    else
                    {
                        img.Price = "会员可见";
                    }
                    img.Cxbs = item["cxbs"].ToString().Trim();
                    img.Fabh = item["fabh"].ToString().Trim();
                    source.Add(img);
                }
                imgList.ForEach(t => back.Add(t));
                //已存在的品牌
                var exist = imgList.Select(t => t.ArticleId).Distinct().ToList();
                //移除已存在的品牌
                source.RemoveAll(t => exist.Contains(t.ArticleId));
                if (source.Count > 0)
                {
                    int    length = source.Count > len ? len : source.Count;
                    Random random = new Random();
                    int    index  = source.Count > len?random.Next(source.Count - len + 1) : 0;

                    source = source.GetRange(index, length);
                    source.ForEach(p => { back.Add(p); });
                }
                if (source.Count < len)
                {
                    var placehold = XmlOperation.ReadXml("Base", "RecommendPicture");
                    for (int i = 0; i < len - source.Count; i++)
                    {
                        ImgInfo imgInfo = new ImgInfo
                        {
                            Entid       = entId,
                            Title       = "品牌推荐",
                            ArticleId   = "",
                            SortId      = 99,
                            IsBrand     = "Y",
                            BrandCode   = "",
                            LinkUrl     = "",
                            ImgUrl      = placehold,
                            LeftPic     = "",
                            BrandImgUrl = placehold,
                            DrugFactory = "",
                            DrugSpec    = "",
                            SubTitle    = "",
                            Price       = "",
                            Cxbs        = "",
                            Fabh        = ""
                        };
                        back.Add(imgInfo);
                    }
                }
            }
            return(back);
        }
Beispiel #21
0
        public List <ImgInfo> GoodsParatope(List <ImgInfo> imgList, string entId, string webUrl, bool landing, bool staleDated, int len, string jgjb, string title, string userId)
        {
            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@type", "GoodsParatope"),
                new SqlParameter("@Jgjb", jgjb),
                new SqlParameter("@EntId", entId),
                new SqlParameter("@userId", userId)
            };
            SqlRun         sql    = new SqlRun(SqlRun.sqlstr);
            var            dt     = sql.RunProcedureDR("Proc_GoodsList", param);
            List <ImgInfo> source = new List <ImgInfo>();
            List <ImgInfo> back   = new List <ImgInfo>();

            //LogQueue.Write(LogType.Debug, "商品count", $"{dt.Rows.Count}");
            if (dt.Rows.Count > 0)
            {
                //补位数据
                foreach (DataRow item in dt.Rows)
                {
                    ImgInfo img = new ImgInfo
                    {
                        Entid     = item["entid"].ToString().Trim(),
                        Title     = title,
                        ArticleId = item["Article_Id"].ToString().Trim(),
                        SortId    = int.Parse(item["sort_Id"].ToString().Trim()),
                        IsBrand   = "N",
                        BrandCode = "",
                        LinkUrl   = item["link_url"].ToString().Trim()
                    };
                    if (item["img_url"].ToString().Trim() != "")
                    {
                        img.ImgUrl = webUrl + item["img_url"].ToString().Trim();
                    }
                    else
                    {
                        img.ImgUrl = "";
                    }
                    if (item["left_pic"].ToString().Trim() != "")
                    {
                        img.LeftPic = webUrl + item["left_pic"].ToString().Trim();
                    }
                    if (item["brand_img_url"].ToString().Trim() != "")
                    {
                        img.BrandImgUrl = webUrl + item["brand_img_url"].ToString().Trim();
                    }
                    else
                    {
                        img.BrandImgUrl = "";
                    }
                    img.SubTitle    = item["sub_title"].ToString().Trim();
                    img.DrugSpec    = item["drug_spec"].ToString().Trim();
                    img.DrugFactory = item["drug_factory"].ToString().Trim();
                    if (landing && !staleDated)
                    {
                        img.Price = BasisConfig.ObjToDecimal(item["price"].ToString(), BaseConfiguration.PricePlace, 0.00M).ToString();
                    }
                    else
                    {
                        img.Price = "会员可见";
                    }
                    img.Cxbs = item["cxbs"].ToString().Trim();
                    img.Fabh = item["fabh"].ToString().Trim();
                    source.Add(img);
                }
                //加入现有商品
                imgList.ForEach(t => back.Add(t));
                //已存在的品牌
                var exist = imgList.Select(t => t.ArticleId).Distinct().ToList();
                //移除已存在的品牌
                source.RemoveAll(t => exist.Contains(t.ArticleId));

                if (source.Count > 0)
                {
                    int    length = source.Count > len ? len : source.Count;
                    Random random = new Random();
                    int    index  = source.Count > len?random.Next(source.Count - len + 1) : 0;

                    source = source.GetRange(index, length);
                    source.ForEach(p => { back.Add(p); });
                }
            }


            return(back);
        }
Beispiel #22
0
        void run()
        {
            TargetPath = txtTargetPath.Text;
            SourcePath = txtSourcePath.Text;
            string str      = txtExcludeFloder.Text;
            int    limitNum = Convert.ToInt32(txtLimitNum.Text);
            var    exclude  = str.Split(';', ';').Where(x => !string.IsNullOrEmpty(x) && x != "undefined").ToList();
            Regex  reg      = new Regex(txtSortReg.Text);

            /* 获取原图路径下的图片
             * 判断是搜索子目录
             * 对得到的图片路径进行正则匹配,将匹配出的序号和路径存入ImgInfo类并添加到列表中去
             */
            var imgPathList = new List <ImgInfo>();
            var tempList    = new List <string>();

            if (checkDeep.Checked)
            {
                tempList = Directory.GetFiles(SourcePath, "*.*", SearchOption.AllDirectories).ToList();
            }
            else
            {
                tempList = Directory.GetFiles(SourcePath, "*.*", SearchOption.TopDirectoryOnly).ToList();
            }
            foreach (var x in tempList)
            {
                long    num = Convert.ToInt64(reg.Match(x).Groups["num"].Value);
                ImgInfo img = new ImgInfo
                {
                    Path = x,
                    Num  = num
                };
                imgPathList.Add(img);
            }
            int count = imgPathList.Count;                          //图片总数

            imgPathList = imgPathList.OrderBy(x => x.Num).ToList(); //按序号大小排序
            int floderCount = 1;                                    //文件夹起始序号
            int imgCount    = 0;                                    //图片起始序号

            for (int i = 0; i < count; i++)
            {
                if (imgCount == limitNum)
                {
                    floderCount++;
                    imgCount = 0;
                }
                imgCount++;
                string   path       = imgPathList[i].Path; //原图路径
                FileInfo file       = new FileInfo(path);
                string   name       = file.Name;
                string   folderPath = TargetPath + "\\" + floderCount;
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                string newImgPath = folderPath + "\\" + name;

                int percent = i * 100 / count;
                proBar.Value = percent + 1;

                if (File.Exists(newImgPath))
                {
                    continue;
                }
                else
                {
                    bool IsMove = true;
                    foreach (var x in exclude)
                    {
                        if (path.Contains(x))
                        {
                            IsMove = false;
                            break;
                        }
                    }
                    if (IsMove)
                    {
                        file.MoveTo(newImgPath);
                    }
                    else
                    {
                        file.CopyTo(newImgPath, false);
                    }
                    rtxtImgList.Text = rtxtImgList.Text.Insert(0, floderCount + @"/" + name + Environment.NewLine);
                }
            }
            picRunning.Visible = false;
        }
Beispiel #23
0
        //static string name = "SOF2";

        public static void Read(BinaryReader reader, ImgInfo imgInfo)
        {
            /*LogMarker(reader, name);
             * Logger.WriteLine("Progressive images are not supported yet");
             * Logger.WriteLine();*/
        }
Beispiel #24
0
 public static void AddBad(ref ImgInfo ret)
 {
     ret.IsOk = false;
     ret.BadCount++;
 }
Beispiel #25
0
 public override String ToString()   // basic info
 {
     return("filename=" + filename + " " + ImgInfo.ToString());
 }
Beispiel #26
0
 /// <summary>
 /// 保存图片 保存按钮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     if (Convert.ToInt32(this._qx) == 1)
     {
         //管理员
         string name     = txtStation_S_Name.Text.Trim();
         string GG       = txtGG.Text.Trim();
         string changjia = txtChangjia.Text.Trim();
         string PH       = txtPH.Text.Trim();
         if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(PH) || string.IsNullOrEmpty(GG) || string.IsNullOrEmpty(changjia) || pictureBox1.Image == null)
         {
             MessageBox.Show("请完善信息!");
         }
         else
         {
             //往服务器上传图片
             string fil = openFileDialog1.FileName;
             if (Convert.ToInt32(isChange.Text) == 0)
             {
                 fil = "111";
             }
             if (this.uploadFileByHttp(Common.GetAppSetingServerIp() + "/Upload.aspx", fil))
             {
                 //往数据库添加数据
                 ImgInfo m = new ImgInfo();
                 m.name     = name;
                 m.beizhu   = "";
                 m.guige    = GG;
                 m.changjia = changjia;
                 m.pihao    = PH;
                 m.url      = strImgs;
                 if (Convert.ToInt32(labId.Text) > 0)
                 {
                     //编辑
                     m.id         = Convert.ToInt32(labId.Text);
                     m.createtime = DateTime.Now;
                     if (imgInfobll.Update(m))
                     {
                         MessageBox.Show("修改成功!");
                         Common.Add("角色:" + _qx, ",修改图片成功" + DateTime.Now);
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("修改失败!");
                     }
                 }
                 else
                 {
                     if (imgInfobll.Add(m))
                     {
                         MessageBox.Show("添加成功!");
                         Common.Add("角色:" + _qx, ",图片添加成功" + DateTime.Now);
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("添加失败!");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("网络异常,图片上传失败!");
             }
         }
     }
     else
     {
         MessageBox.Show("普通用户无权操作!");
     }
 }
Beispiel #27
0
 public static void Read(BinaryReader reader, ImgInfo imgInfo)
 {
     LogMarker(reader, name);
     Logger.WriteLine("Progressive images are not supported yet");
     Logger.WriteLine();
 }
Beispiel #28
0
 internal static void AddBad(ref ImgInfo ret) {
     ret.IsOk = false;
     ret.BadCount++;
 }
Beispiel #29
0
 /// <summary>
 /// 商品查看商品信息修改
 /// </summary>
 /// <param name="Gadmin">商品管理员对象</param>
 /// <param name="goodInfo">商品图片对象</param>
 /// <param name="goodinfo">商品对象</param>
 /// <returns>是否修改成功</returns>
 public bool UpdateGoodinfo(GA Gadmin, ImgInfo goodInfo, Good goodinfo)
 {
     return(Gadmin.UpdateGoodinfo(goodInfo, goodinfo));
 }