Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            CustomRowset cr = new CustomRowset(txtRowsetName.Text, rdEnable.Checked, txtIdentifier.Text, cbType.Text);

            if (rdAddRowset.Checked)
            {
                if (CustomRowset.GetAllCustomRowsets().ContainsKey(cr.name))
                {
                    logger.LogMessage(String.Format("rowset name {0} already exists. Use edit to modify this rowset", cr.name), MessageOptions.Dialog);
                    return;
                }
                CustomRowset.Add(cr);
            }
            else if (rdEditRowset.Checked)
            {
                CustomRowset.Save(cbSelectRowset.Text, cr);
            }
            else if (rdDelete.Checked)
            {
                if (cbSelectRowset.Text.Trim().Length == 0)
                {
                    logger.LogMessage(String.Format("The rowset list is either empty or you haven't chosen anything to delete yet. try again", cr.name), MessageOptions.Dialog);
                    return;
                }
                CustomRowset.Delete(cbSelectRowset.Text);
            }

            if (CustomRowset.GetAllCustomRowsets().Count == 0)
            {
                rdAddRowset.Checked = true;
            }
            PopulateRowset(null);
            Application.DoEvents();
            this.Refresh();
        }
Ejemplo n.º 2
0
        void PopulateRowset(String DefaultItem)
        {
            cbSelectRowset.Items.Clear();
            SortedDictionary <string, CustomRowset> cr = CustomRowset.GetAllCustomRowsets();

            if (cr.Count == 0)
            {
                cbSelectRowset.Text = "";
                cbSelectRowset.Refresh();
                Application.DoEvents();
                return;
            }

            foreach (String key in cr.Keys)
            {
                cbSelectRowset.Items.Add(key);
            }

            if (null == DefaultItem)
            {
                cbSelectRowset.SelectedIndex = 0;
            }
            else
            {
                cbSelectRowset.SelectedItem = DefaultItem;
            }

            cbSelectRowset.Refresh();
            Application.DoEvents();
        }
Ejemplo n.º 3
0
        static void ReplaceOrAppend(String OldName, CustomRowset cRowset, Operation op)
        {
            XmlElement el = m_Doc.CreateElement("Rowset");

            if (!(op == Operation.Delete))
            {
                el.SetAttribute("name", cRowset.name);
                el.SetAttribute("enabled", cRowset.enabled.ToString());
                el.SetAttribute("identifier", cRowset.identifier);
                el.SetAttribute("type", cRowset.type);
            }
            String xPath = String.Format("TextImport/KnownRowsets/Rowset[@name='{0}']", (null == OldName? cRowset.name:OldName));
            int    ExistingRowsetCountByThisName = m_Doc.SelectNodes(xPath).Count;

            //add
            if (OldName == null)
            {
                if (ExistingRowsetCountByThisName > 0)
                {
                    throw new ArgumentException(string.Format(Properties.Resources.Error_CustomRowset_AlreadyExists, cRowset.name, xmlFileName));
                }
                XmlNode nodeKnownRowsets = m_Doc.SelectSingleNode("TextImport/KnownRowsets");
                nodeKnownRowsets.AppendChild(el);
            }
            else
            {
                if (ExistingRowsetCountByThisName > 1)
                {
                    throw new ArgumentException(String.Format(Properties.Resources.Error_CustomRowset_NotExists, OldName, xmlFileName));
                }
                XmlNode node = m_Doc.SelectSingleNode(String.Format("TextImport/KnownRowsets/Rowset[@name='{0}']", OldName));
                if (node.HasChildNodes)
                {
                    throw new ArgumentException(String.Format("the rowset {0} in {1} has know column types.  Current UI doesn't handle this. Please continue to modify the xml document manually", OldName, xmlFileName));
                }
                if (node != null) //silently fail if it doesn't exist in xmldoc
                {
                    if (op == Operation.Edit)
                    {
                        node.ParentNode.ReplaceChild(el, node);
                    }
                    else if (op == Operation.Delete)
                    {
                        node.ParentNode.RemoveChild(node);
                    }
                }
            }
            m_Doc.Save(xmlFileName);
        }
Ejemplo n.º 4
0
 private void fmCustomRowset_Load(object sender, EventArgs e)
 {
     if (!File.Exists(CustomXmlFile))
     {
         if (!Directory.Exists(Globals.AppDataPath))
         {
             Directory.CreateDirectory(Globals.AppDataPath);
         }
         File.Copy(Globals.StartupPath + @"\TextRowsetsCustom_Template.xml", CustomXmlFile);
     }
     CustomRowset.Init(CustomXmlFile);
     rdAddRowset.Checked = true;
     InitConrols(Operation.Add);
     Application.DoEvents();
 }
Ejemplo n.º 5
0
        private void cbSelectRowset_SelectedIndexChanged(object sender, EventArgs e)
        {
            CustomRowset cr = CustomRowset.GetRowsetByName(cbSelectRowset.Text);

            txtIdentifier.Text = cr.identifier;
            txtRowsetName.Text = cr.name;
            if (cr.enabled)
            {
                rdEnable.Checked = true;
            }
            else
            {
                rdDisable.Checked = true;
            }
            PopulateType(cr.type);


            Application.DoEvents();
        }
Ejemplo n.º 6
0
 public static void Add(CustomRowset cr)
 {
     ReplaceOrAppend(null, cr, Operation.Add);
 }
Ejemplo n.º 7
0
 public static void Save(String OldName, CustomRowset cr)
 {
     ReplaceOrAppend(OldName, cr, Operation.Edit);
 }