namespace Easychart.Finance.Win { using Easychart.Finance; using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Resources; using System.Runtime.InteropServices; using System.Windows.Forms; [ToolboxItem(false)] public class FormulaManager : Form { private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnDelete; private System.Windows.Forms.Button btnDown; private System.Windows.Forms.Button btnMore; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnSource; private System.Windows.Forms.Button btnUp; private System.Windows.Forms.CheckBox cbSecondYAxis; private IContainer components; private System.Windows.Forms.ComboBox ddlFavoriteFormula; private bool DisableChangeEvent; private System.Windows.Forms.GroupBox gbCurrent; private System.Windows.Forms.GroupBox gbParam; public System.Windows.Forms.ImageList ilFormula; private System.Windows.Forms.ImageList ilIcon; private System.Windows.Forms.ListBox lbFormulaList; private string[] ListedFormulas = new string[] { "MAIN", "MainArea", "VOLMA", "MACD", "RSI", "CMF", "TRIX", "CCI", "FastSTO", "SlowSTO", "ATR", "OBV", "ULT", "DPO", "WR", "PPO", "PVO", "StochRSI", "AD" }; private string[] OverlayFormulas = new string[] { "MAIN", "MainArea", "HL", "MA", "EMA", "BB", "AreaBB", "SAR", "ZIGLABEL", "ZIG", "ZIGICON", "ZIGW", "ZIGSR", "SR", "SRAxisY", "COMPARE", "COMPARE2", "Fibonnaci", "LinRegr", "TradingIcon" }; private System.Windows.Forms.ToolTip tpBtnDown; private System.Windows.Forms.ToolTip tpBtnUp; private System.Windows.Forms.ToolTip tpDelete; private System.Windows.Forms.ToolTip tpSource; public FormulaManager() { this.InitializeComponent(); this.tpBtnUp.SetToolTip(this.btnUp, "Move Up"); this.tpBtnDown.SetToolTip(this.btnDown, "Move Down"); this.tpDelete.SetToolTip(this.btnDelete, "Delete"); this.tpSource.SetToolTip(this.btnSource, "Source Code"); } private void AddFavorite(string[] Formulas) { this.ddlFavoriteFormula.Items.Clear(); this.ddlFavoriteFormula.Items.Add("Select to add new formula"); foreach (string str in Formulas) { FormulaBase formulaByName = FormulaBase.GetFormulaByName(str); foreach (object obj2 in this.ddlFavoriteFormula.Items) { if (obj2.GetType() == formulaByName.GetType()) { continue; } } this.ddlFavoriteFormula.Items.Add(formulaByName); } this.ddlFavoriteFormula.SelectedIndex = 0; } private void AddFormulas() { FormulaBase selectedItem = (FormulaBase) this.ddlFavoriteFormula.SelectedItem; if (selectedItem != null) { this.AddFormulas(selectedItem.CreateName); } } private void AddFormulas(string Name) { this.lbFormulaList.Items.Add(Name); this.SelectLastFormula(); } private void btnDelete_Click(object sender, EventArgs e) { this.DeleteFormulas(); } private void btnDown_Click(object sender, EventArgs e) { this.MoveFormula(1); } private void btnMore_Click(object sender, EventArgs e) { string name = ChartWinControl.DoSelectFormula(null, null, false); if (name != null) { this.AddFormulas(name); } } private void btnSource_Click(object sender, EventArgs e) { int selectedIndex = this.lbFormulaList.SelectedIndex; if (selectedIndex >= 0) { ChartWinControl.EditFormula(FormulaBase.GetFormulaByName((string) this.lbFormulaList.Items[selectedIndex])); } } private void btnUp_Click(object sender, EventArgs e) { this.MoveFormula(-1); } private void cbSecondYAxis_CheckedChanged(object sender, EventArgs e) { this.DisableChangeEvent = true; try { if (this.lbFormulaList.SelectedItem != null) { string str = this.lbFormulaList.SelectedItem.ToString(); this.lbFormulaList.Items[this.lbFormulaList.SelectedIndex] = str.TrimEnd(new char[] { '!' }) + (this.cbSecondYAxis.Checked ? "!" : ""); } } finally { this.DisableChangeEvent = false; } } private void cbSecondYAxis_Click(object sender, EventArgs e) { } private void ddlFavoriteFormula_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddlFavoriteFormula.SelectedIndex > 0) { this.AddFormulas(); this.ddlFavoriteFormula.SelectedIndex = 0; } } private void DeleteFormulas() { this.DisableChangeEvent = true; int selectedIndex = this.lbFormulaList.SelectedIndex; if (selectedIndex >= 0) { try { this.lbFormulaList.Items.RemoveAt(selectedIndex); } finally { this.DisableChangeEvent = false; } this.SetSelectFormula(selectedIndex); } } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.components = new Container(); ResourceManager manager = new ResourceManager(typeof(FormulaManager)); this.ddlFavoriteFormula = new ComboBox(); this.btnCancel = new Button(); this.gbCurrent = new GroupBox(); this.btnDown = new Button(); this.ilIcon = new ImageList(this.components); this.btnUp = new Button(); this.btnSource = new Button(); this.lbFormulaList = new ListBox(); this.gbParam = new GroupBox(); this.btnDelete = new Button(); this.btnOK = new Button(); this.btnMore = new Button(); this.ilFormula = new ImageList(this.components); this.tpBtnUp = new ToolTip(this.components); this.tpBtnDown = new ToolTip(this.components); this.tpDelete = new ToolTip(this.components); this.tpSource = new ToolTip(this.components); this.cbSecondYAxis = new CheckBox(); this.gbCurrent.SuspendLayout(); base.SuspendLayout(); this.ddlFavoriteFormula.DisplayMember = "CombineName"; this.ddlFavoriteFormula.DropDownStyle = ComboBoxStyle.DropDownList; this.ddlFavoriteFormula.Location = new Point(0x10, 0x10); this.ddlFavoriteFormula.MaxDropDownItems = 12; this.ddlFavoriteFormula.Name = "ddlFavoriteFormula"; this.ddlFavoriteFormula.Size = new Size(0x103, 0x15); this.ddlFavoriteFormula.TabIndex = 0; this.ddlFavoriteFormula.SelectedIndexChanged += new EventHandler(this.ddlFavoriteFormula_SelectedIndexChanged); this.btnCancel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; this.btnCancel.DialogResult =System.Windows.Forms.DialogResult.Cancel; this.btnCancel.Location = new Point(0x68, 400); this.btnCancel.Name = "btnCancel"; this.btnCancel.TabIndex = 9; this.btnCancel.Text = "&Cancel"; this.gbCurrent.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top; this.gbCurrent.Controls.Add(this.cbSecondYAxis); this.gbCurrent.Controls.Add(this.btnDown); this.gbCurrent.Controls.Add(this.btnUp); this.gbCurrent.Controls.Add(this.btnSource); this.gbCurrent.Controls.Add(this.lbFormulaList); this.gbCurrent.Controls.Add(this.gbParam); this.gbCurrent.Controls.Add(this.btnDelete); this.gbCurrent.Location = new Point(0x10, 0x30); this.gbCurrent.Name = "gbCurrent"; this.gbCurrent.Size = new Size(0x250, 0x158); this.gbCurrent.TabIndex = 12; this.gbCurrent.TabStop = false; this.gbCurrent.Text = "Current Formulas"; this.btnDown.Anchor = AnchorStyles.Right | AnchorStyles.Top; this.btnDown.FlatStyle = FlatStyle.Popup; this.btnDown.ImageAlign = ContentAlignment.BottomCenter; this.btnDown.ImageIndex = 1; this.btnDown.ImageList = this.ilIcon; this.btnDown.Location = new Point(280, 0x40); this.btnDown.Name = "btnDown"; this.btnDown.Size = new Size(0x18, 0x18); this.btnDown.TabIndex = 4; this.btnDown.Click += new EventHandler(this.btnDown_Click); this.ilIcon.ImageSize = new Size(20, 20); this.ilIcon.ImageStream = (System.Windows.Forms.ImageListStreamer)manager.GetObject("ilIcon.ImageStream"); this.ilIcon.TransparentColor = Color.Transparent; this.btnUp.Anchor = AnchorStyles.Right | AnchorStyles.Top; this.btnUp.FlatStyle = FlatStyle.Popup; this.btnUp.ImageAlign = ContentAlignment.BottomCenter; this.btnUp.ImageIndex = 0; this.btnUp.ImageList = this.ilIcon; this.btnUp.Location = new Point(280, 0x20); this.btnUp.Name = "btnUp"; this.btnUp.Size = new Size(0x18, 0x18); this.btnUp.TabIndex = 3; this.btnUp.Click += new EventHandler(this.btnUp_Click); this.btnSource.Anchor = AnchorStyles.Right | AnchorStyles.Top; this.btnSource.FlatStyle = FlatStyle.Popup; this.btnSource.ImageIndex = 3; this.btnSource.ImageList = this.ilIcon; this.btnSource.Location = new Point(280, 0x81); this.btnSource.Name = "btnSource"; this.btnSource.Size = new Size(0x18, 0x18); this.btnSource.TabIndex = 6; this.btnSource.Click += new EventHandler(this.btnSource_Click); this.lbFormulaList.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top; this.lbFormulaList.DisplayMember = "Description"; this.lbFormulaList.Location = new Point(8, 0x18); this.lbFormulaList.Name = "lbFormulaList"; this.lbFormulaList.Size = new Size(0x108, 0x12f); this.lbFormulaList.TabIndex = 2; this.lbFormulaList.ValueMember = "Name"; this.lbFormulaList.SelectedIndexChanged += new EventHandler(this.lbOverlayList_SelectedIndexChanged); this.gbParam.Anchor = AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; this.gbParam.Location = new Point(0x138, 0x12); this.gbParam.Name = "gbParam"; this.gbParam.Size = new Size(0x110, 0x11f); this.gbParam.TabIndex = 7; this.gbParam.TabStop = false; this.gbParam.Text = "Parameters"; this.btnDelete.Anchor = AnchorStyles.Right | AnchorStyles.Top; this.btnDelete.FlatStyle = FlatStyle.Popup; this.btnDelete.ImageAlign = ContentAlignment.BottomCenter; this.btnDelete.ImageIndex = 2; this.btnDelete.ImageList = this.ilIcon; this.btnDelete.Location = new Point(280, 0x60); this.btnDelete.Name = "btnDelete"; this.btnDelete.Size = new Size(0x18, 0x18); this.btnDelete.TabIndex = 5; this.btnDelete.Click += new EventHandler(this.btnDelete_Click); this.btnOK.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; this.btnOK.Location = new Point(0x10, 400); this.btnOK.Name = "btnOK"; this.btnOK.TabIndex = 8; this.btnOK.Text = "&OK"; this.btnMore.Location = new Point(0x120, 15); this.btnMore.Name = "btnMore"; this.btnMore.Size = new Size(0x48, 0x17); this.btnMore.TabIndex = 1; this.btnMore.Text = "More"; this.btnMore.Click += new EventHandler(this.btnMore_Click); this.ilFormula.ImageSize = new Size(0x10, 0x10); this.ilFormula.ImageStream = (System.Windows.Forms.ImageListStreamer)manager.GetObject("ilFormula.ImageStream"); this.ilFormula.TransparentColor = Color.Transparent; this.cbSecondYAxis.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; this.cbSecondYAxis.FlatStyle = FlatStyle.Flat; this.cbSecondYAxis.Location = new Point(0x138, 0x139); this.cbSecondYAxis.Name = "cbSecondYAxis"; this.cbSecondYAxis.Size = new Size(0xd0, 0x13); this.cbSecondYAxis.TabIndex = 8; this.cbSecondYAxis.Text = "Show in second Y-axis"; this.cbSecondYAxis.Click += new EventHandler(this.cbSecondYAxis_Click); this.cbSecondYAxis.CheckedChanged += new EventHandler(this.cbSecondYAxis_CheckedChanged); base.AcceptButton = this.btnOK; this.AutoScaleBaseSize = new Size(6, 14); base.CancelButton = this.btnCancel; base.ClientSize = new Size(0x268, 0x1b6); base.Controls.Add(this.btnMore); base.Controls.Add(this.ddlFavoriteFormula); base.Controls.Add(this.btnCancel); base.Controls.Add(this.gbCurrent); base.Controls.Add(this.btnOK); this.Font = new Font("Verdana", 8.5f); base.MinimumSize = new Size(400, 400); base.Name = "FormulaManager"; base.StartPosition = FormStartPosition.CenterScreen; this.Text = "Formula Manager"; this.gbCurrent.ResumeLayout(false); base.ResumeLayout(false); } private void lbOverlayList_SelectedIndexChanged(object sender, EventArgs e) { if (!this.DisableChangeEvent) { string str; this.ParamToTextBox((string) this.lbFormulaList.SelectedItem, out str); } } private void MoveFormula(int Delta) { this.DisableChangeEvent = true; try { int selectedIndex = this.lbFormulaList.SelectedIndex; int num2 = selectedIndex + Delta; if (((selectedIndex >= 0) && (num2 >= 0)) && (num2 < this.lbFormulaList.Items.Count)) { object item = this.lbFormulaList.Items[selectedIndex]; this.lbFormulaList.Items.RemoveAt(selectedIndex); this.lbFormulaList.Items.Insert(selectedIndex + Delta, item); this.lbFormulaList.SelectedIndex = num2; } } finally { this.DisableChangeEvent = false; } } public void ParamToTextBox(string NameAndParam, out string FormulaName) { this.cbSecondYAxis.Checked = NameAndParam.EndsWith("!"); FormulaBase formulaByName = FormulaBase.GetFormulaByName(NameAndParam.TrimEnd(new char[] { '!' })); FormulaName = formulaByName.FormulaName; SelectFormula.AddParamToGroupBox(this.gbParam, this.ilFormula, formulaByName, new EventHandler(this.tbP4_Leave)); } private void SelectFirstFormula() { this.SetSelectFormula(0); } private void SelectLastFormula() { this.SetSelectFormula(this.lbFormulaList.Items.Count - 1); } private void SetSelectFormula(int Index) { if (Index < 0) { Index = 0; } if (Index >= this.lbFormulaList.Items.Count) { Index = this.lbFormulaList.Items.Count - 1; } if ((Index >= 0) && (Index < this.lbFormulaList.Items.Count)) { this.lbFormulaList.SelectedIndex = Index; } } public DialogResult ShowForm() { this.AddFavorite(this.ListedFormulas); return this.ShowForm(null, null); } public DialogResult ShowForm(FormulaArea fa, FormulaBase SelectedFormula) { if (fa != null) { string[] strArray = fa.FormulaToStrings(); if (strArray != null) { this.CurrentFormulas = string.Join("#", strArray); string createName = ""; if (SelectedFormula != null) { createName = SelectedFormula.CreateName; } this.SelectedFormula = createName; ArrayList list = new ArrayList(); list.AddRange(strArray); if (fa.IsMain()) { list.AddRange(this.OverlayFormulas); } else { list.AddRange(this.ListedFormulas); } this.AddFavorite((string[]) list.ToArray(typeof(string))); } } return base.ShowDialog(); } private void tbP4_Leave(object sender, EventArgs e) { string str = this.TextBoxToParam((string) this.lbFormulaList.SelectedItem); if (str != "") { this.DisableChangeEvent = true; try { this.lbFormulaList.Items[this.lbFormulaList.SelectedIndex] = str; } finally { this.DisableChangeEvent = false; } } } private string TextBoxToParam(string FormulaName) { int index = FormulaName.IndexOf('('); if (index >= 0) { FormulaName = FormulaName.Substring(0, index); } string param = SelectFormula.GetParam(this.gbParam); if (FormulaBase.GetFormulaByName(FormulaName) != null) { return (FormulaName + param); } return ""; } public string CurrentFormulas { get { string str = ""; foreach (string str2 in this.lbFormulaList.Items) { if (str != "") { str = str + "#"; } str = str + str2; } return str; } set { this.lbFormulaList.Items.Clear(); if ((value != "") && (value != null)) { foreach (string str in value.Split(new char[] { '#' })) { this.AddFormulas(str); } this.SelectFirstFormula(); } } } public string SelectedFormula { get { if (this.lbFormulaList.SelectedIndex > 0) { return this.lbFormulaList.Items[this.lbFormulaList.SelectedIndex].ToString(); } return ""; } set { int index = this.lbFormulaList.Items.IndexOf(value); if (index >= 0) { this.lbFormulaList.SelectedIndex = index; } } } } }