void chk_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox      chk = (CheckBox)sender;
            EntryTemplate t   = (EntryTemplate)chk.Tag;

            et_to_secure_edit[t].EnableProtection(chk.Checked);
        }
Пример #2
0
        void chk_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox      chk   = (CheckBox)sender;
            EntryTemplate t     = (EntryTemplate)chk.Tag;
            var           sedit = et_to_secure_edit[t];

            sedit.EnableProtection(chk.Checked);
            if (sedit == current_password_field && current_password_confirm_field != null)
            {
                if (chk.Checked)
                {
                    current_password_confirm_field.TextEx = sedit.TextEx;
                }
                current_password_confirm_field.Enabled = chk.Checked;
                current_password_confirm_field.EnableProtection(chk.Checked);
            }
        }
Пример #3
0
        void btn_popout_Click(object sender, EventArgs e)
        {
            Button        btn = (Button)sender;
            EntryTemplate t   = (EntryTemplate)btn.Tag;

            if (form.EntryStrings.Get(t.fieldName) == null)
            {
                form.EntryStrings.Set(t.fieldName, new ProtectedString(t.type.StartsWith("Protected"), ""));
            }

            ProtectedString psValue = form.EntryStrings.Get(t.fieldName);

            Debug.Assert(psValue != null);
            EditStringForm esf = new EditStringForm();

            esf.InitEx(form.EntryStrings, t.fieldName, psValue, m_host.Database);
            if (esf.ShowDialog() == DialogResult.OK)
            {
                form.UpdateEntryStrings(false, true);
            }
        }
Пример #4
0
 private void init_child_vals()
 {
     foreach (KeyValuePair <EntryTemplate, Control> pair in et_to_control)
     {
         if (pair.Value == null)
         {
             continue;
         }
         EntryTemplate t        = pair.Key;
         String        get_name = t.fieldName;
         if (t.fieldName == "@confirm")
         {
             get_name = PwDefs.PasswordField;
         }
         ProtectedString str = null;
         if (t.fieldName == "@override")
         {
             get_name = "";
             find_override_url_control(form);
             Debug.Assert(override_url_control != null || new_override_url_control != null);
             if (new_override_url_control != null)
             {
                 str = new ProtectedString(false, new_override_url_control.Text);
             }
             else
             {
                 str = new ProtectedString(false, override_url_control.Text);
             }
         }
         if (get_name != "")
         {
             str = form.EntryStrings.Get(get_name);
         }
         if (str == null)
         {
             str = new ProtectedString(t.type.StartsWith("Protected"), "");
         }
         if (t.type == "Inline" || t.type == "Inline URL")
         {
             TextBox box = (TextBox)pair.Value;
             String  val = str.ReadString();
             val      = val.Replace("\r", "");
             val      = val.Replace("\n", "\r\n");
             box.Text = val;
         }
         else if (t.type == "Protected Inline")
         {
             var sedit = et_to_secure_edit[t];
             sedit.TextEx = str;
         }
         else if (t.type == "RichTextbox")
         {
             var    box = (CustomRichTextBoxEx)pair.Value;
             String val = str.ReadString();
             val      = val.Replace("\r", "");
             val      = val.Replace("\n", "\r\n");
             box.Text = val;
         }
         else if (t.type == "Listbox")
         {
             ComboBox combobox = (ComboBox)pair.Value;
             combobox.SelectedItem = str.ReadString();
         }
         else if (t.type == "Checkbox")
         {
             bool     val;
             CheckBox box = (CheckBox)pair.Value;
             box.Checked = false;
             if (Boolean.TryParse(str.ReadString(), out val))
             {
                 box.Checked = val;
             }
         }
         else if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
         {
             DateTimePicker picker = (DateTimePicker)pair.Value;
             if (t.fieldName == "@exp_date")
             {
                 find_expires_control(form);
                 Debug.Assert(expires_control != null && expires_cbx_control != null);
                 picker.Value   = expires_control.Value;
                 picker.Checked = expires_cbx_control.Checked;
             }
             else
             {
                 DateTime val;
                 if (DateTime.TryParse(str.ReadString(), out val))
                 {
                     picker.Value = val;
                 }
             }
         }
     }
 }
