| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- 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;
- }
- }
- }
- }
- }
|