Цитата | А какими функциями должна обладать книжка? Может ли у одного контакта быть несколько номеров? И что именно вызывает трудности при создании модели?
|
Нет, несколько номеров не может быть. Трудность вызывает: Есть контекстное меню, веб броузер, и treeView. Каждый из них имеет в порядке фций личных и функций которые пересекаются (Например клик по любому элементу контексного меню пересекается с treeView(запрашивает выделеную ноду и её параметры) и потом шлет запрос в webBrowser на загрузку какойто страницы). Вопрос: Есть ли смысл писать обертки к чемуто и как это делается. Вот резаный листинг моей программы
Код | #region TreeViewContactList scripts;
private void FillTreeRecursive(TreeNodeCollection treeNodes, XmlNode xmlNode) { foreach (XmlElement xmlElement in xmlNode.ChildNodes)// перечисляем узлы XML документа { TreeNode childNode = treeNodes.Add(showXMLdisableChars(xmlElement.Name));// создаём TreeNode для XML-узла FillTreeRecursive(childNode.Nodes, xmlElement);// вызываем метод рекурсивно, чтобы заполнить вложенные узлы } } private void ExpandTreeRecursive(TreeNode treeNode1, int expendLevel) { if (treeNode1.Level < expendLevel) { int treeNodeCount = treeNode1.GetNodeCount(false); if (treeNodeCount > 0) { treeNode1.Expand(); TreeNode ThisChild = treeNode1.FirstNode; for (int i = 0; i < treeNodeCount; i++) { ExpandTreeRecursive(ThisChild, expendLevel); ThisChild = ThisChild.NextNode; } } } } private void treeViewContactList_AfterCheck(object sender, TreeViewEventArgs e) { TreeNode ChNode = e.Node; int NodeChildCount = e.Node.GetNodeCount(false); if (NodeChildCount > 0) { TreeNode ThisChild = ChNode.FirstNode; for (int i = 0; i < NodeChildCount; i++) { ThisChild.Checked = ChNode.Checked; ThisChild = ThisChild.NextNode; } } } private void treeViewContactList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { this.selectedNode = e.Node; }
#endregion
#region ..::WebBrowser::.. //!-- //!--ATENTION! Document complite! ATENTION! //!-- private void webBrowserCommand_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser wb = this.webBrowserCommand; string htmlTitle = wb.DocumentTitle; string htmlText = wb.DocumentText.Substring(40 + htmlTitle.Length); htmlText = showXMLdisableChars(htmlText); switch (htmlTitle) { case "Login": Login(htmlText); break; case "loadKontactList": loadKontactList(hideXMLdisableChars(htmlText)); break; case "addKontact": addKontact(htmlText); break; case "deleteKontact": deleteKontact(htmlText); break; case "addGroup": addGroup(htmlText); break; case "renameGroup": renameGroup(htmlText); break; case "deleteGroup": deleteGroup(htmlText); break; case "autoComplite": wb.Document.All["passw"].SetAttribute("VALUE", this.passw); wb.Document.InvokeScript("formSubmit"); break; default: string st = htmlTitle.Substring(0, 12); if (st == "sentWeb2Mail") { if (sendLabel2) { st = "2"; } else { st = htmlTitle.Substring(12); sendLabel2 = true; } sentWeb2Mail(st); } break; } } //!-- //!--ATENTION! Document complite! ATENTION! //!-- public void Command(string parametrs) {
string output = string.Empty; string name = string.Empty; string comma = string.Empty;// Сдесь мы используем комманду hideXMLdissable int findSep = 0;
// узнаем и удаляем исполняющий файл findSep = parametrs.IndexOf("|"); name = parametrs.Substring(0, findSep); parametrs = parametrs.Substring(findSep + 1);
output += htmlAutoCompliteHead; output += @"<FORM method='POST' name='autoComplite' id='autoComplite' action='" + this.httpURL + name + "'>"; output += @"<input type='text' name='login' value='" + this.login + "'>"; output += @"<input type='password' name='passw'>";
findSep = parametrs.IndexOf("|"); while (findSep != -1) { name = parametrs.Substring(0, findSep); parametrs = parametrs.Substring(findSep + 1); findSep = parametrs.IndexOf("|");
comma = hideXMLdisableChars(parametrs.Substring(0, findSep)); parametrs = parametrs.Substring(findSep + 1);
findSep = parametrs.IndexOf("|");
output += @"<input type='text' name='" + name + "' id='" + name + "' value='" + comma + "'>"; } output += "<input type='submit'>"; output += "</FORM>";
webBrowserCommand.DocumentText = output; } public void WebBrowserOptionsSet(WebBrowser wb) { wb.Visible = true; //wb. wb.AllowWebBrowserDrop = false; // запрет drag and drop на броузер wb.WebBrowserShortcutsEnabled = false; // запрет горячих клавиш wb.IsWebBrowserContextMenuEnabled = true; // запрет правой кнопки } #endregion
#region ..::Context Menu::.. //Open private void contextMenu2Nodes_Opened(object sender, EventArgs e) {
} private void contextMenu2Nodes_Opening(object sender, CancelEventArgs e) { menuItem1.Text = selectedNode.Text + " - "; switch (this.selectedNode.Level) { case 0: menuItem_changeKontact.Visible = false; menuItem_deleteContact.Visible = false; menuItem_drop2group.Visible = false; menuItem_renameGroup.Visible = false; menuItem_deleteGroup.Visible = false; menuItem1.Text=" :: "+selectedNode.GetNodeCount(false) + " групп :: "+ (selectedNode.GetNodeCount(true )-selectedNode.GetNodeCount(false))/5 + " контактов :: "; break; case 1: menuItem1.Text += selectedNode.GetNodeCount(false) + " человек"; menuItem_changeKontact.Visible = false; menuItem_deleteContact.Visible = false; menuItem_drop2group.Visible = false; menuItem_renameGroup.Visible = true ; menuItem_deleteGroup.Visible = true ; break; case 2: string tempStr = selectedNode.FirstNode.NextNode.Text.Substring(2); if (tempStr.Length == 10) menuItem1.Text += "8 (" + tempStr.Substring(0, 3) + ") " + tempStr.Substring(3, 3) + "-" + tempStr.Substring(6, 4); menuItem_changeKontact.Visible = true; menuItem_deleteContact.Visible = true; menuItem_drop2group.Visible = true; menuItem_renameGroup.Visible = false; menuItem_deleteGroup.Visible = false; break; default: e.Cancel = true; break; } } //Click private void menuItem_addGroup_Click(object sender, EventArgs e) { addGroup(); } private void menuItem_deleteGroup_Click(object sender, EventArgs e) { Command("deleteGroup.php|group_name|" + selectedNode.Text + "|"); } private void menuItem_renameGroup_Click(object sender, EventArgs e) { renameGroup(); } private void menuItem_addKontact_Click(object sender, EventArgs e) { addKontact(); } private void menuItem_deleteContact_Click(object sender, EventArgs e) { deleteKontact(); } private void menuItem_changeKontact_Click(object sender, EventArgs e) { changeKontact(); } private void menuItem_myToolStripMenuItemCollectionI_Click(object sender, EventArgs e) { MessageBox.Show("Comming soon..."); } //eventFunction private void addKontact() { string text2view = string.Empty; switch (this.selectedNode.Level) { case 1: text2view = selectedNode.Text; break; case 0: if (selectedNode.GetNodeCount(false) < 1) return; text2view = selectedNode.FirstNode.Text; break; case 2: text2view = selectedNode.Parent.Text; break; default: break; } AddKontact newKontact = new AddKontact(treeViewContactList.Nodes[0],text2view); newKontact.ShowDialog(); if (newKontact.isApplyPressed) { MessageBox.Show("Имя." + newKontact.name + "\nГруппа." + newKontact.group + "\nМоб." + newKontact.phone + "\ne-mail." + newKontact.mail + "\nICQ." + newKontact.ICQ); Command("addKontact.php|name|"+newKontact.name.ToString()+"|phone|"+ newKontact.phone.ToString()+"|mail|"+newKontact.mail.ToString()+"|ICQ|"+ newKontact.ICQ.ToString()+"|group_name|"+newKontact.group.ToString()+"|"); } newKontact.Dispose(); } private void addKontact(string htmlText) { // echo $row['id']+"|$group_name|$name|$phone|$mail|$icq"; string[] kontInfo = new string[6]; int pos; for (int i = 0; i < 6; i++) { pos = htmlText.IndexOf('|'); kontInfo[i] = htmlText.Substring(0, pos); htmlText = htmlText.Substring(pos + 1); }
TreeNode thisNode = treeViewContactList.Nodes[0].FirstNode; for (int i = 0; i < treeViewContactList.Nodes[0].GetNodeCount(false); i++) { if (thisNode.Text == kontInfo[1]) // Является ли Нода нашей Группой. { thisNode.Nodes.Add(kontInfo[2]); // Добавляем в группу новую Ноду if (thisNode.GetNodeCount(false) < 2) thisNode.Expand(); // Если в группе не было элементов - расскрываем группу thisNode = thisNode.LastNode; // Выделяем её thisNode.Nodes.Add("id" + kontInfo[0]); // \/ доп. инфо \/ thisNode.Nodes.Add("ph" + kontInfo[3]); thisNode.Nodes.Add("m" + kontInfo[4]); thisNode.Nodes.Add("ICQ" + kontInfo[5]); // /\ доп. инфо /\ break; } thisNode = thisNode.NextNode; }
} private void changeKontact() { AddKontact newKontact = new AddKontact(treeViewContactList.Nodes[0], selectedNode); newKontact.ShowDialog(); if (newKontact.isApplyPressed) // Если мы вышли из newKontact по Apply { // echo $row['id']+"|$group_name|$name|$phone|$mail|$icq"; string id = selectedNode.FirstNode.Text.Substring(2); selectedNode.Remove(); addKontact(id+"|"+newKontact.group+"|"+newKontact.name+"|"+newKontact.phone+"|"+newKontact.mail+"|"+newKontact.ICQ+"|"); MessageBox.Show("ID"+id+"\nИмя." + newKontact.name + "\nГруппа." + newKontact.group + "\nМоб." + newKontact.phone + "\ne-mail." + newKontact.mail + "\nICQ." + newKontact.ICQ); Command("changeKontact.php|id|"+id+"|name|" + newKontact.name.ToString() + "|phone|" + newKontact.phone.ToString() + "|mail|" + newKontact.mail.ToString() + "|ICQ|" + newKontact.ICQ.ToString() + "|group_name|" + newKontact.group.ToString()+"|"); } newKontact.Dispose(); } private void deleteKontact() { string id = selectedNode.FirstNode.Text.Substring(2); Command("deleteKontact.php|id|" + id + "|"); } private void deleteKontact(string htmlText) { if (htmlText == "true") selectedNode.Remove(); }
private void addGroup() { AddKontact newKontact = new AddKontact(); newKontact.ShowDialog(); if (newKontact.isApplyPressed) { Command("addGroup.php|name|" + newKontact.name + "|"); } } private void addGroup(string htmlText) { if (htmlText != "false") { TreeNode thisTree = treeViewContactList.Nodes[0]; thisTree.Nodes.Add(htmlText); } } private void renameGroup() { AddKontact newKontact = new AddKontact(selectedNode.Text); newKontact.ShowDialog(); if (newKontact.isApplyPressed) { Command("renameGroup.php|name_old|" + selectedNode.Text+"|name_new|" + newKontact.name + "|"); } } private void renameGroup(string HTMLtext) { if (HTMLtext != "false") { selectedNode.Text = HTMLtext; } } private void deleteGroup(string htmlText) { if (htmlText != "false") { selectedNode.Remove(); } } //command-s #endregion
private void loadKontactList() { Command("loadKontactList.php|"); } private void loadKontactList(string XMLtext) { XmlDocument docXML = new XmlDocument(); docXML.LoadXml(XMLtext); FillTreeRecursive(treeViewContactList.Nodes, docXML); // переносим в ViewTree ExpandTreeRecursive(treeViewContactList.Nodes[0], 2); // Открываем ветки selectedNode = treeViewContactList.Nodes[0]; //добавляем группы в контекстное меню addGroupList2Menu(); }
|
|