Пример #5
0
 private void save_child_vals()
 {
     foreach (KeyValuePair <EntryTemplate, Control> pair in et_to_control)
     {
         if (pair.Value == null)
         {
             continue;
         }
         EntryTemplate   t = pair.Key;
         ProtectedString str;
         if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
         {
             DateTimePicker picker = (DateTimePicker)pair.Value;
             if (t.fieldName == "@exp_date")
             {
                 find_expires_control(form);
                 Debug.Assert(expires_control != null && expires_cbx_control != null);
                 expires_cbx_control.Checked = picker.Checked;
                 expires_control.Value       = picker.Value;
                 continue;
             }
             str = new ProtectedString(false, picker.Value.ToString());
         }
         else if (t.type == "Checkbox")
         {
             CheckBox checkbox = (CheckBox)pair.Value;
             str = new ProtectedString(false, checkbox.Checked.ToString());
         }
         else if (t.type == "Inline" || t.type == "Inline URL")
         {
             TextBox box = (TextBox)pair.Value;
             str = new ProtectedString(false, box.Text == null ? "" : box.Text.Replace("\r", ""));
         }
         else if (t.type == "RichTextbox")
         {
             var box = (CustomRichTextBoxEx)pair.Value;
             str = new ProtectedString(false, box.Text == null ? "" : box.Text.Replace("\r", ""));
         }
         else if (t.type == "Listbox")
         {
             ComboBox combobox = (ComboBox)pair.Value;
             str = new ProtectedString(false, combobox.SelectedItem == null ? "" : combobox.SelectedItem.ToString());
         }
         else if (t.type == "Protected Inline")
         {
             var sedit = et_to_secure_edit[t];
             str = sedit.TextEx;
         }
         else
         {
             continue;
         }
         str = str.WithProtection(t.type.StartsWith("Protected"));
         if (t.fieldName == "@confirm")
         {
             //form.m_secRepeat.SetProtectedString(str, form.EntryRef, "Viewing/Editing Entry");
             continue;
         }
         if (t.fieldName == "@override")
         {
             find_override_url_control(form);
             Debug.Assert(new_override_url_control != null || override_url_control != null);
             if (new_override_url_control != null)
             {
                 new_override_url_control.Text = str.ReadString();
             }
             else
             {
                 override_url_control.Text = str.ReadString();
             }
             continue;
         }
         form.EntryStrings.Set(t.fieldName, str);
         //if (t.fieldName == PwDefs.PasswordField && current_password_confirm_field == null)
         //form.m_secRepeat.SetProtectedString(str, form.EntryRef, "Viewing/Editing Entry");
     }
 }
