Пример #1
0
        private void ToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            switch (e.Button.Tag as string)
            {
            case "save":

                try
                {
                    string provider = ProviderComboBox.SelectedItem.ToString();

                    // First Lets Remove the current node for this entire database
                    XmlNode node = settings.SelectSingleNode(string.Format("Languages/Language[@From='{0}']", provider));
                    node.ParentNode.RemoveChild(node);

                    // Grab the parent node of the entire xml file
                    XmlNode parentNode = settings.SelectSingleNode(@"//Languages");

                    // Create our new Language Node entry for this database
                    XmlNode langNode = settings.CreateNode(XmlNodeType.Element, "Language", null);
                    parentNode.AppendChild(langNode);

                    // Fill in it's To/From Attributes
                    XmlAttribute attr = settings.CreateAttribute("From");
                    attr.Value = provider;
                    langNode.Attributes.Append(attr);

                    attr       = settings.CreateAttribute("To");
                    attr.Value = "C#";
                    langNode.Attributes.Append(attr);

                    // Lets sort them in order of the database column type
                    DataTable dt = (DataTable)MappingsDataGridView.DataSource;
                    dt.DefaultView.Sort = "Database ASC";

                    // Now let's add all of the mappings
                    foreach (DataRowView row in dt.DefaultView)
                    {
                        XmlNode typeNode = settings.CreateNode(XmlNodeType.Element, "Type", null);
                        langNode.AppendChild(typeNode);

                        attr       = settings.CreateAttribute("From");
                        attr.Value = (string)row.Row["Database"];
                        typeNode.Attributes.Append(attr);

                        attr       = settings.CreateAttribute("To");
                        attr.Value = (string)row.Row[".NET"];
                        typeNode.Attributes.Append(attr);
                    }

                    settings.Save(this.Settings.LanguageMappingFile);
                }
                catch (Exception ex)
                {
                    this.MainWindow.ShowError(ex);
                }
                break;
            }
        }
Пример #2
0
        private void CreateKey(ref XmlDataDocument xmlDoc, ref XmlNode xmlNodeSection, string name, string sValue)
        {
            XmlNode newNodeKey = xmlDoc.CreateNode(XmlNodeType.Element, name, string.Empty);

            newNodeKey.InnerText = sValue;
            xmlNodeSection.AppendChild(newNodeKey);
        }
Пример #3
0
        private static void AddNode(string sUid, string sPwd, bool RememberMe)
        {
            bool            isAdd    = true;
            XmlDataDocument UserDate = new XmlDataDocument();

            UserDate.Load(QQuser);
            XmlNode root = UserDate.SelectSingleNode("root");

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                if (root.ChildNodes[i].Attributes["user"].Value.Trim() == sUid)
                {
                    //更新用户消息
                    if (RememberMe)
                    {
                        root.ChildNodes[i].ChildNodes[0].InnerText = sPwd;
                    }
                    else
                    {
                        root.ChildNodes[i].ChildNodes[0].InnerText = "";
                    }
                    UserDate.Save(QQuser);
                    isAdd = false;
                    break;
                }
            }
            if (isAdd)
            {
                XmlNode    NodeAtt = UserDate.CreateNode(XmlNodeType.Attribute, "user", null);
                XmlElement user    = UserDate.CreateElement("user");
                XmlElement pwd     = UserDate.CreateElement("pwd");
                user.Attributes.SetNamedItem(NodeAtt);
                user.Attributes["user"].Value = sUid;
                if (RememberMe)
                {
                    pwd.InnerText = sPwd;
                }
                else
                {
                    pwd.InnerText = "";
                }
                user.AppendChild(pwd);
                root.AppendChild(user);
                UserDate.Save(QQuser);
            }
        }
Пример #4
0
        private void SetValuePathQuery(string inKey, string[] Value)
        {
            // проверить существует ли запись, прежде чем что-либо делать
            if (xmlDataDoc == null)
            {
                xmlDataDoc = new XmlDataDocument(mDataSet);
            }

            mDataSet.EnforceConstraints = false;
            XmlNode nodRecord = xmlDataDoc.SelectSingleNode($"/{DATA_SET_COMMAND}/{Clobal.TableCommand}[Key={inKey.ToUpper().Trim()}]");

            if (nodRecord == null)
            {
                // запись не найдена, значить добавить строку
                string  strXpathQueryRoot = "/" + DATA_SET_COMMAND;
                XmlNode nodRoot           = xmlDataDoc.SelectSingleNode(strXpathQueryRoot);

                if (nodRoot != null)
                {
                    //<appSettings>
                    //  <Key>1</Key>
                    //  <Value>1</Value>
                    //  <Type>String</Type>
                    //</appSettings>
                    XmlNode nodChild = xmlDataDoc.CreateNode(XmlNodeType.Element, Clobal.TableCommand, string.Empty);
                    CreateKey(ref xmlDataDoc, ref nodChild, COMMAND_KEY, inKey.ToUpper().Trim());
                    CreateKey(ref xmlDataDoc, ref nodChild, COMMAND_VALUE, Value[0]);
                    CreateKey(ref xmlDataDoc, ref nodChild, COMMAND_TYPE, Value[1]);
                    nodRoot.AppendChild(nodChild);
                }
                else
                {
                    throw new Exception(RootIsNotExist);
                }
            }
            else
            {
                // запись найдена, обновить новыми значениями
                nodRecord.ChildNodes[0].InnerText = inKey.ToUpper().Trim();
                nodRecord.ChildNodes[1].InnerText = Value[0];
                nodRecord.ChildNodes[2].InnerText = Value[1];
            }
            mDataSet.EnforceConstraints = true;
        }