/// <summary>Returns the required height.</summary>
        private int ArrangeControls(Graphics g)
        {
            //580 is the initial width of the panel
            int inputW  = 280;               //The input section on the right.
            int promptW = 580 - 20 - inputW; //20 is for the scrollbar on the right

            panelMain.Controls.Clear();
            int yPos  = 5;
            int itemH = 0;          //item height

            labels = new Label[Parameters.Count];
            inputs = new Control[Parameters.Count];
            for (int i = 0; i < Parameters.Count; i++)
            {
                //Calculate height
                itemH = (int)g.MeasureString(Parameters[i].Prompt, Font, promptW).Height;
                if (itemH < 20)
                {
                    itemH = 20;
                }
                //promptingText
                labels[i]          = new Label();
                labels[i].Location = new Point(5, yPos);
                //labels[i].Name="Label"+i.ToString();
                labels[i].Size      = new Size(promptW - 8, itemH);
                labels[i].Text      = Parameters[i].Prompt;
                labels[i].TextAlign = ContentAlignment.MiddleRight;
                //labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
                panelMain.Controls.Add(labels[i]);
                if (Parameters[i].ValueType == ParamValueType.Boolean)
                {
                    //add a checkbox
                    inputs[i]          = new CheckBox();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    if (Parameters[i].CurrentValues.Count == 0)
                    {
                        ((CheckBox)inputs[i]).Checked = false;
                    }
                    else
                    {
                        ((CheckBox)inputs[i]).Checked = true;
                    }
                    ((CheckBox)inputs[i]).FlatStyle = FlatStyle.System;
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.Date)
                {
                    //add a validDate box
                    inputs[i]          = new ValidDate();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    ;
                    if (Parameters[i].CurrentValues.Count > 0)
                    {
                        DateTime myDate = (DateTime)Parameters[i].CurrentValues[0];
                        inputs[i].Text = myDate.ToShortDateString();
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.Enum)
                {
                    //add a psuedo combobox filled with values for one enumeration
                    inputs[i] = new ComboBoxMulti();
                    Type eType = Type.GetType("ODR." + Parameters[i].EnumerationType.ToString());
                    for (int j = 0; j < Enum.GetNames(eType).Length; j++)
                    {
                        ((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
                        if (Parameters[i].CurrentValues.Count > 0 &&
                            Parameters[i].CurrentValues
                            .Contains((int)(Enum.Parse(eType, Enum.GetNames(eType)[j]))))
                        {
                            ((ComboBoxMulti)inputs[i]).SetSelected(j, true);
                        }
                    }
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.Integer)
                {
                    //add a validNumber box
                    inputs[i]          = new ValidNumber();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    if (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((int)Parameters[i].CurrentValues[0]).ToString();
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.Number)
                {
                    //add a validDouble box
                    inputs[i]          = new ValidDouble();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    if (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((double)Parameters[i].CurrentValues[0]).ToString("n");
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.String)
                {
                    //add a textbox
                    inputs[i]          = new TextBox();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    //inputs[i].Name=
                    inputs[i].Size = new Size(inputW - 5, 20);
                    if (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = Parameters[i].CurrentValues[0].ToString();
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                yPos += itemH + 5;
                //if(yPos>panelMain.Height && !vScrollBar2.Visible)
                //	return yPos;//There's not enough room, so stop and make the scrollbar visible.
            }
            //panelSlide.Height=yPos;
            //vScrollBar2.Maximum=panelSlide.Height;
            //vScrollBar2.Minimum=0;
            //vScrollBar2.LargeChange=panelMain.Height;
            //vScrollBar2.SmallChange=5;
            return(yPos);
        }
        /*
         * ///<summary></summary>
         * public void AddInputItem(string myPromptingText,ParamValueType myValueType,ArrayList myCurrentValues,EnumType myEnumerationType,DefCat myDefCategory,ReportFKType myFKType){
         *      MultInput2.AddInputItem(myPromptingText,myValueType,myCurrentValues,myEnumerationType,myDefCategory,myFKType);
         * }*/

        /*
         * ///<summary>After this form closes, use this method to retrieve the data that the user entered.</summary>
         * public ArrayList GetCurrentValues(int itemIndex){
         *      return MultInput2.GetCurrentValues(itemIndex);
         * }*/

        //private void contrParamInput_SizeChanged(object sender, System.EventArgs e) {
        //	Height=contrParamInput.Bottom+90;
        //	Refresh();//this should trigger another layout
        //}

        private void butOK_Click(object sender, System.EventArgs e)
        {
            //make sure all entries are valid
            for (int i = 0; i < Parameters.Count; i++)
            {
                if (Parameters[i].ValueType == ParamValueType.Date)
                {
                    if (((ValidDate)inputs[i]).errorProvider1.GetError(inputs[i]) != "")
                    {
                        MessageBox.Show("Please fix data entry errors first.");
                        return;
                    }
                }
                if (Parameters[i].ValueType == ParamValueType.Integer)
                {
                    if (((ValidNumber)inputs[i]).errorProvider1.GetError(inputs[i]) != "")
                    {
                        MessageBox.Show("Please fix data entry errors first.");
                        return;
                    }
                }
                if (Parameters[i].ValueType == ParamValueType.Number)
                {
                    if (((ValidDouble)inputs[i]).errorProvider1.GetError(inputs[i]) != "")
                    {
                        MessageBox.Show("Please fix data entry errors first.");
                        return;
                    }
                }
            }
            //then fill the current values and output value.  For most fields, the length of CurrentValues will be 0 or 1.
            for (int i = 0; i < Parameters.Count; i++)
            {
                Parameters[i].CurrentValues = new ArrayList();
                if (Parameters[i].ValueType == ParamValueType.Boolean)
                {
                    if (((CheckBox)inputs[i]).Checked)
                    {
                        Parameters[i].CurrentValues.Add(true);
                    }
                }
                else if (Parameters[i].ValueType == ParamValueType.Date)
                {
                    Parameters[i].CurrentValues.Add(PIn.Date(inputs[i].Text));
                }

                /*else if(Parameters[i].ValueType==ParamValueType.Def){
                 *      ComboBoxMulti comboBox=(ComboBoxMulti)inputs[i];
                 *      for(int j=0;j<comboBox.SelectedIndices.Count;j++){
                 *              retVal.Add(
                 *                      Defs.Short[(int)Parameters[i].DefCategory]
                 *                      [(int)comboBox.SelectedIndices[j]].DefNum);
                 *      }
                 * }*/
                else if (Parameters[i].ValueType == ParamValueType.Enum)
                {
                    ComboBoxMulti comboBox = (ComboBoxMulti)inputs[i];
                    Type          eType    = Type.GetType("ODR." + Parameters[i].EnumerationType.ToString());
                    for (int j = 0; j < comboBox.SelectedIndices.Count; j++)
                    {
                        Parameters[i].CurrentValues.Add((int)(Enum.Parse(eType, Enum.GetNames(eType)[(int)comboBox.SelectedIndices[j]])));
                    }
                }
                else if (Parameters[i].ValueType == ParamValueType.Integer)
                {
                    Parameters[i].CurrentValues.Add(PIn.Long(inputs[i].Text));
                }
                else if (Parameters[i].ValueType == ParamValueType.Number)
                {
                    Parameters[i].CurrentValues.Add(PIn.Double(inputs[i].Text));
                }
                else if (Parameters[i].ValueType == ParamValueType.String)
                {
                    if (inputs[i].Text != "")
                    {
                        //the text is first stripped of any ?'s
                        Parameters[i].CurrentValues.Add(inputs[i].Text.Replace("?", ""));                       //Regex.Replace(inputs[i].Text,@"\?",""));
                    }
                }
                Parameters[i].FillOutputValue();
                //MessageBox.Show(multInputItems[1].CurrentValues.Count.ToString());
                //return retVal;
            }
            DialogResult = DialogResult.OK;
        }
Exemple #3
0
		/// <summary>Returns the required height.</summary>
		private int ArrangeControls(Graphics g){
			//580 is the initial width of the panel
			int inputW=280;//The input section on the right.
			int promptW=580-20-inputW;//20 is for the scrollbar on the right
			panelMain.Controls.Clear();
			int yPos=5;
			int itemH=0;//item height
			labels=new Label[Parameters.Count];
			inputs=new Control[Parameters.Count];
			for(int i=0;i<Parameters.Count;i++){
				//Calculate height
				itemH=(int)g.MeasureString(Parameters[i].Prompt,Font,promptW).Height;
				if(itemH<20)
					itemH=20;
				//promptingText
				labels[i]=new Label();
				labels[i].Location=new Point(5,yPos);
				//labels[i].Name="Label"+i.ToString();
				labels[i].Size=new Size(promptW-8,itemH);
				labels[i].Text=Parameters[i].Prompt;
				labels[i].TextAlign=ContentAlignment.MiddleRight;
				//labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
				panelMain.Controls.Add(labels[i]);
				if(Parameters[i].ValueType==ParamValueType.Boolean){
					//add a checkbox
					inputs[i]=new CheckBox();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					if(Parameters[i].CurrentValues.Count==0)
						((CheckBox)inputs[i]).Checked=false;
					else
						((CheckBox)inputs[i]).Checked=true;
					((CheckBox)inputs[i]).FlatStyle=FlatStyle.System;
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.Date){
					//add a validDate box
					inputs[i]=new ValidDate();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					;
					if(Parameters[i].CurrentValues.Count>0){
						DateTime myDate=(DateTime)Parameters[i].CurrentValues[0];
						inputs[i].Text=myDate.ToShortDateString();
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.Enum){
					//add a psuedo combobox filled with values for one enumeration
					inputs[i]=new ComboBoxMulti();
					Type eType=Type.GetType("ODR."+Parameters[i].EnumerationType.ToString());
					for(int j=0;j<Enum.GetNames(eType).Length;j++){
						((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
						if(Parameters[i].CurrentValues.Count > 0
							&& Parameters[i].CurrentValues
							.Contains((int)(Enum.Parse(eType,Enum.GetNames(eType)[j])))  ) {
							((ComboBoxMulti)inputs[i]).SetSelected(j,true);
						}
					}
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.Integer){
					//add a validNumber box
					inputs[i]=new ValidNumber();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					if(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=((int)Parameters[i].CurrentValues[0]).ToString();
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.Number){
					//add a validDouble box
					inputs[i]=new ValidDouble();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					if(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=((double)Parameters[i].CurrentValues[0]).ToString("n");
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.String){
					//add a textbox
					inputs[i]=new TextBox();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					//inputs[i].Name=
					inputs[i].Size=new Size(inputW-5,20);
					if(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=Parameters[i].CurrentValues[0].ToString();
					}
					panelMain.Controls.Add(inputs[i]);
				}
				yPos+=itemH+5;
				//if(yPos>panelMain.Height && !vScrollBar2.Visible)
				//	return yPos;//There's not enough room, so stop and make the scrollbar visible.
			}
			//panelSlide.Height=yPos;
			//vScrollBar2.Maximum=panelSlide.Height;
			//vScrollBar2.Minimum=0;
			//vScrollBar2.LargeChange=panelMain.Height;
			//vScrollBar2.SmallChange=5;
			return yPos;
		}