The same imported report does not get the parameter value - c#

I am importing the same report 3 times. For each iteration, I am passing a different value, but the problem is that only the first imported report gets the value, the other two are blank. Here is my code:
foreach (var current in reportParameterList)
{
if (string.IsNullOrEmpty(current.SubreportName))
{
document.SetParameterValue(current.Name, current.Value);
}
else
{
document.SetParameterValue(current.Name, current.Value, current.SubreportName);
}
}
So, for the where is subreport name blank, that is for the main report, the else case is for my subreports. So, the same report, imported 3 times doesn't show the value on the second and third.
UPDATE:
The method for filling values for subreports:
for (int i = 0; i < _reportLayoutConfiguration.ReportLayout.Count; i++)
{
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest1.rpt")
{
SetSectionOneReportParameters(reportParameterList);
}
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest2.rpt")
{
SetSectionTwoReportParameters(reportParameterList);
}
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest3.rpt")
{
SetSectionThreeReportParameters(reportParameterList);
}
}
private void SetSectionOneReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterOne_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest1.rpt" });
}
private void SetSectionTwoReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterTwo_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest2.rpt" });
}
private void SetSectionThreeReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterThree_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest3.rpt" });
}
Of course, this is for testing only.

Related

how to make a grid with the local space Unity?

I am gridding around an object but I need the grid to align in the local space of the pivot object
the code that i have
private void createColum()
{
for (int i =0; i<gridGame.Count;i++)
{
if(gridGame[i] == gridGame[0])
{
gridGame[i].localPosition = gridGame[0].localPosition;
}
if(gridGame[i]!= gridGame[0])
{
gridGame[i].localPosition = new Vector3(gridGame[i-1].localPosition.x + distX,gridGame[0].localPosition.y, gridGame[0].localPosition.z);
}
if(i +1 > limiteFila)
{
if(i%limiteFila==0)
{
gridGame[i].localPosition = new Vector3(gridGame[0].position.x, gridGame[0].position.y , gridGame[i-Mathf.RoundToInt(limiteFila)].position.z + distY);
}else
{
gridGame[i].position = new Vector3(gridGame[i-1].position.x + distX, gridGame[0].position.y , gridGame[i-1].position.z);
}
}
gridGame[i].rotation = gridGame[0].rotation;
}
}
with this the grid of objects is formed but only in taking the world space
picture of how you are at this moment
I'm not sure if this will help, but you can turn the grid into a child object and leave the worldPositionStays as false, to do so use the SetParent(Transform parent, bool worldPositionStays). For example as a reference for your script.
private void createColum()
{
for (int i =0; i<gridGame.Count;i++)
{
if(gridGame[i] == gridGame[0])
{
gridGame[i].localPosition = gridGame[0].localPosition;
gridGame[i].transform.SetParent(this.transform, false);
}
if(gridGame[i]!= gridGame[0])
{
gridGame[i].localPosition = new Vector3(gridGame[i-1].localPosition.x + distX,gridGame[0].localPosition.y, gridGame[0].localPosition.z);
}
if(i +1 > limiteFila)
{
if(i%limiteFila==0)
{
gridGame[i].localPosition = new Vector3(gridGame[0].position.x, gridGame[0].position.y , gridGame[i-Mathf.RoundToInt(limiteFila)].position.z + distY);
}else
{
gridGame[i].position = new Vector3(gridGame[i-1].position.x + distX, gridGame[0].position.y , gridGame[i-1].position.z);
}
}
gridGame[i].rotation = gridGame[0].rotation;
}
}

From List to Graphical Interface

