Example #1
0
        /// <summary>
        /// Copy variables
        /// </summary>
        /// <param name="list">variable list</param>
        /// <param name="po">printer object</param>
        /// <returns>if at least one item removed</returns>
        public static bool CopyVariables(ListBox list, PrinterObject po)
        {
            bool atLeastOne = false;

            for (int index = 0; index < list.SelectedIndices.Count; ++index)
            {
                PrinterVariable pv     = list.SelectedItems[index] as PrinterVariable;
                PrinterVariable copied = new PrinterVariable();
                copied.Name  = "Copy of " + pv.Name;
                copied.Value = pv.Value;
                if (po.ExistTestVariable(copied.Name))
                {
                    po.EditVariable(copied.Name, copied.Value);
                    for (int counter = 0; counter < list.Items.Count; ++counter)
                    {
                        if ((list.Items[counter] as PrinterVariable).Name == copied.Name)
                        {
                            list.Items.RemoveAt(counter);
                            list.Items.Insert(counter, copied);
                            break;
                        }
                    }
                }
                else
                {
                    po.AddVariable(copied.Name, copied.Value);
                    list.Items.Add(copied);
                }
                hasModified = true;
                atLeastOne  = true;
            }
            list.Refresh();
            return(atLeastOne);
        }
Example #2
0
 /// <summary>
 /// Cast a printer object (base class)
 /// to a Accu object
 /// </summary>
 /// <param name="pv">printer variable</param>
 private void Cast(PrinterVariable pv)
 {
     for (int index = 0; index < pv.Values.Count(); ++index)
     {
         PrinterVariable sub = pv.Values.ElementAt(index);
         this.IncludedVariables.Add(sub.Name, new AccuChild(sub));
     }
 }
Example #3
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="pv">source</param>
 public AccuChild(PrinterVariable pv)
 {
     this.Name    = pv.Name;
     this.Include = pv.Include;
     this.Indent  = pv.Indent;
     this.Value   = pv.Value;
     this.Cast(pv);
 }
Example #4
0
 /// <summary>
 /// Cast a printer object (base class)
 /// to a Accu object
 /// </summary>
 /// <param name="po">printer object</param>
 private void Cast(PrinterObject po)
 {
     for (int index = 0; index < po.Values.Count(); ++index)
     {
         PrinterVariable pv = po.Values.ElementAt(index);
         this.Variables.Add(pv.Name, new AccuChild(pv));
     }
     this.Strings.AddRange(po.Datas);
 }
Example #5
0
 /// <summary>
 /// Add a variable
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="obj">object value</param>
 public new void AddVariable(string key, PrinterVariable obj)
 {
     if (this.Variables.ContainsKey(key))
     {
         this.Variables[key] = obj.Clone() as AccuChild;
     }
     else
     {
         this.Variables.Add(key, obj.Clone() as AccuChild);
     }
 }
Example #6
0
 /// <summary>
 /// Fill all variable in list box
 /// </summary>
 /// <param name="list">variable list</param>
 /// <param name="pv">printer variable</param>
 public static void FillVars(ListBox list, PrinterVariable pv)
 {
     foreach (PrinterVariable inpv in pv.Values)
     {
         list.Items.Add(inpv);
     }
     list.DisplayMember = "Name";
     list.ValueMember   = "Value";
     if (pv.Values.Count() > 0)
     {
         list.SetSelected(0, true);
     }
 }
Example #7
0
        /// <summary>
        /// Delete variables
        /// </summary>
        /// <param name="list">variable list</param>
        /// <param name="po">variable object</param>
        /// <returns>if at least one item removed</returns>
        public static bool DeleteVariables(ListBox list, PrinterVariable po)
        {
            bool atLeastOne = false;

            for (int index = list.SelectedIndices.Count - 1; index >= 0; --index)
            {
                PrinterVariable pv  = list.SelectedItems[index] as PrinterVariable;
                int             pos = list.SelectedIndices[index];
                po.DeleteVariable(pv.Name);
                list.Items.RemoveAt(pos);
                hasModified = true;
                atLeastOne  = true;
            }
            list.Refresh();
            return(atLeastOne);
        }
Example #8
0
 /// <summary>
 /// Edit a variable
 /// </summary>
 /// <param name="list">variable list</param>
 /// <param name="po">printer object</param>
 /// <returns>added variable</returns>
 public static bool EditVariable(ListBox list, PrinterObject po)
 {
     if (list.SelectedIndices.Count == 1)
     {
         PrinterVariable pv  = list.SelectedItems[0] as PrinterVariable;
         Variable        var = new Variable();
         var.IsIndented = pv.Indent;
         var.Controls["txtName"].Text = pv.Name;
         if (pv.Include)
         {
             (var.IncludePage.Controls["rbInclude"] as RadioButton).Checked = true;
             var.IncludePage.Controls["txtFile"].Text = pv.Value;
             FillVars(var.IncludePage.Controls["vars"] as ListBox, pv);
             var.IncludePage.Controls["txtSource"].Text = pv.ToString();
         }
         else
         {
             (var.ValuePage.Controls["rbValue"] as RadioButton).Checked = true;
             var.ValuePage.Controls["txtValue"].Text = pv.Value;
         }
         DialogResult dr = var.ShowDialog();
         if (dr == DialogResult.OK)
         {
             if (!String.IsNullOrEmpty(pv.Name) && pv.Name != var.Controls["txtName"].Text)
             {
                 po.DeleteVariable(pv.Name);
                 list.Items.RemoveAt(list.SelectedIndices[0]);
             }
             pv.Indent  = var.IsIndented;
             pv.Include = (var.IncludePage.Controls["rbInclude"] as RadioButton).Checked;
             if (pv.Include)
             {
                 pv.Value = var.IncludePage.Controls["txtFile"].Text;
                 foreach (PrinterVariable subpv in (var.IncludePage.Controls["vars"] as ListBox).Items)
                 {
                     pv.AddVariable(subpv.Name, subpv);
                 }
             }
             else
             {
                 pv.Value = var.ValuePage.Controls["txtValue"].Text;
             }
             pv.Name = var.Controls["txtName"].Text;
             if (po.ExistTestVariable(pv.Name))
             {
                 po.EditVariable(pv.Name, pv);
                 for (int index = 0; index < list.Items.Count; ++index)
                 {
                     if ((list.Items[index] as PrinterVariable).Name == pv.Name)
                     {
                         list.Items.RemoveAt(index);
                         list.Items.Insert(index, pv);
                         list.SelectedIndices.Add(index);
                         break;
                     }
                 }
             }
             else
             {
                 po.AddVariable(pv.Name, pv);
                 int pos = list.Items.Add(pv);
                 list.SelectedIndices.Add(pos);
             }
             list.Refresh();
             hasModified = true;
             return(true);
         }
         return(false);
     }
     return(false);
 }
Example #9
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public Variable()
 {
     InitializeComponent();
     this.ofd = new OpenFileDialog();
     this.pv  = new PrinterVariable();
 }