예제 #1
0
        private void load_Data()
        {
            view.Clear();
            int countCell = _listItems.Select(x => x.Length).Max();

            view.Columns.Add(new ColumnHeader {
                Text = "", Width = 40
            });
            for (int i = 1; i < countCell; i++)
            {
                _indexField.Add(i, "");
                view.Columns.Add(new ColumnHeader {
                    Text = "Column " + i.ToString(), Width = 125
                });
                ComboBox com = new ComboBox()
                {
                    Tag           = i,
                    Left          = (i - 1) * 125 + 40,
                    Top           = 7,
                    Width         = 125,
                    DropDownStyle = ComboBoxStyle.DropDownList,
                };
                com.SelectedIndexChanged += (se, ev) =>
                {
                    ComboBox si     = (ComboBox)se;
                    int      column = (int)si.Tag;
                    string   field  = _fields[si.SelectedIndex == 0 ? 0 : si.SelectedIndex - 1];
                    _indexField[column] = field;
                    switch (field)
                    {
                    case _Word:
                        _indexWord = column;
                        break;

                    case _Meaning:
                        _indexMeaning = column;
                        break;
                    }
                };
                com.Items.Add("");
                com.Items.AddRange(_fields);
                boxHeader.Controls.Add(com);
                if (countCell == 3)
                {
                    if (i == 1)
                    {
                        com.SelectedIndex = 1;
                    }
                    else if (i == 2)
                    {
                        com.SelectedIndex = 4;
                    }
                }
                else if (i <= 3)
                {
                    com.SelectedIndex = i;
                }
            }

            int k = 1;

            foreach (string[] it in _listItems)
            {
                if (it.Length < 3)
                {
                    continue;
                }
                bool chk = false;
                if (it[2][0] == '/')
                {
                    chk = true;
                }
                it[1] = DataExtract.format_Word(it[1]);
                view.Items.Add(new ListViewItem(it)
                {
                    Checked = chk
                });
                if (k % 2 == 0)
                {
                    view.Items[k - 1].BackColor = SystemColors.ControlLight;
                }
                k++;
            } //end for line
        }     // end function
예제 #2
0
        }//end function

        private void format_Items()
        {
            var lsField = _indexField.Values.ToList();

            if (lsField.IndexOf(_Word) == -1 || lsField.IndexOf(_Meaning) == -1)
            {
                MessageBox.Show(string.Format("Please choose config column [{0}] and [{1}]", _Word, _Meaning));
                return;
            }

            int countCell = _listItems.Select(x => x.Length).Max();
            int colMiss   = countCell - _indexField.Count;

            if (colMiss > 1)
            {
                if (MessageBox.Show("Has " + colMiss.ToString() + " column not config, Are you will submit?", "Are you sure ?",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation,
                                    MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            int index = 0;

            _listWord.Clear();
            _listExam.Clear();

            #region
            foreach (string[] it in _listItems)
            {
                string word           = DataExtract.format_Word(it[_indexWord]),
                              meaning = DataExtract.format_Meaning(it[_indexMeaning]);

                ELWORD o = new ELWORD()
                {
                    WORD = word, MEANING = meaning
                };
                ELEXAMPLE xam = null;

                foreach (var kv in _indexField)
                {
                    switch (kv.Value)
                    {
                    case "Pronounce":
                        o.PRONOUNCE = it[kv.Key];
                        break;

                    case "Type":
                        o.TYPE = (byte)DataExtract.fomart_Type(it[kv.Key]);
                        break;

                    case "Example":
                        if (xam == null)
                        {
                            xam = new ELEXAMPLE()
                            {
                                WORD = word
                            }
                        }
                        ;
                        xam.EXAMPLE = it[kv.Key];
                        break;

                    case "Example_Meaning":
                        if (xam == null)
                        {
                            xam = new ELEXAMPLE()
                            {
                                WORD = word
                            }
                        }
                        ;
                        xam.MEANING = it[kv.Key];
                        break;
                    }
                }
                _listWord.Add(o);
                if (xam != null)
                {
                    _listExam.Add(xam);
                }
                index++;
            }
            #endregion
        }
예제 #3
0
        void boxMain_DragDrop(object sender, DragEventArgs e)
        {
            string htm = null;

            #region [ === GET DATA FROM DROP DRAP === ]

            //use the underlying IDataObject to get the FileGroupDescriptorW as a MemoryStream
            MemoryStream dataFormatStream = (MemoryStream)e.Data.GetData("text/html");
            byte[]       dataFormatBytes  = new byte[dataFormatStream.Length];
            dataFormatStream.Read(dataFormatBytes, 0, dataFormatBytes.Length);
            dataFormatStream.Close();

            //if (dataFormatBytes[1] == 0)
            //    htm = Encoding.Unicode.GetString(dataFormatBytes);
            //else
            //    htm = Encoding.ASCII.GetString(dataFormatBytes);
            htm = Encoding.UTF8.GetString(dataFormatBytes);

            #endregion


            List <string> listMp3 = new List <string>();
            var           ps2     = Regex.Matches(htm, "http(.+?)mp3", RegexOptions.IgnoreCase);
            foreach (Match mi in ps2)
            {
                string img = mi.ToString();
                listMp3.Add(img);
            }

            if (radWORD.Checked)
            {
                #region
                List <string[]> li = new List <string[]>()
                {
                };
                if (htm.Contains("<table"))
                {
                    li = DataExtract.format_TableHTML(htm);
                }
                else
                {
                    li = DataExtract.format_TextHtml(htm);
                }
                new FormELWordAdd(li, listMp3.ToArray()).Show();
                #endregion
            }
            else if (radGRAM.Checked)
            {
                string text = DataExtract.format_TextPlain(htm);
                new FormELGramAdd(text, listMp3.ToArray()).Show();
            }
            else
            {
                #region
                var ps = Regex.Matches(htm, "<img.+?src=[\"'](.+?)[\"'].*?", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (Match mi in ps)
                {
                    string img = mi.ToString(), src = mi.Groups[1].Value;
                    //string id = " " + Guid.NewGuid().ToString() + " ";
                    string id = " {img" + src + "img} ";

                    int p = htm.IndexOf(img);
                    if (p > 0)
                    {
                        string s0 = htm.Substring(0, p),
                               s1 = htm.Substring(p + img.Length, htm.Length - (p + img.Length));
                        int pend  = s1.IndexOf(">");
                        if (pend != -1)
                        {
                            s1 = s1.Substring(pend + 1);
                        }
                        htm = s0 + id + s1;
                    }
                    //htm = htm.Replace(img, id);
                }
                string text = DataExtract.format_TextPlain(htm);

                //List<string> listImg = new List<string>();
                //var ps2 = Regex.Matches(text, "{img(.+?)img}", RegexOptions.IgnoreCase);
                //foreach (Match mi in ps2)
                //{
                //    string img = mi.ToString();
                //    listImg.Add(img);
                //}
                new FormELDocAdd("", text, listMp3.ToArray()).Show();
                #endregion
            }
        }