예제 #1
0
        private void txtFind_TextChanged(object sender, EventArgs e)
        {
            string find = ((TextBox)sender).Text;


            List <ListViewItem> dataSource = allItems;

            //https://devblogs.microsoft.com/pfxteam/
            if (!string.IsNullOrEmpty(find))
            {
                dataSource = allItems.AsParallel()
                             /*.Where(item => !string.IsNullOrEmpty(item.SubItems[1].Text))*/.Where(item => item.SubItems[1].Text.Contains(find)).ToList();
                dataSource.ForEach(item => {
                    var subItems = item.SubItems;
                    var key      = MySqlHexDecimalEncoding.hex(item.SubItems[1].Text);
                    if (chkMultiKey.Checked)
                    {
                        item.Checked = (h_multiKey.ContainsValue(key)); //如果是多键不同值,存在这个key就选中
                    }
                    else
                    {
                        item.Checked = replacement.Contains(key); //多键同值,存在这个key就选中
                    }
                    Console.WriteLine("{0}", subItems[0].GetType());
                });

                toolTips.Text = string.Format("共命中{0}条记录!", dataSource.Count);
            }
            else
            {
                toolTips.Text = string.Format("共{0}条记录!", dataSource.Count);
            }

            this.lstFieldStat.BeginUpdate();
            lstFieldStat.Items.Clear();
            lstFieldStat.Items.AddRange(dataSource.ToArray());
            this.lstFieldStat.EndUpdate();
        }
예제 #2
0
        private void frmFieldStat_Closed(object sender, EventArgs e)
        {
            HashSet <string> replacement = ((frmFieldStat)sender).replacement; //待批量替换成 replaceTo的数据

            string replaceTo = ((frmFieldStat)sender).txtReplaceTo.Text;       //替换目标

            Hashtable h_multiKey = ((frmFieldStat)sender).h_multiKey;          //待替换的键值对

            bool isMultiKey = ((frmFieldStat)sender).chkMultiKey.Checked;      //是否为多键值对替换

            StringBuilder builder = new StringBuilder();

            List <Payload> ltPayLoads = new List <Payload>();

            if (!isMultiKey)
            {
                foreach (string item in replacement)
                {
                    bool isNull = string.IsNullOrEmpty(replaceTo);
                    //如果发现hex或者unhex以后的字符串和待替换的一直,则放弃
                    bool shouldIngoreReplacement = (!isNull) && (MySqlHexDecimalEncoding.hex(item).Equals(replaceTo) || MySqlHexDecimalEncoding.unhex(item).Equals(replaceTo));
                    if (shouldIngoreReplacement)
                    {
                        continue;
                    }

                    if (isNull)
                    {
                        Payload customPayload = new Payload("invalid to null", item, null)
                        {
                            Rules = "full"
                        };
                        ltPayLoads.Add(customPayload);
                    }
                    else
                    {
                        string  hex           = MySqlHexDecimalEncoding.hex(replaceTo);
                        Payload customPayload = new Payload("replace", item, hex)
                        {
                            Rules = "full"
                        };
                        ltPayLoads.Add(customPayload);
                    }
                }
            }
            else
            {
                foreach (object key in h_multiKey.Keys)
                {
                    string targetKey   = (string)key;
                    string targetValue = (string)h_multiKey[key];

                    //如果发现hex或者unhex以后的字符串和待替换的一直,则放弃
                    bool shouldIngoreReplacement = MySqlHexDecimalEncoding.unhex(targetValue).Equals(targetKey);
                    if (shouldIngoreReplacement)
                    {
                        continue;
                    }

                    Payload customPayload = new Payload("replace", targetKey, targetValue)
                    {
                        Rules = "full"
                    };
                    builder.Append(targetKey);
                    builder.Append("->");
                    builder.Append(targetValue);
                    builder.Append("\n");
                    ltPayLoads.Add(customPayload);
                }
            }

            if (!string.IsNullOrEmpty(selectedColumn) && ltPayLoads.Count > 0)
            {
                DialogResult result = DialogResult.None;

                //普通替换
                if (!isMultiKey)
                {
                    result = MessageBox.Show(string.Concat("即将执行以下替换:\n", string.Join(",", replacement), "\n替换成:", replaceTo), "数据更新提醒",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
                else
                {
                    result = MessageBox.Show(string.Concat("即将执行多键值对替换\n", builder), "数据更新提醒",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }


                if (result == DialogResult.Yes)
                {
                    scheduler.Run(schema, table, Payload.Instance.BuildSqls(schema, table, selectedColumn, ltPayLoads));
                }
            }
        }