I'm creating a shop inside my game to buy virtual goods.
Main Shop Page
Each group has its own items. I've created a view where only one item is visible each time, with buttons to go to the previous and next item.
Specific group selection Menu - Teams
The question is that I don't know how to show the list where I have the items, in that last window and make that touching the buttons previous/next the list shows the different items.
Each item inside the list is called inventory[x] (x = the number in the loop) and has the properties itemName and itemDescription.
How can I make the code communicate with the graphical user interface?
I've created 6 inventory lists (each one for one type of unlockable virtual good) and I use GameSparks API for online features such a player profile.
The lists are declared at the beginning of the script:
public static List<Inventario> inventarioEquipos = new List<Inventario>(); //Inventory for Teams
public static List<Inventario> inventarioPelotas = new List<Inventario>(); //Inventory for Balls
public static List<Inventario> inventarioModos = new List<Inventario>(); //Inventory for Modes
public static List<Inventario> inventarioVitores = new List<Inventario>(); //Inventory for Cheers
public static List<Inventario> inventarioCampos = new List<Inventario>(); //Inventory for Fields
public static List<Inventario> inventarioFondos = new List<Inventario>(); //Inventory for Backgrounds
In the Awake method I call:
Info_Botones ("Equipos"); //I call this function for each group, to load its items and show how many items of a total of X the player owns. If you look at the first picture, will see below TEAMS: 1/2. That's what this function is for (besides to load all the unlockables in separated lists).
Info_Botones ("Pelotas");
Info_Botones ("Modos");
Info_Botones ("Vitores");
Info_Botones ("Campos");
Info_Botones ("Fondos");
The code of the main function is as follows:
private void Info_Botones(string tipoDeInventario) { //"tipoDeInventario" means InventoryType and I use it to pass to the function which type of inventory I want to load (Teams, Balls, Modes, Cheers, Fields or Backgrounds)
int numero = 0;
new LogEventRequest()
.SetEventKey("INVENTARIO")
.SetEventAttribute("TAG_TYPE", tipoDeInventario)
.Send((response) =>
{
if (!response.HasErrors)
{
List<object> entryList = response.ScriptData.GetObjectList("result") as List<object>;
for (int i = 0; i < entryList.Count; i++)
{
Dictionary<string, object> entry = entryList[i] as Dictionary<string, object>;
int itemId = i;
string itemName = (entry["name"]).ToString();
string itemDescription = (entry["description"]).ToString();
int itemPrice = int.Parse((entry["currency1Cost"].ToString()));
string itemInteractable = (entry["interactable"]).ToString();
Inventario inv = new Inventario(itemId, itemName, itemDescription, itemPrice, itemInteractable);
if(tipoDeInventario == "Equipos") {
inventarioEquipos.Add(inv);
if (inventarioEquipos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Pelotas") {
inventarioPelotas.Add(inv);
if (inventarioPelotas[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Modos") {
inventarioModos.Add(inv);
if (inventarioModos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Vitores") {
inventarioVitores.Add(inv);
if (inventarioVitores[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Campos") {
inventarioCampos.Add(inv);
if (inventarioCampos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Fondos") {
inventarioFondos.Add(inv);
if (inventarioFondos[i].itemInteractable == "False") {
numero++;
}
} else {
}
}
if(tipoDeInventario == "Equipos") {
txtBtnCantidadEquipos.text = numero.ToString() + "/" + inventarioEquipos.Count;
} else if(tipoDeInventario == "Pelotas") {
txtBtnCantidadPelotas.text = numero.ToString() + "/" + inventarioPelotas.Count;
} else if(tipoDeInventario == "Modos") {
txtBtnCantidadModos.text = numero.ToString() + "/" + inventarioModos.Count;
} else if(tipoDeInventario == "Vitores") {
txtBtnCantidadVitores.text = numero.ToString() + "/" + inventarioVitores.Count;
} else if(tipoDeInventario == "Campos") {
txtBtnCantidadCampos.text = numero.ToString() + "/" + inventarioCampos.Count;
} else if(tipoDeInventario == "Fondos") {
txtBtnCantidadFondos.text = numero.ToString() + "/" + inventarioFondos.Count;
} else {
}
}
else
{
Debug.Log("ERROR AL OBTENER VG DEL JUGADOR: " + response.Errors.JSON);
}
});
}
I've achieved it using IF condictions. If anyone needs the code, ask for it and I will share it (I'm not at home right now).
Thanks!

DropDownList not modifying binding

I have a DropDownListFor which is bound to a field in my model called BinRangeSelection. When I select a value in this drop downlist, the BinRangeSelection value does not change, it remains null. Here is my drop down:
#Html.DropDownListFor(m => m.BinRangeSelection, new SelectList(Model.BinRanges), "Select BIN Range", new { id = "BinRangesDropDown_start", #class = "five columns" })
And my BinRangeSelection String:
private String _BinRangeSelection;
public String BinRangeSelection
{
get
{
return _BinRangeSelection;
}
set
{
System.Diagnostics.Debug.WriteLine("testing");
string[] rangeSplit = Regex.Split(value, " - ");
foreach (IdentifiBINConfiguration ibc in IdentifiBINConfigs)
{
if (ibc.LowerRange == rangeSplit[0] && ibc.UpperRange == rangeSplit[1])
{
IdentifiBINConfiguration = ibc;
}
}
_BinRangeSelection = value;
BinRangeSelection = value;
}
}
That testing statement is never printing to the console, and I've placed break points and nothing in the set function is being called.

Datagridview adds up unwanted rows

The last line of this code is supposed to fill in a row with 3 columns in a datagridview every time the variable "temperature" and "umidita" are shown in the relevant text boxes.
These data comes from the serial port and get updated every x seconds.
private void SetText(string text)
{
string temperatura;
string umidita;
if (this.txtOutput.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.BeginInvoke(d, new object[] { text });
}
else
{
string f = text;
char firstChar = f[0];
if (firstChar == 'T')
{
temperatura = f;
temperatura = f.Replace("T", "");
textBox1.Text = temperatura;
}
else if (firstChar == 'U')
{
umidita = f;
umidita = f.Replace("U", "");
textBox2.Text = umidita;
}
dataGridView1.Rows.Add(new string[] { DateTime.Now.ToString("HH:mm:ss"), textBox1.Text, textBox2.Text });
}
}
The code is working but I get 3 rows at time filled in with the same data.
I am not familiar with datagridview and I do not understand why I am getting such behavior. What do I need to change to get one row at time filled in with time, "temperatura" and "umidita"?
////you can check if you already inserted a row in this time
int rowsCount = dataGridView1.Rows.Count;
string cuurentTime = DateTime.Now.ToString("HH:mm:ss");
if (cuurentTime != dataGridView1.Rows[rowsCount - 1].Cells[0].Value.ToString())
{
dataGridView1.Rows.Add(new string[] { cuurentTime, textBox1.Text, textBox2.Text });
}

How do I edit the name of an item in a CheckedListBox?

I have a CheckedListBox that has X number of items. These items are placed there at runtime. These items are supposed to represent reports that can be displayed in the DataGridView. What I need to do now is display the record count for each report in parenthesis right next to the report name. I tried, not for too long, to edit the actual name of the item but couldn't find out how to do it. So then, I brute forced it. Saved the items to an array, cleared the items, appended the record counts to each item in the array, created new items. Well, this has caused issues because now it's not retaining my checks and the reason why is because whenever I generate the reports, I clear the items and recreate them. Well, rather than doing another foreach loop to save the checked status, does anyone know of a way to change the text of existing items in a CheckedListBox?
Here is the code I currently have:
In the MainForm.Designer.cs:
this.clbReports.Items.AddRange(new object[] {
"Report 1",
"Report 2",
"Report 3",
"Report 4",
"Report 5",
"Report 6",
"Report 7",
"Report 8",
"Report 9",
"Report 10",
"Report 11"});
And it looks like:
And I want it to look like (but there won't all be 0's):
Here is the SelectedIndexChanged function:
private void clbReports_SelectedIndexChanged(object sender, EventArgs e)
{
string strCheckBox = clbReports.SelectedItem.ToString();
bool bShowAllIsChecked = clbReports.GetItemChecked(clbReports.FindString("Show All Error Reports"));
bool bSelected = clbReports.GetItemChecked(clbReports.FindString(strCheckBox));
int nIndex = -1;
if (strCheckBox.Contains("Show All Error Reports"))
{
foreach (string str in _strReports)
{
if (!str.Contains("Show All Error Reports") && !str.Contains("Show Tagged Records"))
{
nIndex = clbReports.FindString(str);
if (nIndex > -1)
{
clbReports.SetItemChecked(nIndex, bSelected);
}
}
}
}
else
{
if (strCheckBox.Contains("Show All Error Reports") || bShowAllIsChecked)
{
foreach (string str in _strReports)
{
nIndex = clbReports.FindString(str);
if (nIndex > -1)
{
clbReports.SetItemChecked(nIndex, false);
}
}
}
nIndex = clbReports.FindString(strCheckBox);
if (nIndex > -1)
{
clbReports.SetItemChecked(nIndex, bShowAllIsChecked ? true : bSelected);
}
}
string[] strCheckedItems = new string[clbReports.CheckedItems.Count];
clbReports.CheckedItems.CopyTo(strCheckedItems, 0);
List<string> checkBoxReportFilter = new List<string>();
foreach (ReportRecord obj in this._lstReportRecords)
{
foreach (string str in strCheckedItems)
{
if (str.Contains(obj.Description))
{
checkBoxReportFilter.Add(obj.PartID.ToString());
}
}
}
try
{
if (checkBoxReportFilter.Count == 0 && clbReports.CheckedItems.Count > 0)
{
throw new NullReferenceException();
}
_strReportFilter = String.Join(",", checkBoxReportFilter.ToArray());
}
catch (NullReferenceException)
{
_strReportFilter = "-1";
}
generateReport();
}
And here is the code where I am clearing the items, getting the report counts and creating the new items.
_lstReportRecords = _dataController.ReportList;
bool[] bChecked = new bool[clbReports.Items.Count];
int nCounter = 0;
foreach (string str in _strReports)
{
foreach (string str2 in clbReports.SelectedItems)
{
bChecked[nCounter] = str2.Contains(str);
}
nCounter++;
}
clbReports.Items.Clear();
nCounter = 0;
foreach (string str in _strReports)
{
int nCount = _lstReportRecords.Where<ReportRecord>(delegate(ReportRecord rr) {
return rr.Description == str;
}).Count();
string newReport = str + " (" + nCount + ")";
clbReports.Items.Add(newReport);
clbReports.SetItemChecked(nCounter, bChecked[nCounter]);
nCounter++;
}
Please tell me there is an easier way to do this. I tried doing foreach loops through the clbReports.Items but it wants me to cast it to a string (errored on me when trying to cast to a CheckBox) so I couldn't change the value. And even if I could cast it to a CheckBox, I have a feeling it will give me the error that Enumeration has failed because the list has been changed (or however they word it). Any and all help is welcome. Thanks.
Edit: Please know that the Report X are just so that the actual report names aren't displayed to keep it generic. However, in the code, I just copied and pasted so the Show All Error Reports and Show All Tagged Records are reports I need to check.
The right ( == most simple and most direct) answer and solution is:
this.clbReports.Items[nIndex] = "new text of the item"
yes, those items are of type "object". No, nobody minds that, string is an object too ;)
If I were you, I'd try to give the INotifyPropertyChanged Interface a go.
You Shouldn't mess with events unless necessary. this will mean you can't use the designer to create the items, but as far as I've understood, it's a runtime-modified list anyway...
In detail:
• Create A Class (e.g.'Foo') that Implements INotifyPropertyChanged (Basically this will tell any listener that the text property has changed). This class will hold the names of all entries.
• create an ObservableCollection and bind your CheckedListBox to that Collection. In WinForms you will have to create a DataBindingSource and plug your Collection to one end and the ComboBox to the other end.
• Any change made to the collection will be visible in the control.
HTH
Sebi
In order to change the items in a ListBox (or a CheckedListBox), you should change these items' ToString() result.
The easiest solution would be to create a "Holder" class, which has a reference to the report it represents. Then the Holder class' ToString() method should be something like this:
public override string ToString()
{
return String.Format("{0} ({1})", BaseStr, MyReport.RecordCount);
}
If you change MyReport.RecordCount somehow (because a report's record count changes), you can just call clbReports.Refresh(), and it'll automatically show the new value.
I think this way you don't even need the temporary array solution in the second code block; however, I'd like to suggest an alternative way of getting the item's checked state.
You can iterate through the clbReports.CheckedIndices, and fill your bChecked array with true values only for indices in that array.
Well, due to time constraints I tried something else. I went with a ListView where CheckBoxes = true and View = List. I also removed Show All Error Reports and Show Tagged Records to checkboxes outside of the list. This made it a lot easier to do the functions I wanted. Here is the new code.
MainForm.Designer.cs
//
// cbTaggedRecords
//
this.cbTaggedRecords.AutoSize = true;
this.cbTaggedRecords.Location = new System.Drawing.Point(151, 9);
this.cbTaggedRecords.Name = "cbTaggedRecords";
this.cbTaggedRecords.Size = new System.Drawing.Size(106, 17);
this.cbTaggedRecords.TabIndex = 3;
this.cbTaggedRecords.Text = "Tagged Records";
this.cbTaggedRecords.UseVisualStyleBackColor = true;
this.cbTaggedRecords.CheckedChanged += new System.EventHandler(this.ShowTaggedRecords_CheckChanged);
//
// cbAllErrorReports
//
this.cbAllErrorReports.AutoSize = true;
this.cbAllErrorReports.Location = new System.Drawing.Point(6, 9);
this.cbAllErrorReports.Name = "cbAllErrorReports";
this.cbAllErrorReports.Size = new System.Drawing.Size(102, 17);
this.cbAllErrorReports.TabIndex = 2;
this.cbAllErrorReports.Text = "All Error Reports";
this.cbAllErrorReports.UseVisualStyleBackColor = true;
this.cbAllErrorReports.CheckedChanged += new System.EventHandler(this.ShowAllErrorReports_CheckChanged);
//
// listView1
//
this.listView1.CheckBoxes = true;
listViewItem1.StateImageIndex = 0;
listViewItem2.StateImageIndex = 0;
listViewItem3.StateImageIndex = 0;
listViewItem4.StateImageIndex = 0;
listViewItem5.StateImageIndex = 0;
listViewItem6.StateImageIndex = 0;
listViewItem7.StateImageIndex = 0;
listViewItem8.StateImageIndex = 0;
listViewItem9.StateImageIndex = 0;
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
listViewItem3,
listViewItem4,
listViewItem5,
listViewItem6,
listViewItem7,
listViewItem8,
listViewItem9});
this.listView1.Location = new System.Drawing.Point(6, 29);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(281, 295);
this.listView1.TabIndex = 1;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.listView_ItemChecked);
MainForm.cs
private void listView_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (e != null)
{
int nLength = e.Item.Text.IndexOf("(") - 1;
string strReport = nLength <= 0 ? e.Item.Text : e.Item.Text.Substring(0, nLength);
if (e.Item.Checked)
{
_lstReportFilter.Add(strReport);
}
else
{
_lstReportFilter.Remove(strReport);
}
}
List<string> checkBoxReportFilter = new List<string>();
foreach (ReportRecord obj in this._lstReportRecords)
{
foreach (string str in _lstReportFilter)
{
if (str.ToLower().Contains(obj.Description.ToLower()))
{
checkBoxReportFilter.Add(obj.PartID.ToString());
}
}
}
try
{
if (checkBoxReportFilter.Count == 0 && listView1.CheckedItems.Count > 0)
{
throw new NullReferenceException();
}
_strReportFilter = String.Join(",", checkBoxReportFilter.ToArray());
}
catch (NullReferenceException)
{
_strReportFilter = "-1";
}
if (!bShowAll)
{
generateReport();
}
}
private void ShowAllErrorReports_CheckChanged(object sender, EventArgs e)
{
bShowAll = true;
foreach (ListViewItem lvi in listView1.Items)
{
lvi.Checked = ((CheckBox)sender).Checked;
}
_lstReportFilter.Clear();
bShowAll = false;
generateReport();
}
private void ShowTaggedRecords_CheckChanged(object sender, EventArgs e)
{
bool bChecked = ((CheckBox)sender).Checked;
if (bChecked)
{
if (!_lstReportFilter.Contains("Show Tagged Records"))
{
_lstReportFilter.Add("Show Tagged Records");
}
}
else
{
_lstReportFilter.Remove("Show Tagged Records");
}
listView_ItemChecked(null, null);
}
Code to add counts to CheckBoxes
_lstReportRecords = _dataController.ReportList;
int nTotalCount = 0;
foreach (ListViewItem lvi in listView1.Items)
{
int nCount = _lstReportRecords.Where(rr => lvi.Text.Contains(rr.Description)).Count();
nTotalCount += nCount;
lvi.Text = (lvi.Text.Contains("(") ? lvi.Text.Substring(0, lvi.Text.IndexOf("(") + 1) : lvi.Text + " (") + nCount.ToString() + ")";
}
cbAllErrorReports.Text = (cbAllErrorReports.Text.Contains("(") ? cbAllErrorReports.Text.Substring(0, cbAllErrorReports.Text.IndexOf("(") + 1) : cbAllErrorReports.Text + " (") + nTotalCount.ToString() + ")";
int nTaggedCount = _lstReportRecords.Where(rr => rr.Description.Contains("Tagged")).Count();
cbTaggedRecords.Text = (cbTaggedRecords.Text.Contains("(") ? cbTaggedRecords.Text.Substring(0, cbTaggedRecords.Text.IndexOf("(") + 1) : cbTaggedRecords.Text + " (") + nTaggedCount.ToString() + ")";
Thank you all for your help and ideas.

Categories