void mnitlbAll_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string typed = e.StringUserTyped;
			var senderMinMaxCurrentStep = sender as MenuItemLabeledTextBox;
			try {
				decimal parsed = Decimal.Parse(typed);
				switch (senderMinMaxCurrentStep.Name) {
					case "mniltbValueMin":			this.ValueMin		= parsed; break; 
					case "mniltbValueMax":			this.ValueMax		= parsed; break; 
					case "mniltbValueCurrent":
						if (parsed < this.ValueMin) {
							this.ValueCurrent = this.ValueMin;
							e.HighlightTextWithRed = true;
							return;
						}
						if (parsed > this.ValueMax) {
							this.ValueCurrent = this.ValueMax;
							e.HighlightTextWithRed = true;
							return;
						}
						this.ValueCurrent = parsed;
						this.ValueCurrentChanged(this, EventArgs.Empty);
						this.ctxSlider_Opening(this, null);		// not sure how textbox gets multiline input inside!!! may be this will help as for ScriptContexts
						break;
					case "mniltbValueStep":			this.ValueStep		= parsed; break;
					default:	Assembler.PopupException("mnitlbAll_UserTyped(): add handler for senderMinMaxCurrentStep.Name[" + senderMinMaxCurrentStep.Name + "]"); break;
				}
			} catch (Exception ex) {
				e.HighlightTextWithRed = true;
			}
		}
		void mniltbScriptContextDuplicateTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string dupeScriptContextName = e.StringUserTyped;
			ContextScript scriptContextToDuplicate = this.ScriptContextFromMniTag(sender);
			this.Strategy.ScriptContextAdd(dupeScriptContextName, scriptContextToDuplicate);
			this.RaiseOnScriptContextDuplicated(dupeScriptContextName);
			this.ctxParameterBags_Opening(this, null);
		}
		void mniltbScriptContextRenameTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string scriptContextNewName = e.StringUserTyped;
			ContextScript scriptContextToRename = this.ScriptContextFromMniTag(sender);
			this.Strategy.ScriptContextRename(scriptContextToRename, scriptContextNewName);
			this.RaiseOnScriptContextRenamed(scriptContextNewName);
			this.ctxParameterBags_Opening(this, null);
		}
Ejemplo n.º 4
0
        void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }
            e.Handled = e.SuppressKeyPress = true;
            string typed = this.LabeledTextBoxControl.TextBox.Text;

            typed = typed.Trim();
            typed = typed.Replace('\'', '~');                   //  no single quotes against future SQL-injection: update name='456~~; DELETE *;'
            typed = typed.Replace('"', '~');                    //  no double quotes for current JSON consistency: "ScriptContextsByName": { "456~~": {} }
            var args = new LabeledTextBoxUserTypedArgs(typed);

            if (this.UserTyped != null)
            {
                this.UserTyped(this, args);
            }
            this.LabeledTextBoxControl.TextRed = args.HighlightTextWithRed;
            if (args.RootHandlerShouldCloseParentContextMenuStrip == false)
            {
                return;
            }
            ContextMenuStrip ctx = this.Owner as ContextMenuStrip;

            if (ctx == null)
            {
                return;
            }
            ctx.Close();
        }
		public void WorkspaceCloneTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string workspaceCloneToName = e.StringUserTyped;