Пример #6
0
        private static void SetControlSizing(EntryTemplate template, Control control)
        {
            int?width  = CONTROL_WIDTH;
            int?left   = LEFT_CONTROL_OFFSET;
            int?top    = null;
            int?height = null;

            if (template == null)
            {
                if (control is Label)
                {
                    width = LABEL_WIDTH;
                    left  = 0;
                }
            }
            else
            {
                switch (template.type)
                {
                case "DataGridView":
                    left = null;

                    width  = PAGE_WIDTH;
                    height = PAGE_HEIGHT - BUTTON_HEIGHT - DpiUtil.ScaleIntY(10);
                    if (control is Button)
                    {
                        top    = height + DpiUtil.ScaleIntY(5);
                        height = BUTTON_HEIGHT;
                        width  = PAGE_WIDTH - DpiUtil.ScaleIntX(140) - DpiUtil.ScaleIntX(45);
                    }
                    break;

                case "Divider":
                    width = CONTROL_WIDTH + LABEL_WIDTH;
                    break;

                case "Checkbox":
                    width = null;
                    break;

                case "Inline URL":
                    width = CONTROL_WIDTH - 30;
                    if (control is LinkLabel)
                    {
                        left  = left + width + DpiUtil.ScaleIntX(10);
                        width = null;
                    }
                    break;

                case "Protected Inline":
                    if (control is CheckBox || control is Button)
                    {
                        left  = left + width + DpiUtil.ScaleIntX(10);
                        width = null;
                    }
                    break;
                }
            }
            if (left != null)
            {
                control.Left = (int)left;
            }
            if (width != null)
            {
                control.Width = (int)width;
            }
            if (top != null)
            {
                control.Top = (int)top;
            }
            if (height != null)
            {
                control.Height = (int)height;
            }
        }
        /// <summary>
        /// check templates
        /// </summary>
        /// <param name="templates"></param>
        public static void CheckTemplate(List <EntryTemplate> templates)
        {
            Assert.AreEqual(3, templates.Count);

            for (int i = 0; i < 3; ++i)
            {
                EntryTemplate temp = templates[i];
                Assert.AreEqual(i + 1, temp.Identity);

                switch (i + 1)
                {
                case 1:
                    // vendor
                    Assert.AreEqual(EntryType.VendorEntry,
                                    temp.EntryT);
                    Assert.AreEqual("Traffic expense on work", temp.TempName);
                    Assert.AreEqual(TestData.VENDOR_BUS,
                                    temp.getDefaultValue(VendorEntry.VENDOR).ToString());
                    Assert.AreEqual(TestData.GL_ACCOUNT_CASH,
                                    temp.getDefaultValue(VendorEntry.REC_ACC).ToString());
                    Assert.AreEqual(TestData.GL_ACCOUNT_COST,
                                    temp.getDefaultValue(VendorEntry.GL_ACCOUNT).ToString());
                    Assert.AreEqual(TestData.BUSINESS_AREA_WORK,
                                    temp.getDefaultValue(VendorEntry.BUSINESS_AREA)
                                    .ToString());
                    Assert.AreEqual(TestData.AMOUNT_VENDOR,
                                    temp.getDefaultValue(EntryTemplate.AMOUNT));
                    Assert.AreEqual(TestData.TEXT_VENDOR_DOC,
                                    temp.getDefaultValue(EntryTemplate.TEXT));

                    break;

                case 2:
                    // G/L
                    Assert.AreEqual(EntryType.GLEntry, temp.EntryT);
                    Assert.AreEqual(TestData.TEXT_GL_DOC, temp.TempName);
                    Assert.AreEqual(TestData.GL_ACCOUNT_BANK,
                                    temp.getDefaultValue(GLAccountEntry.SRC_ACCOUNT)
                                    .ToString());
                    Assert.AreEqual(TestData.GL_ACCOUNT_CASH,
                                    temp.getDefaultValue(GLAccountEntry.DST_ACCOUNT)
                                    .ToString());
                    break;

                case 3:

                    // customer
                    Assert.AreEqual(EntryType.CustomerEntry,
                                    temp.EntryT);
                    Assert.AreEqual(TestData.TEXT_CUSTOMER_DOC, temp.TempName);
                    Assert.AreEqual(TestData.CUSTOMER1,
                                    temp.getDefaultValue(CustomerEntry.CUSTOMER).ToString());
                    Assert.AreEqual(TestData.GL_ACCOUNT_BANK,
                                    temp.getDefaultValue(CustomerEntry.REC_ACC).ToString());
                    Assert.AreEqual(TestData.GL_ACCOUNT_REV,
                                    temp.getDefaultValue(CustomerEntry.GL_ACCOUNT)
                                    .ToString());

                    Assert.AreEqual(TestData.TEXT_CUSTOMER_DOC,
                                    temp.getDefaultValue(EntryTemplate.TEXT));
                    break;
                }
            }
        }
