public static int TargetProcessesCount(int id)
        {
            int count = 0;
            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt = wrapper.ReadDatatable("SELECT * FROM tradeskill WHERE ID2 = " + id + ";");
            DataRowCollection drc = dt.Rows;
            count += drc.Count;
            wrapper.Dispose();

            return count;
        }
        public Tradeskill(Client client, int srcLocation, int targetLocation)
        {
            this.client = client;
            this.sourcePlacement = srcLocation;
            this.targetPlacement = targetLocation;
            this.source = this.client.Character.GetInventoryAt(srcLocation).Item;
            this.target = this.client.Character.GetInventoryAt(targetLocation).Item;

            this.SourceID = this.source.HighID;
            this.TargetID = this.target.HighID;

            this.IsTradeSkill = false;

            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt =
                wrapper.ReadDatatable(
                    "SELECT * FROM tradeskill WHERE ID1 = " + this.source.HighID + " AND ID2 = " + this.target.HighID
                    + ";");
            wrapper.Dispose();
            DataRowCollection drc = dt.Rows;

            if (drc.Count > 0)
            {
                this.IsTradeSkill = true;

                this.sourceName = GetItemName(this.source.LowID, this.source.HighID, this.source.Quality);
                this.targetName = GetItemName(this.target.LowID, this.target.HighID, this.target.Quality);

                this.TargetMinQL = (int)drc[0][2];

                List<int> itemids = new List<int>();

                string[] ItemIDS = ((string)drc[0][3]).Split(',');
                foreach (string id in ItemIDS)
                {
                    itemids.Add(Convert.ToInt32(id.Trim()));
                }

                for (int i = 0; i < itemids.Count / 2; i++)
                {
                    int lowid = itemids.ElementAt(i * 2);
                    int highid = itemids.ElementAt(i * 2 + 1);
                    int lowql = ItemHandler.interpolate(lowid, highid, 1).Quality;
                    int highql = ItemHandler.interpolate(lowid, highid, 300).Quality;
                    this.resultProperties.Add(new TradeSkillResultInfo(lowql, highql, lowid, highid));
                }

                this.rangePercent = (int)drc[0][4];
                this.deleteFlag = (int)drc[0][5];
                string skill = (string)drc[0][6];
                string skillpercent = (string)drc[0][7];
                string skillperbump = (string)drc[0][8];
                this.maxBump = (int)drc[0][9];
                this.minXP = (int)drc[0][10];
                this.maxXP = (int)drc[0][11];
                int isImplant = (int)drc[0][12];

                this.isDeleteSource = ((this.deleteFlag & 1) == 1);
                this.isDeleteTarget = (((this.deleteFlag >> 1) & 1) == 1);

                string[] skills = skill.Split(',');
                string[] skillpercents = skillpercent.Split(',');
                string[] skillperbumps = skillperbump.Split(',');

                this.Skills = new List<TradeSkillSkillInfo>();

                if (skills[0] != string.Empty)
                {
                    for (int i = 0; i < skills.Count(); ++i)
                    {
                        if (skills[0].Trim() != string.Empty)
                        {
                            this.Skills.Add(
                                new TradeSkillSkillInfo(
                                    Convert.ToInt32(skills[i]),
                                    Convert.ToInt32(skillpercents[i]),
                                    Convert.ToInt32(skillperbumps[i]),
                                    this.client.Character.Stats.GetStatbyNumber(Convert.ToInt32(skills[i])).Value,
                                    (int)Math.Ceiling(Convert.ToInt32(skillpercents[i]) / 100M * this.target.Quality),
                                    StatsList.GetStatName(Convert.ToInt32(skills[i]))));
                        }
                    }
                }

                int leastBump = 0;

                if (isImplant > 0)
                {
                    if (this.target.Quality >= 250)
                    {
                        this.maxBump = 5;
                    }
                    else if (this.target.Quality >= 201)
                    {
                        this.maxBump = 4;
                    }
                    else if (this.target.Quality >= 150)
                    {
                        this.maxBump = 3;
                    }
                    else if (this.target.Quality >= 100)
                    {
                        this.maxBump = 2;
                    }
                    else if (this.target.Quality >= 50)
                    {
                        this.maxBump = 1;
                    }
                    else
                    {
                        this.maxBump = 0;
                    }
                }

                foreach (TradeSkillSkillInfo skillinfo in this.Skills)
                {
                    if (skillinfo.PerBump != 0)
                    {
                        leastBump = Math.Min(
                            (skillinfo.Value - skillinfo.Requirement) / skillinfo.PerBump, this.maxBump);
                    }
                }

                this.MinQL = this.target.Quality;
                this.MaxQL = Math.Min(
                    this.target.Quality + leastBump,
                    ItemHandler.interpolate(
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).LowID,
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).HighID,
                        300).Quality);

                this.Quality = this.MaxQL;

                this.SetResultIDS(this.Quality);
                this.resultName = GetItemName(this.ResultLowId, this.ResultHighId, this.Quality);
            }
        }