//			ScriptContext scriptContextToRename = this.ScriptContextFromMniTag(sender);
//			this.Strategy.ScriptContextRename(scriptContextToRename, workspaceCloneToName);
//			this.RaiseOnScriptContextRenamed(workspaceCloneToName);
//			this.ctxParameterBags_Opening(this, null);
			Assembler.PopupException("NotImplementedException WorkspaceCloneTo_UserTyped(" + e.StringUserTyped + ")");
		}
		void mniltbDelay_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			MenuItemLabeledTextBox mnilbDelay = sender as MenuItemLabeledTextBox;
			string typed = e.StringUserTyped;
			int typedMsec = this.DataSnapshot.TreeRefreshDelayMsec;
			bool parsed = Int32.TryParse(typed, out typedMsec);
			if (parsed == false) {
				mnilbDelay.InputFieldValue = this.DataSnapshot.TreeRefreshDelayMsec.ToString();
				mnilbDelay.TextRed = true;
				return;
			}
			this.DataSnapshot.TreeRefreshDelayMsec = typedMsec;
			mnilbDelay.TextRed = false;
			this.DataSnapshotSerializer.Serialize();
			e.RootHandlerShouldCloseParentContextMenuStrip = true;
		}
		void TextBox_KeyDown(object sender, KeyEventArgs e) {
			if (e.KeyCode != Keys.Enter) return;
			e.Handled = e.SuppressKeyPress = true;
			string typed = this.LabeledTextBoxControl.TextBox.Text;
			typed = typed.Trim();
			typed = typed.Replace('\'', '~');	//  no single quotes against future SQL-injection: update name='456~~; DELETE *;' 
			typed = typed.Replace('"', '~');	//  no double quotes for current JSON consistency: "ScriptContextsByName": { "456~~": {} }
			var args = new LabeledTextBoxUserTypedArgs(typed);
			if (this.UserTyped != null) {
				this.UserTyped(this, args);
			}
			this.LabeledTextBoxControl.TextRed = args.HighlightTextWithRed;
			if (args.RootHandlerShouldCloseParentContextMenuStrip == false) return;
			ContextMenuStrip ctx = this.Owner as ContextMenuStrip;
			if (ctx == null) return;
			ctx.Close();
		}
		void mniltbScriptContextNewWithDefaults_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string newScriptContextName = e.StringUserTyped;
			this.Strategy.ScriptContextAdd(newScriptContextName);
			this.RaiseOnScriptContextCreated(newScriptContextName);
			this.ctxParameterBags_Opening(this, null);
		}
		void mniltbDataSourceAddNew_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string newDataSourceName = e.StringUserTyped;
			DataSource foundWithSameName = this.dataSourceRepository.ItemFind(newDataSourceName);
			if (foundWithSameName != null) {
				Assembler.InstanceInitialized.StatusReporter.DisplayStatus("DataSource[" + newDataSourceName + "] already exists");
				this.tree.EnsureModelVisible(foundWithSameName);
				this.tree.SelectObject(foundWithSameName);
				e.HighlightTextWithRed = true;
				//e.RootHandlerShouldCloseParentContextMenuStrip = true;
				return;
			}
			// literally: create, add, make it visible, emulate a click on the newborn, popup editor 
			var dataSourceNewborn = new DataSource(newDataSourceName);
			this.dataSourceRepository.ItemAdd(dataSourceNewborn, this);
			// all the rest was already done in dataSourceRepository.ItemAdd() => dataSourceRepository_OnDataSourceAdded(),