Пример #8
0
        private void InitializeGridView(TabPage page)
        {
            if (dataGridView != null)
            {
                page.Controls.Add(dataGridView);
                page.Controls.Add(remove_as_template_button);
                return;
            }

            page.HorizontalScroll.Enabled = false;
            page.SuspendLayout();
            dataGridView   = new DataGridView();
            colTitle       = new DataGridViewTextBoxColumn();
            colField       = new DataGridViewComboBoxColumn();
            colFieldName   = new DataGridViewTextBoxColumn();
            colType        = new DataGridViewComboBoxColumn();
            colOpt         = new DataGridViewDisableButtonColumn();
            colOptionValue = new DataGridViewTextBoxColumn();
            //
            // dataGridView
            //
            dataGridView.AllowUserToResizeRows = false;
            dataGridView.MultiSelect           = false;
            dataGridView.AllowDrop             = true;
            dataGridView.AllowUserToDeleteRows = true;
            dataGridView.AutoGenerateColumns   = false;

            dataGridView.EditMode                    = DataGridViewEditMode.EditOnEnter;
            dataGridView.DefaultValuesNeeded        += dataGridView_DefaultValuesNeeded;
            dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            dataGridView.Columns.AddRange(new DataGridViewColumn[] {
                colTitle,
                colField,
                colFieldName,
                colType,
                colOpt, colOptionValue
            });
            dataGridView.Location = new Point(0, 0);
            dataGridView.Name     = "dataGridView";
            dataGridView.TabIndex = 0;
            SetBaseSizes(page);
            var template = new EntryTemplate(null, null, "DataGridView", 0, null);            //used just for the conrol sizing

            SetControlSizing(template, dataGridView);
            dataGridView.ScrollBars             = ScrollBars.None;
            dataGridView.DragDrop              += dataGridView_DragDrop;
            dataGridView.DragOver              += dataGridView_DragOver;
            dataGridView.MouseDown             += dataGridView_MouseDown;
            dataGridView.MouseMove             += dataGridView_MouseMove;
            dataGridView.CellEnter             += dataGridView_CellEnter;
            dataGridView.MouseClick            += dataGridView_MouseClick;
            dataGridView.RowValidating         += dataGridView_RowValidating;
            dataGridView.CellValidating        += dataGridView_CellValidating;
            dataGridView.RowStateChanged       += dataGridView_RowStateChanged;
            dataGridView.SelectionChanged      += dataGridView_SelectionChanged;
            dataGridView.CellClick             += dataGridView_CellClick;
            dataGridView.EditingControlShowing += dataGridView_EditingControlShowing;
            //
            // colTitle
            //
            colTitle.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            colTitle.HeaderText   = "Title";
            colTitle.Name         = "colTitle";
            colTitle.SortMode     = DataGridViewColumnSortMode.NotSortable;
            //
            // colField
            //
            colField.HeaderText = "Field";
            colField.Items.AddRange(new object[] {
                "Custom",
                "Title",
                "Username",
                "Password",
                "Password Confirmation",
                "URL",
                "Notes",
                "Override URL",
                "Expiry Date"
            });
            colField.Name          = "colField";
            colField.Width         = DpiUtil.ScaleIntX(105);
            colField.DropDownWidth = 180;


            //
            // colFieldName
            //
            colFieldName.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            colFieldName.HeaderText   = "Field Name";
            colFieldName.Name         = "colFieldName";
            colFieldName.SortMode     = DataGridViewColumnSortMode.NotSortable;
            colFieldName.Width        = DpiUtil.ScaleIntX(75);
            //
            // colType
            //
            colType.HeaderText = "Type";
            colType.Name       = "colType";
            colType.Width      = DpiUtil.ScaleIntX(100);
            colType.Items.AddRange(new object[] {
                "Inline",
                "Inline URL",
                "Popout",
                "Protected Inline",
                "Protected Popout",
                "Date",
                "Time",
                "Date Time",
                "Checkbox",
                "Divider",
                "Listbox",
                "RichTextbox"
            });
            colType.DropDownWidth = 150;
            colOpt.HeaderText     = "Npt";
            colOpt.Name           = "colOpt";
            colOpt.Width          = DpiUtil.ScaleIntX(40);
            colOpt.UseColumnTextForButtonValue = true;
            colOpt.Text                 = "Opt";
            colOpt.ToolTipText          = "Option";
            colOptionValue.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            colOptionValue.Visible      = false;
            colOptionValue.Name         = "colOptionValue";
            colOptionValue.Width        = 0;


            page.Controls.Add(dataGridView);
            remove_as_template_button        = new Button();
            remove_as_template_button.Text   = "Remove As Template";
            remove_as_template_button.Height = BUTTON_HEIGHT;
            remove_as_template_button.Width  = PAGE_WIDTH - DpiUtil.ScaleIntX(140) - DpiUtil.ScaleIntX(45);
            remove_as_template_button.Left   = DpiUtil.ScaleIntX(85);
            //remove_as_template_button.Height = 28;
            remove_as_template_button.UseVisualStyleBackColor = true;

            dataGridView.Tag = template;

            remove_as_template_button.Tag    = template;
            remove_as_template_button.Click += remove_as_template_button_Click;
            SetControlSizing(template, remove_as_template_button);
            page.Controls.Add(remove_as_template_button);
            page.ResumeLayout();
        }
        /// <summary>
        /// save document as template
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="name">template name</param>
        /// <returns></returns>
        public async Task<EntryTemplate> SaveAsTemplate(IDocumentEntry entry, String name)
        {
            EntryTemplate template;

            // get the id
            int id = _list.Count + 1;

            try
            {
                CurrencyAmount amount = (CurrencyAmount)entry
                        .GetValue(EntryTemplate.AMOUNT);
                String text = (String)entry.GetValue(EntryTemplate.TEXT);
                if (entry is VendorEntry)
                {
                    template = new EntryTemplate(_coreDriver, _mdMgmt,
                            EntryType.VendorEntry, id, name);
                    template.AddDefaultValue(EntryTemplate.AMOUNT, amount);
                    template.AddDefaultValue(EntryTemplate.TEXT, text);

                    Object vendor = entry.GetValue(VendorEntry.VENDOR);
                    if (vendor != null)
                    {
                        template.AddDefaultValue(VendorEntry.VENDOR, vendor);
                    }
                    Object recAcc = entry.GetValue(VendorEntry.REC_ACC);
                    if (recAcc != null)
                    {
                        template.AddDefaultValue(VendorEntry.REC_ACC, recAcc);
                    }
                    Object costAcc = entry.GetValue(VendorEntry.GL_ACCOUNT);
                    if (costAcc != null)
                    {
                        template.AddDefaultValue(VendorEntry.GL_ACCOUNT, costAcc);
                    }
                    Object businessArea = entry.GetValue(VendorEntry.BUSINESS_AREA);
                    if (businessArea != null)
                    {
                        template.AddDefaultValue(VendorEntry.BUSINESS_AREA,
                                businessArea);
                    }

                    this.addTemplate(template);
                }
                else if (entry is GLAccountEntry)
                {
                    template = new EntryTemplate(_coreDriver, _mdMgmt,
                            EntryType.GLEntry, id, name);

                    template.AddDefaultValue(EntryTemplate.AMOUNT, amount);
                    template.AddDefaultValue(EntryTemplate.TEXT, text);

                    Object recAcc = entry.GetValue(GLAccountEntry.SRC_ACCOUNT);
                    if (recAcc != null)
                    {
                        template.AddDefaultValue(GLAccountEntry.SRC_ACCOUNT, recAcc);
                    }
                    Object costAcc = entry.GetValue(GLAccountEntry.DST_ACCOUNT);
                    if (costAcc != null)
                    {
                        template.AddDefaultValue(GLAccountEntry.DST_ACCOUNT,
                                costAcc);
                    }

                    this.addTemplate(template);
                }
                else if (entry is CustomerEntry)
                {
                    template = new EntryTemplate(_coreDriver, _mdMgmt,
                            EntryType.CustomerEntry, id, name);

                    template.AddDefaultValue(EntryTemplate.AMOUNT, amount);
                    template.AddDefaultValue(EntryTemplate.TEXT, text);

                    Object customer = entry.GetValue(CustomerEntry.CUSTOMER);
                    if (customer != null)
                    {
                        template.AddDefaultValue(CustomerEntry.CUSTOMER, customer);
                    }
                    Object recAcc = entry.GetValue(CustomerEntry.REC_ACC);
                    if (recAcc != null)
                    {
                        template.AddDefaultValue(CustomerEntry.REC_ACC, recAcc);
                    }
                    Object costAcc = entry.GetValue(CustomerEntry.GL_ACCOUNT);
                    if (costAcc != null)
                    {
                        template.AddDefaultValue(CustomerEntry.GL_ACCOUNT, costAcc);
                    }

                    this.addTemplate(template);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 72, e.Message,
                        MessageType.ERRO);
                throw new SystemException(e);
            }

            // save
            await _coreDriver.MdMgmt.StoreAsync();
            String filePath = String.Format("%s/%s", _coreDriver.RootFolder.Path,
                    FILE_NAME);
            StorageFile file = await _coreDriver.RootFolder.CreateFileAsync(
                FILE_NAME, CreationCollisionOption.OpenIfExists);

            XDocument xdoc = this.ToXMLDoc();

            await FileIO.WriteTextAsync(file, xdoc.ToString());
            return template;
        }
 /// <summary>
 /// add template
 /// </summary>
 /// <param name="entry"></param>
 /// <exception cref="DuplicatedTemplateException"></exception>
 private void addTemplate(EntryTemplate entry)
 {
     if (_list.ContainsKey(entry.Identity))
     {
         throw new DuplicatedTemplateException(entry.Identity);
     }
     _coreDriver.logDebugInfo(this.GetType(), 72,
             String.Format("Template: %s add", entry.TempName),
             MessageType.INFO);
     _list.Add(entry.Identity, entry);
 }