| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- namespace IndexFormula.Finance.Win
- {
- using IndexFormula.Finance;
- using MuchInfo.Chart.Data.EnumTypes;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- /// <summary>
- /// 当前数据公式应用窗口
- /// ShowForm()后,直接取FormulaManager.CurrentFormulas来获取得到的公式
- /// </summary>
- [ToolboxItem(false)]
- public partial 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();
- switch (SetLanguage.currentLanguage)
- {
- case ChartLanguageType.SimplifiedChinese:
- this.tpBtnUp.SetToolTip(this.btnUp, "上移");
- this.tpBtnDown.SetToolTip(this.btnDown, "下移");
- this.tpDelete.SetToolTip(this.btnDelete, "删除");
- this.tpSource.SetToolTip(this.btnSource, "源代码");
- break;
- case ChartLanguageType.TraditionalChinese:
- this.tpBtnUp.SetToolTip(this.btnUp, "上移");
- this.tpBtnDown.SetToolTip(this.btnDown, "下移");
- this.tpDelete.SetToolTip(this.btnDelete, "刪除");
- this.tpSource.SetToolTip(this.btnSource, "源代碼");
- break;
- case ChartLanguageType.English:
- 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");
- break;
- }
- //SetLanguage.CurrentUICulture();
- }
- private void AddFavorite(string[] Formulas)
- {
- this.ddlFavoriteFormula.Items.Clear();
- switch (SetLanguage.currentLanguage)
- {
- case ChartLanguageType.SimplifiedChinese:
- this.ddlFavoriteFormula.Items.Add("选择要添加新的公式");
- break;
- case ChartLanguageType.TraditionalChinese:
- this.ddlFavoriteFormula.Items.Add("選擇要添加新的公式");
- break;
- case ChartLanguageType.English:
- this.ddlFavoriteFormula.Items.Add("Select to add new formula");
- break;
- }
- 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 = new SelectFormula().Select(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)
- {
- EditFormula(FormulaBase.GetFormulaByName((string)this.lbFormulaList.Items[selectedIndex]));
- }
- }
- /// <summary>
- /// 编辑公式
- /// </summary>
- /// <param name="fb"></param>
- /// <returns></returns>
- public static bool EditFormula(FormulaBase fb)
- {
- string formulaFile = PluginManager.GetFormulaFile(fb);
- if (formulaFile != null)
- {
- string directoryName = Path.GetDirectoryName(formulaFile);
- formulaFile = Path.GetFileNameWithoutExtension(formulaFile).Replace('_', '.');
- formulaFile = directoryName + @"\" + formulaFile;
- if (File.Exists(formulaFile))
- {
- Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(SetLanguage.languageName);
- FormulaSourceEditor.Open(formulaFile, fb.GetType().ToString());
- return true;
- }
- }
- return false;
- }
- 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 System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormulaManager));
- this.ddlFavoriteFormula = new System.Windows.Forms.ComboBox();
- this.btnCancel = new System.Windows.Forms.Button();
- this.gbCurrent = new System.Windows.Forms.GroupBox();
- this.cbSecondYAxis = new System.Windows.Forms.CheckBox();
- this.btnDown = new System.Windows.Forms.Button();
- this.btnUp = new System.Windows.Forms.Button();
- this.btnSource = new System.Windows.Forms.Button();
- this.lbFormulaList = new System.Windows.Forms.ListBox();
- this.gbParam = new System.Windows.Forms.GroupBox();
- this.btnDelete = new System.Windows.Forms.Button();
- this.ilIcon = new System.Windows.Forms.ImageList(this.components);
- this.btnOK = new System.Windows.Forms.Button();
- this.btnMore = new System.Windows.Forms.Button();
- this.ilFormula = new System.Windows.Forms.ImageList(this.components);
- this.tpBtnUp = new System.Windows.Forms.ToolTip(this.components);
- this.tpBtnDown = new System.Windows.Forms.ToolTip(this.components);
- this.tpDelete = new System.Windows.Forms.ToolTip(this.components);
- this.tpSource = new System.Windows.Forms.ToolTip(this.components);
- this.gbCurrent.SuspendLayout();
- this.SuspendLayout();
- //
- // ddlFavoriteFormula
- //
- this.ddlFavoriteFormula.DisplayMember = "CombineName";
- this.ddlFavoriteFormula.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- resources.ApplyResources(this.ddlFavoriteFormula, "ddlFavoriteFormula");
- this.ddlFavoriteFormula.Name = "ddlFavoriteFormula";
- this.ddlFavoriteFormula.SelectedIndexChanged += new System.EventHandler(this.ddlFavoriteFormula_SelectedIndexChanged);
- //
- // btnCancel
- //
- resources.ApplyResources(this.btnCancel, "btnCancel");
- this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btnCancel.Name = "btnCancel";
- //
- // gbCurrent
- //
- resources.ApplyResources(this.gbCurrent, "gbCurrent");
- 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.Name = "gbCurrent";
- this.gbCurrent.TabStop = false;
- //
- // cbSecondYAxis
- //
- resources.ApplyResources(this.cbSecondYAxis, "cbSecondYAxis");
- this.cbSecondYAxis.Name = "cbSecondYAxis";
- this.cbSecondYAxis.CheckedChanged += new System.EventHandler(this.cbSecondYAxis_CheckedChanged);
- this.cbSecondYAxis.Click += new System.EventHandler(this.cbSecondYAxis_Click);
- //
- // btnDown
- //
- resources.ApplyResources(this.btnDown, "btnDown");
- this.btnDown.Image = global::IndexFormula.Finance.Win.Properties.Resources.arrow_down;
- this.btnDown.Name = "btnDown";
- this.btnDown.Click += new System.EventHandler(this.btnDown_Click);
- //
- // btnUp
- //
- resources.ApplyResources(this.btnUp, "btnUp");
- this.btnUp.Image = global::IndexFormula.Finance.Win.Properties.Resources.arrow_up;
- this.btnUp.Name = "btnUp";
- this.btnUp.Click += new System.EventHandler(this.btnUp_Click);
- //
- // btnSource
- //
- resources.ApplyResources(this.btnSource, "btnSource");
- this.btnSource.Image = global::IndexFormula.Finance.Win.Properties.Resources.application_edit;
- this.btnSource.Name = "btnSource";
- this.btnSource.Click += new System.EventHandler(this.btnSource_Click);
- //
- // lbFormulaList
- //
- resources.ApplyResources(this.lbFormulaList, "lbFormulaList");
- this.lbFormulaList.DisplayMember = "Description";
- this.lbFormulaList.Name = "lbFormulaList";
- this.lbFormulaList.ValueMember = "Name";
- this.lbFormulaList.SelectedIndexChanged += new System.EventHandler(this.lbOverlayList_SelectedIndexChanged);
- //
- // gbParam
- //
- resources.ApplyResources(this.gbParam, "gbParam");
- this.gbParam.Name = "gbParam";
- this.gbParam.TabStop = false;
- //
- // btnDelete
- //
- resources.ApplyResources(this.btnDelete, "btnDelete");
- this.btnDelete.Image = global::IndexFormula.Finance.Win.Properties.Resources.Delete;
- this.btnDelete.Name = "btnDelete";
- this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
- //
- // ilIcon
- //
- this.ilIcon.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- resources.ApplyResources(this.ilIcon, "ilIcon");
- this.ilIcon.TransparentColor = System.Drawing.Color.Transparent;
- //
- // btnOK
- //
- resources.ApplyResources(this.btnOK, "btnOK");
- this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.btnOK.Name = "btnOK";
- //
- // btnMore
- //
- resources.ApplyResources(this.btnMore, "btnMore");
- this.btnMore.Name = "btnMore";
- this.btnMore.Click += new System.EventHandler(this.btnMore_Click);
- //
- // ilFormula
- //
- this.ilFormula.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- resources.ApplyResources(this.ilFormula, "ilFormula");
- this.ilFormula.TransparentColor = System.Drawing.Color.Transparent;
- //
- // FormulaManager
- //
- this.AcceptButton = this.btnOK;
- resources.ApplyResources(this, "$this");
- this.CancelButton = this.btnCancel;
- this.Controls.Add(this.btnMore);
- this.Controls.Add(this.ddlFavoriteFormula);
- this.Controls.Add(this.btnCancel);
- this.Controls.Add(this.gbCurrent);
- this.Controls.Add(this.btnOK);
- this.Name = "FormulaManager";
- this.gbCurrent.ResumeLayout(false);
- this.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, string.Empty);
- }
- /// <summary>
- /// 弹出编辑当前公式对话框
- /// </summary>
- /// <param name="formulas">当前图表用到的公式集</param>
- /// <param name="SelectedFormula">当前选中图表的应用公式</param>
- /// <returns>返回对话框</returns>
- public DialogResult ShowForm(string[] formulas, string selectedFormula)
- {
- if (formulas != null)
- {
- string[] strArray = formulas;
- if (strArray != null)
- {
- this.CurrentFormulas = string.Join("#", strArray);
- string createName = "";
- if (selectedFormula != null)
- {
- createName = selectedFormula;
- }
- this.SelectedFormula = createName;
- ArrayList list = new ArrayList();
- list.AddRange(strArray);
- //以下稍作修改,合并2个常用的公式供一般性选择
- list.AddRange(CombinationArray(this.OverlayFormulas, this.ListedFormulas));
- //if (fa.IsMain()) //是否为基本主要的。这个函数需要界面数据,暂时不作实现
- //{
- // list.AddRange(this.OverlayFormulas);
- //}
- //else
- //{
- // list.AddRange(this.ListedFormulas);
- //}
- this.AddFavorite((string[])list.ToArray(typeof(string)));
- }
- }
- return base.ShowDialog();
- }
- 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();
- }
- /// <summary>
- /// 合并两组字符串
- /// </summary>
- /// <param name="array1">字符串1</param>
- /// <param name="array2">字符串2</param>
- /// <returns>返回合并后字符串</returns>
- private string[] CombinationArray(string[] array1, string[] array2)
- {
- List<string> comArray = new List<string>();
- comArray.AddRange(array1);
- foreach (string str in array2)
- {
- if (!comArray.Contains(str))
- {
- comArray.Add(str);
- }
- }
- return comArray.ToArray();
- }
- public bool IsMain(int AxisYIndex)
- {
- //以下主要判断数据的类型
- //for (int i = 0; i < this.FormulaDataArray.Count; i++)
- //{
- // if ((((this[i].RenderType == FormulaRenderType.STOCK) || (this[i].RenderType == FormulaRenderType.MONOSTOCK)) || (string.Compare(this[i].Name, "Main", true) == 0)) && ((AxisYIndex < 0) || (this[i].AxisYIndex == AxisYIndex)))
- // {
- // return true;
- // }
- //}
- //return false;
- return true;
- }
- 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;
- }
- }
- }
- }
- }
|