//			this.populateDataSourcesIntoTreeListView();
//			this.tree.EnsureModelVisible(foundWithSameName);
//			this.tree.SelectObject(foundWithSameName);
//			this.SelectSymbol(ds.Name);
			// but now user has selected the static provider and I want the provider's icon in the tree
			this.populateIconForDataSource(dataSourceNewborn);
			this.RaiseOnDataSourceEditClicked();	//ds
		}
		void mnitlbAll_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			try {
				string userTyped = e.StringUserTyped;
				int userTypedInteger;
				bool validInteger = Int32.TryParse(userTyped, out userTypedInteger);
				if (validInteger == false) {
					e.HighlightTextWithRed = true;
					return;
				}
				if (userTypedInteger <= 0) {
					e.HighlightTextWithRed = true;
					return;
				}
				MenuItemLabeledTextBox mniTypedAsLTB = sender as MenuItemLabeledTextBox;
				if (mniTypedAsLTB == null) {
					string msg = "SENDER_MUSTBE_LabeledTextBoxControl_GOT " + mniTypedAsLTB.GetType();
					Assembler.PopupException(msg);
					return;
				}

				BarScale barScaleTyped;
				switch (mniTypedAsLTB.Name) {
					case "mnitlbMinutes":		barScaleTyped = BarScale.Minute;		break;
					case "mnitlbHourly":		barScaleTyped = BarScale.Hour;			break;
					case "mnitlbDaily":			barScaleTyped = BarScale.Daily;			break;
					case "mnitlbWeekly":		barScaleTyped = BarScale.Weekly;		break;
					case "mnitlbMonthly":		barScaleTyped = BarScale.Monthly;		break;
					//case "mnitlbQuarterly":		barScaleTyped = BarScale.Quarterly;		break;
					case "mnitlbYearly":		barScaleTyped = BarScale.Yearly;		break;
					default:
						string msg = "SENDER_UNEXPECTED_NAME " + mniTypedAsLTB.Name;
						Assembler.PopupException(msg);
						return;
				}
				
				this.selectOneDeselectResetOthers(this.DdbBars.DropDownItems, mniTypedAsLTB, this.GroupScaleLabeledTextboxes);
				
				BarScaleInterval scaleIntervalUserEntered = new BarScaleInterval(barScaleTyped, userTypedInteger);
				ContextChart context = this.ChartFormManager.ContextCurrentChartOrStrategy;
				context.ScaleInterval = scaleIntervalUserEntered;
				this.ChartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("mniltbAll_UserTyped");
			} catch (Exception ex) {
				Assembler.PopupException("mniltbMinutes_UserTyped()", ex);
			}
		}
		void mnitlbPositionSizeDollarsConstantEachTrade_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			try {
				string userTyped = e.StringUserTyped;
				double userTypedDouble;
				bool validInteger = Double.TryParse(userTyped, out userTypedDouble);
				if (validInteger == false) {
					e.HighlightTextWithRed = true;
					return;
				}
				if (userTypedDouble <= 0) {
					e.HighlightTextWithRed = true;
					return;
				}
				
				ContextScript context = this.ChartFormManager.Strategy.ScriptContextCurrent;
				context.PositionSize = new PositionSize(PositionSizeMode.DollarsConstantForEachTrade, userTypedDouble);

				this.selectOneDeselectResetOthers(this.DdbBacktest.DropDownItems, sender, this.GroupPositionSizeLabeledTextboxes);

				this.ChartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("mnitlbPositionSizeDollarsEachTradeConstant_UserTyped");
			} catch (Exception ex) {
				Assembler.PopupException("mnitlbPositionSizeDollarsEachTradeConstant_UserTyped()", ex);
			}
		}
		void mnitlbShowLastBars_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			try {
				string userTyped = e.StringUserTyped;
				int userTypedInteger;
				bool validInteger = Int32.TryParse(userTyped, out userTypedInteger);
				if (validInteger == false) {
					e.HighlightTextWithRed = true;
					return;
				}
				if (userTypedInteger < 0) {
					e.HighlightTextWithRed = true;
					return;
				}
				
				ContextChart context = this.ChartFormManager.ContextCurrentChartOrStrategy;
				context.DataRange = (userTypedInteger == 0) ? new BarDataRange() : new BarDataRange(userTypedInteger);

				this.mnitlbShowLastBars.BackColor = Color.Gainsboro;
				this.mniShowBarRange.Checked = false;
				this.mniShowBarRange_Click(sender, null);

				this.ChartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("mnitlbShowLastBars_UserTyped");
			} catch (Exception ex) {
				Assembler.PopupException("mnitlbShowLastBars_UserTyped()", ex);
			}
		}
		void mniltbStrategyDuplicateTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string msig = "StrategiesTree.mniStrategyDuplicate_Click(): ";
			if (this.FolderSelected == null) {
				string msg = "this.FolderSelected==null; please set mniFolderCreate.Enabled=false when right-clicked not on the folder";
				statusReporter.PopupException(new Exception(msig + msg));
				return;
			}
			if (this.StrategySelected == null) {
				string msg = "this.StrategySelected==null";
				statusReporter.PopupException(new Exception(msig + msg));
				return;
			}

			Strategy strategyNew = null;
			string strategyNameUserTyped = e.StringUserTyped;
			try {
				strategyNew = strategyRepository.StrategyDuplicate(this.StrategySelected, strategyNameUserTyped);
			} catch (Exception ex) {
				statusReporter.PopupException(ex);
				return;
			} finally {
				this.tree.RebuildAll(true);
			}

			this.tree.SelectObject(strategyNew, true); // does it work??
			this.StrategySelected = strategyNew;
			//var olvStrategy = this.treeListView.FindItemWithText(strategyNew.Name, true, 0); // finds first occurency, not what I've inserted!
			//var olvStrategy = this.tree.ModelToItem(strategyNew);
			//this.tree.EditSubItem(olvStrategy as OLVListItem, 0);
			e.RootHandlerShouldCloseParentContextMenuStrip = true;

			this.RaiseOnStrategyDuplicated(msig);
		}
		void mniltbFolderCreate_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string msig = "StrategiesTree.mniltbFolderCreate_UserTyped(): ";
			string folderNew = e.StringUserTyped;
			try {
				if (string.IsNullOrEmpty(folderNew)) folderNew = strategyRepository.GenerateFolderName();
				strategyRepository.FolderAdd(folderNew, false);
				e.RootHandlerShouldCloseParentContextMenuStrip = true;
			} catch (Exception ex) {
				statusReporter.PopupException(ex);
				return;
			}

			this.FolderSelected = folderNew;
			this.tree.SetObjects(this.strategyRepository.AllFoldersAvailable);
			this.tree.SelectObject(folderNew, true); // does it work??
			//var olvStrategy = this.treeListView.FindItemWithText(strategyNew.Name, true, 0); // finds first occurency, not what I've inserted!
			//var olvStrategy = this.tree.ModelToItem(folderNew);
			//this.tree.EditSubItem(olvStrategy as OLVListItem, 0);

			this.RaiseOnFolderCreated(msig);
		}
		void mniltbFolderRename_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string stringUserTyped = e.StringUserTyped;
			if (this.FolderSelected == stringUserTyped) return;
			try {
				stringUserTyped = this.strategyRepository.FolderRenameModifyNameTillNoException(this.FolderSelected, stringUserTyped);
				this.strategyRepository.FolderRename(this.FolderSelected, stringUserTyped);
				this.FolderSelected = stringUserTyped;
				this.tree.SetObjects(this.strategyRepository.AllFoldersAvailable);
				this.tree.RebuildAll(true);
				e.RootHandlerShouldCloseParentContextMenuStrip = true;
			} catch (Exception ex1) {
				e.HighlightTextWithRed = true;
				this.statusReporter.PopupException(ex1);
			}
		}
		void mniltbCsvSeparator_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			this.dataSnapshot.CsvDelimiter = e.StringUserTyped;
			this.dataSnapshotSerializer.Serialize();
			this.stepsAllparseFromDataSnapshot();
		}
		public void WorkspaceRenameTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			string workspaceRenameToName = e.StringUserTyped;
			Assembler.PopupException("NotImplementedException WorkspaceRenameTo_UserTyped(" + e.StringUserTyped + ")");
		}
		void mniltbSymbolRenameTo_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) {
			if (this.DataSourceSelected == null) {
				Assembler.PopupException("mnitlbSymbolRenameTo_UserTyped(): this.DataSourceSelected=null");
				return;
			}
			this.dataSourceRepository.SymbolRename(this.DataSourceSelected, this.SymbolSelected, e.StringUserTyped, this);
			this.SelectSymbol(this.DataSourceSelected.Name, e.StringUserTyped);
			e.RootHandlerShouldCloseParentContextMenuStrip = true;
		}