Passing properties to a function (only get property error)C# - c#

I have a class thats receive all crystal report req to open the form of the report(a switch and a lot of cases).
and i need to copy and paste every time this code
if (sender.GetType() == typeof(CheckBox))
{
foreach (CheckBox elemento in flowLayoutPanel1.Controls.OfType<CheckBox>())
{
if (elemento.Checked)
{
foreach (string elemento2 in ListaTodos)
{
string Name = elemento.Tag.ToString();
if (Name.Substring(Name.Length - 1, 1) == elemento2.Substring(elemento2.Length - 1, 1))
{
crParceiro.ReportDefinition.ReportObjects[Name].ObjectFormat.EnableSuppress = false;
crParceiro.ReportDefinition.ReportObjects[elemento2].ObjectFormat.EnableSuppress = false;
}
}
}
else
{
foreach (string elemento2 in ListaTodos)
{
string Name = elemento.Tag.ToString();
if (Name.Substring(Name.Length - 1, 1) == elemento2.Substring(elemento2.Length - 1, 1))
{
crParceiro.ReportDefinition.ReportObjects[Name].ObjectFormat.EnableSuppress = true;
crParceiro.ReportDefinition.ReportObjects[elemento2].ObjectFormat.EnableSuppress = true;
}
}
}
}
}
Problem: i created a function and triend to paste this part of code there... and i passed the crParceiro.ReportDefinition, and also crParceiro.ReportDefinition.ReportsObject
but it doesnt have the set property and i cant set it out and return on REF our OUT...
I tried to Return the value and Linq Expressions(it says..."object doesnt have set property") no success
**Reference of Linq Exp and Return Value: **Link here
A good example of the problem are:
ReportDefinition teste = new ReportDefinition();
teste.ReportObjects = null;
//Error: Property or idexer ...cannot be assigned to -- its read only.
what can i do? im very lost..

In the code that you posted you are NOT setting the ReportObjects to null or any other value. You are accesing items of the ReportObjects by index and changing properties of these items but not direcctly on the ReportObjects
So this should work.
private void YourMethod(ReportObjects repObjs, List<string> ListaTodos)
{
foreach (CheckBox elemento in flowLayoutPanel1.Controls.OfType<CheckBox>())
{
bool enableSuppress ;
//enableSuppress changes based on the the "elemento" being checked or not
enableSuppress = !elemento.Checked ;
foreach (string elemento2 in ListaTodos)
{
string Name = elemento.Tag.ToString();
if (Name.Substring(Name.Length - 1, 1) == elemento2.Substring(elemento2.Length - 1, 1))
{
repObjs[Name].ObjectFormat.EnableSuppress = enableSuppress;
repObjs[elemento2].ObjectFormat.EnableSuppress = enableSuppress;
}
}
}
}
Then in your current call you use it like this
if (sender.GetType() == typeof(CheckBox))
{
YourMethod(crParceiro.ReportDefinition.ReportObjects, ListaTodos) ;
}

Related

C#, Newtonsoft, need to get array items not already handled

I have a json array that looks like...
{
"equipment": [{
"date_of_examination": "2022-05-20T14:08:38.072965",
"defect_type": ["DN"],
"eqpt_ref": "AA1",
"eqpt_name": ["2 Leg Chain Sling"],
"eqpt_manufacturer": "Merc",
"eqpt_model": "edes",
"part_no": "A1",
"serial_no": "A1",
"year": "2019",
"swl": "32 tons",
"exam_type": ["6 Months"],
"date_of_last_examination": "2021-11-20T00:00:00",
"date_of_next_examination": "2022-11-20T00:00:00",
"defect": "sling is torn",
"action_required": "replace"
}, {
"date_of_examination": "2022-05-20T14:12:23.997004",
"eqpt_ref": "AA2",
"eqpt_name": ["Other - "],
"eqpt_name_other": "widget",
"eqpt_manufacturer": "merc",
"eqpt_model": "edes",
"part_no": "B1",
"serial_no": "B1",
"year": "2019",
"swl": "32 tons",
"exam_type": ["6 Months"]
}, {
"date_of_examination": "2022-05-20T14:13:24.795136",
"defect_type": ["DF"],
"eqpt_ref": "CC1",
"eqpt_name": ["Endless Round Sling (2.5m)"],
"eqpt_manufacturer": "merc",
"eqpt_model": "edes",
"part_no": "c1",
"serial_no": "c1",
"year": "2019",
"swl": "42 tons",
"exam_type": ["6 Months"],
"defect": "stitching is coming undone",
"danger_value": "6",
"danger_units": ["Weeks"],
"action_required": "needs to be stitched again"
}]
}
I am attempting to loop through the array and filter items as I need, to populate a table later.
The table has three parts.
First, is show all items with a defect_type of "DN". Second is to show all defect_type of "DF", and the last part is to show all the rest (in his case, the one with eqpt_name of AA2)
My original code is...
for (int j = 0; j <= 2; j++)
{
// Note, some table name parts won't have the "Filter..." aspect
// the string below will change depending on which loop we are in.
string[] tableNameParts = "TableStart:equipment:defectNow:Filter:defect_type=DN".Split(':');
string tableNameJson = tableNameParts[1].Replace("»", "");
var jsonRows = IncomingJson[tableNameJson];
if (tableNameParts.Count() > 3)
{
// We probably have a filter set.
if (tableNameParts[3].Replace("»", "").ToLower() == "filter" && tableNameParts.Count() > 4)
{
// These values are not set in stone. It is what values have been set in the JSON, and then matched.
// for example... TableStart:<subform name>:<differentiator>:Filter:<field name>=<field value>
string[] FilterParts = tableNameParts[4].Split('=');
// Get the filter field and value to filter by
if (FilterParts.Count() > 1)
{
string FilterField = FilterParts[0].Replace("»", "");
string FilterValue = FilterParts[1].Replace("»", "");
JArray filteredArray = new JArray();
if (jsonRows[0].GetType() == typeof(JObject))
{
//int loopCount = 0;
foreach (JObject arrayObject in jsonRows) // Each group can have a set of arrays. (each record has multiple sub records)
//for (int i = 0; i < jsonRows.Count(); i++)
{
//JObject arrayObject = jsonRows[i];
foreach (var objectItem in arrayObject)
{
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
{
foreach (var item in objectItem.Value)
{
objectItemValue += item;
}
}
else
{
objectItemValue = (string)objectItem.Value;
}
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
{
// We need to save the item.
filteredArray.Add(arrayObject);
testArray.Add(arrayObject);
//arrayObject["filtered"] = true;
//IncomingJson[tableNameJson][loopCount]["filtered"] = true;
}
}
//loopCount++;
}
}
else
{
foreach (JArray arrayGroup in jsonRows) // The array group (e.g. fault_record_subform)
{
// We are looking through the json array, to find any rows that match our filter key and filter value.
// We will then add that into our jsonRows
//int loopCount = 0;
foreach (JObject arrayObject in arrayGroup) // Each group can have a set of arrays. (each record has multiple sub records)
{
foreach (var objectItem in arrayObject)
{
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
{
foreach (var item in objectItem.Value)
{
objectItemValue += item;
}
}
else
{
objectItemValue = (string)objectItem.Value;
}
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
{
// We need to save the item.
filteredArray.Add(arrayObject);
testArray.Add(arrayObject);
//arrayObject["filtered"] = true;
//IncomingJson[tableNameJson][loopCount]["filtered"] = true;
}
}
}
//loopCount++;
}
}
//filteredArray.CopyTo(testArray, 0);
jsonRows = filteredArray; // limit the jsonRows to the filtered set (overwrite the jsonRows)
}
}
}
else
{
// This is not a filter set
JArray singleArray = new JArray();
foreach(var arraySet in jsonRows)
{
if (!testArray.Intersect(arraySet).Any())
{
if (arraySet.GetType() == typeof(JObject))
{
singleArray.Add(arraySet);
}
else
{
foreach (JObject arrayObject in arraySet)
{
singleArray.Add(arrayObject);
}
}
}
}
jsonRows = singleArray;
}
}
By the time it gets to the "this is not a filter set" (which should be the third iteration of the loop), I need to be able to ignore the other filtered items, but as you might see, I have attempted to mark an item as filtered (then filter out). I have also tried to add the filtered items to an alternative array and use that to filter out. All to no avail.
How do I make it so that the "this is not a filter set" rows can ignore the rows already filtered?
=========== EDIT ==============
After reviewing the link from dbc to the fiddler (I don't have an account on there, and don't know how to link to my changes), I have it running in the fiddler with the code below.
JObject json = JObject.Parse(GetJson());
string[] tableNames = {"TableStart:equipment:defectNow:Filter:defect_type=DN","TableStart:equipment:defectFuture:Filter:defect_type=DF","TableStart:equipment:defectNone"};
for (int j = 0; j <= 2; j++)
{
// Note, some table name parts won't have the "Filter..." aspect
// the string below will change depending on which loop we are in.
string[] tableNameParts = tableNames[j].Split(':');
string tableNameJson = tableNameParts[1].Replace("»", "");
var jsonRows = json[tableNameJson];
if (tableNameParts.Count() > 3)
{
// We probably have a filter set.
if (tableNameParts[3].Replace("»", "").ToLower() == "filter" && tableNameParts.Count() > 4)
{
// These values are not set in stone. It is what values have been set in the JSON, and then matched.
// for example... TableStart:<subform name>:<differentiator>:Filter:<field name>=<field value>
string[] FilterParts = tableNameParts[4].Split('=');
// Get the filter field and value to filter by
if (FilterParts.Count() > 1)
{
string FilterField = FilterParts[0].Replace("»", "");
string FilterValue = FilterParts[1].Replace("»", "");
JArray filteredArray = new JArray();
if (jsonRows[0].GetType() == typeof(JObject))
{
//int loopCount = 0;
foreach (JObject arrayObject in jsonRows) // Each group can have a set of arrays. (each record has multiple sub records)
//for (int i = 0; i < jsonRows.Count(); i++)
{
//JObject arrayObject = jsonRows[i];
foreach (var objectItem in arrayObject)
{
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
{
foreach (var item in objectItem.Value)
{
objectItemValue += item;
}
}
else
{
objectItemValue = (string)objectItem.Value;
}
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
{
// We need to save the item.
filteredArray.Add(arrayObject);
//testArray.Add(arrayObject);
//arrayObject["filtered"] = true;
//IncomingJson[tableNameJson][loopCount]["filtered"] = true;
}
}
//loopCount++;
}
}
else
{
foreach (JArray arrayGroup in jsonRows) // The array group (e.g. fault_record_subform)
{
// We are looking through the json array, to find any rows that match our filter key and filter value.
// We will then add that into our jsonRows
//int loopCount = 0;
foreach (JObject arrayObject in arrayGroup) // Each group can have a set of arrays. (each record has multiple sub records)
{
foreach (var objectItem in arrayObject)
{
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
{
foreach (var item in objectItem.Value)
{
objectItemValue += item;
}
}
else
{
objectItemValue = (string)objectItem.Value;
}
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
{
// We need to save the item.
filteredArray.Add(arrayObject);
//testArray.Add(arrayObject);
//arrayObject["filtered"] = true;
//IncomingJson[tableNameJson][loopCount]["filtered"] = true;
}
}
}
//loopCount++;
}
}
//filteredArray.CopyTo(testArray, 0);
jsonRows = filteredArray; // limit the jsonRows to the filtered set (overwrite the jsonRows)
}
}
}
else
{
// This is not a filter set
JArray singleArray = new JArray();
foreach(var arraySet in jsonRows)
{
//if (!testArray.Intersect(arraySet).Any())
{
if (arraySet.GetType() == typeof(JObject))
{
singleArray.Add(arraySet);
}
else
{
foreach (JObject arrayObject in arraySet)
{
singleArray.Add(arrayObject);
}
}
}
}
jsonRows = singleArray;
}
}
What I need ultimately (the jsonRows will be used elsewhere in my code within the loop) is that the third set will have items not found in the first 2 sets.
After a bit of further experimentation, using dotnetfiddle as introduced to me by #dbc (thank you), I have created a List and added each arrayObject into the list during the filtering stages.
I then during the unfiltered stage check if my arraySet is contained in the List, and if not, then add that item to the remaining jsonRows, thereby giving me the balance of the original list.
As can be seen here...
https://dotnetfiddle.net/ot35Z2

List<T>.addrange() not working

I have property :
public List<RequestCheckListDetail> DocumentChecklistMasterList
{
get
{
if (ViewState["DocumentChecklistMasterList"].IsObjectUsable())
_documentChecklistMasterList = (List<RequestCheckListDetail>)ViewState["DocumentChecklistMasterList"];
else
this._documentChecklistMasterList = new List<RequestCheckListDetail>();
return this._documentChecklistMasterList;
}
set { ViewState["DocumentChecklistMasterList"] = value; }
}
I am trying to add data to it using another list. However another list has different entity, so i am running loop over first list like:
List<RequestCheckListDetail> newList = new List<RequestCheckListDetail>();
int i = 0;
foreach (DocumentCheckListMaster item in list)
{
newList.Add(new RequestCheckListDetail
{
Id = i,
CheckListMaster = item
});
i++;
}
this.DocumentChecklistMasterList.AddRange(newList);
even if newList has items in it, DocumentChecklistMasterList always have 0 items.
I have tried following things:
List<RequestCheckListDetail> newList = new List<RequestCheckListDetail>();
int i = 0;
foreach (DocumentCheckListMaster item in list)
{
this.DocumentChecklistMasterList.Add(new RequestCheckListDetail
{
Id = i,
CheckListMaster = item
});
i++;
}
List<RequestCheckListDetail> newList = new List<RequestCheckListDetail>();
int i = 0;
foreach (DocumentCheckListMaster item in list)
{
this.DocumentChecklistMasterList.Insert(i,
new RequestCheckListDetail {
Id = i,
CheckListMaster = item
});
i++;
}
None of these codes are working properly.
I am still not able to add items to DocumentChecklistMasterList
Please help me:
EDIT:
IsObjectUsable() is extension method i have added to check if object is null
public static bool IsObjectUsable(this object checkObject)
{
bool isUsable = true;
if (checkObject == null || checkObject == DBNull.Value)
{
isUsable = false;
}
return isUsable;
}

C# List.Remove(object)

I have an object which is a List within a List:
public List<List<MyObject>> Grid { get; set; }
I have noticed that sometimes when I do:
Grid[currentShape.ColumnNumber].Remove(currentShape);
It removes two objects from the array.
The way in which I populate the Grid object is if a certain condition is met, then I basically do:
Grid[newShape.ColumnNumber].Add(newShape);
currentShape = newShape;
currentShape is a class variable which I use to move around the object on the screen. Is it because of a Reference Type that when I sometimes do .Remove(), it deletes more than one object from the array? Do I need to extend the .Remove() somehow?
Any help is highly appreciated.
Update - The entire method:
public void MoveIfPossible(MoveDirection direction)
{
List<Shape> neighbouringShapes = new List<Shape>();
switch (direction)
{
case MoveDirection.Right:
if (currentShape.ColumnNumber == utilities.columns.Count - 1)
return;
neighbouringShapes = GetNeighbouringShapes(currentShape.ColumnNumber);
foreach (var s in neighbouringShapes)
{
if (currentShape.Position.X + 1 < s.Position.X && currentShape.Position.Y + currentShape.Texture.Height >= s.Position.Y)
{
return;
}
}
world.Grid[currentShape.ColumnNumber].Remove(currentShape);
world.Grid[currentShape.ColumnNumber + 1].Add(currentShape);
currentShape.Position.X = utilities.columns[currentShape.ColumnNumber + 1].X;
currentShape.ColumnNumber++;
currentShape.Coordinate.X = currentShape.ColumnNumber;
currentShape.Coordinate.Y = world.Grid[currentShape.ColumnNumber].Count - 1;
break;
case MoveDirection.Left:
if (currentShape.ColumnNumber == 0)
return;
neighbouringShapes = GetNeighbouringShapes(currentShape.ColumnNumber - 1);
foreach (var s in neighbouringShapes)
{
if (currentShape.Position.X - 1 > s.Position.X && currentShape.Position.Y + currentShape.Texture.Height >= s.Position.Y)
{
return;
}
}
world.Grid[currentShape.ColumnNumber].Remove(currentShape);
world.Grid[currentShape.ColumnNumber - 1].Add(currentShape);
currentShape.Position.X = utilities.columns[currentShape.ColumnNumber - 1].X;
currentShape.ColumnNumber--;
currentShape.Coordinate.X = currentShape.ColumnNumber;
currentShape.Coordinate.Y = world.Grid[currentShape.ColumnNumber].Count;
break;
}
}

Collection modified during foreach error

I know you can't modify a collection during a foreach, but I should be able to set variable values of the underlying iterator through it. For some reason the method below, every time it executes is giving be the "Collection was modified..." error:
private static IInstrument AdjustForSimpleInstrument(DateTime valueDate, IInstrument temp)
{
var instr = temp;
foreach (var component in instr.Components)
{
component.Schedule.ScheduleRows.RemoveAll(
sr =>
((sr.Payment != null) && (sr.Payment.PaymentDate != null) &&
(sr.Payment.PaymentDate.AdjustedDate.Date <= valueDate.Date)));
if (
!component.ScheduleInputs.ScheduleType.In(ComponentType.Floating, ComponentType.FloatingLeg,
ComponentType.Cap, ComponentType.Floor)) continue;
foreach (var row in component.Schedule.ScheduleRows)
{
var clearRate = false;
if (row.Payment.CompoundingPeriods != null)
{
if (row.Payment.CompoundingPeriods.Count > 0)
{
foreach (
var period in
row.Payment.CompoundingPeriods.Where(
period => ((FloatingRate)period.Rate).ResetDate.FixingDate > valueDate))
{
period.Rate.IndexRate = null;
clearRate = true;
}
}
}
else if (row.Payment.PaymentRate is FloatingRate)
{
if (((FloatingRate)row.Payment.PaymentRate).ResetDate.FixingDate > valueDate)
clearRate = true;
}
else if (row.Payment.PaymentRate is MultipleResetRate)
{
if (
((MultipleResetRate)row.Payment.PaymentRate).ChildRates.Any(
rate => rate.ResetDate.FixingDate > valueDate))
{
clearRate = true;
}
}
if (clearRate)
{
row.Payment.PaymentRate.IndexRate = null;
}
}
}
return temp;
}
Am I just missing something easy here? The loop that is causing the exception is the second, this one:
foreach (var row in component.Schedule.ScheduleRows)
I suspect this is not .NET-framework stuff, so I assume that row is connected to its collection. Modifying the contents of the row, might shift its place inside its collection, thus modifying the collection, which is not allowed during some foreach-operations.
The solution is simple: create a copy of the collection (by using LINQ).
foreach (var row in component.Schedule.ScheduleRows.ToList())
...

Unexpected behaviour of dynamic html rendering a table with data via C#

I'm encountering an unfamiliar problem with functionality. I think it has something to do with scope of a loop, and server-side code operations/manipulation when rendering a page.
Say I want to repeat a Table Row - each hosts a text input, rows and their textboxes are rendered with values according to content of DATABASE "binded" Data.
Everything works perfectly until more requirements are added - READONLY Attribute And event Key (javascript small validation task).
Otherwise it does work, alternating rows via two separated strings that I "inject" with string format on a condition of if row count is odd vs even, then I tried to filter some of columns to have a keypress event bound to a js function and another attribute as a string.
If the string is empty, then end part of the element "declaration" will be empty
if condition was met, then that string is assigned with value "ReadOnly" and js string is assigned with keypress event "calling a function code".
Here's the code. The situation is weird as style attributes, information of current column, columns names, everything does function as expected but those two READONLY Attribute And event Key (javascript small validation task) that do not.
Render a dynamic Table Code
This is the front code, c# code behind is used mostly (to keep a little code client-side as possible)
`ControlsInteraction.WithTable.Design()`
AND
`ControlsInteraction.WithTable.ExtractData()`
are dealing with dynamic functions of rendering and translation of columns names and values
int count = 0;
bool TblOk = DebugTests.Sesseion.SeSn.Raised(DebugTests.Flag.HT_DB_CPA_Table_init_Complete);
if (TblOk)
{
string TextBxRendr = "";//holds Renderd <TD> base String-code
string AltrnatBgColor;
string NoAttribute = "";
string Js_NumericKprss = "onkeypress=\"return onlN(event)\""
string ReadOnly = "READONLY";
var TimesCol = ALLTablesDataSet.Tables[Tbl1.TableName].Columns;
string DtrawTbl1 = Tbl1.TableName;
ControlsInteraction.WithTable.Design Tbldz =
new ControlsInteraction.WithTable.Design();
ControlsInteraction.WithTable.ExtractData DtExtrct =
new ControlsInteraction.WithTable.ExtractData();
foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DtrawTbl].Rows)
{
AltrnatBgColor= Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"),true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>",AltrnatBgColor));
for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{
if (i != (TimesRow.ItemArray.Length - 1))
{
Js_NumericKprss = "onkeypress=\"return onlN(event)\"";
//asking for: current row will Not be read only via its name
if (DtExtrct.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.Comments, DtExtrct.DataRowToInt(TimesRow, "RecordNum")))
Js_NumericKprss = NoAttribute; // same goes with the other manipulation i've needed to implement on each column
TextBxRendr = string.Format(
"<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {4} {5} \\></td>",
TimesCol[i], TimesRow["RecordNum"], TimesRow[i], AltrnatBgColor,Js_NumericKprss,ReadOnly
);
}
else
{
TextBxRendr = string.Format(
"<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{2}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>",
"img",i + 1, AltrnatBgColor
);
}
Response.Write(TextBxRendr);
count++;
}
}
}
Is injected properly and the read only part READONLY Attribute, and event Key - (javascript small validation task)
Either functions on all or none
What am I doing wrong?
answering my own Question aventually answer is
...well everything , including #Patrics Comment Was Wrong
i can just say put good attention to : how to work with DataTable DataRow, DataTable DataColumns
and the relations for and foreach variables scope
use your visual sudio debugger on every line to check on your codes values
i did not have the time to rename variables but if you need to make a dynamic
html table out of a DB table this is the way
foreach (System.Data.DataRow TimesRow in ALLTablesSet.Tables[DrawTbl].Rows)
{
recordNum = RDE.DataRowToInt(TimesRow, "RecordNum");
AltBgCol = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), true);
altBgColOnly = Tbldz.RowsBGColorAlternate(RDE.DataRowToInt(TimesRow, "RecordNum"), false);
Response.Write(string.Format("<tr {0}>", AltBgCol));
for (int i = 0; i < TimesRow.ItemArray.Length; i++)
{
if (i != (TimesRow.ItemArray.Length - 1))
{
Js_NumericKprss = "onkeypress=\"return onlN(event)\""; ReadOnly = "";
if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Comments, i))
{
Js_NumericKprss = ""; ReadOnly = "";
}
else if (RDE.CurrRowIs(TimesRow, HentalDBSchema.HTDB_Cols.TblTimeCPAReport.Fines, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.PhoneExpences, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerDay, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.SalaryPerMonth, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TotalGrossWages, i)
|| RDE.CurrRowIs(TimesRow, MyDBSchema.DBs_Cols.TblCPAReport.TravelFee, i))
{
ReadOnly = "";
Js_NumericKprss = "onkeypress=\"return onlN(event)\"";
}
else
ReadOnly = "READONLY";
TxtRndr = string.Format("<td><input type='text' id=\"{0}_{1}\" value=\"{2} \" style=\"width:50px;{3} border:none; \" class=\"RepTblDataTDs\" {5} {6} \\></td>{4}", TimesCol[i], TimesRow["RecordNum"], TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t", Js_NumericKprss, ReadOnly);
}
else
{
TxtRndr = string.Format("<td><input type='image' id=\"{0}_{1}\" src=\"images/Save.png\" style=\"width:25px;{3}\" style=\"width:25px\" onclick=\"UbpdateTblCPA(this, {1});\" /></td>{4}", "imgBut", i + 1, TimesRow[i], altBgColOnly, Environment.NewLine + "\t\t\t");
}
Response.Write(TxtRndr);
count++;
}
}
i am adding all researches i have made to be more easy on the data extraction and some more methods i have worked on so if u like to use it feel free to ...
public class ControlsInteraction
{
public class WithDDL
{
public class GetSelVal
{
public string AsString(DropDownList DDLToCollectValusFrom)
{
return DDLToCollectValusFrom.SelectedValue;
}
public int AsInt(DropDownList DDLToCollectValusFrom)
{
if(DDLToCollectValusFrom.SelectedValue != null)
return Convert.ToInt32(DDLToCollectValusFrom.SelectedValue);
return 666;
}
}
public List<string> GetListItems_Values(DropDownList DDLToCollectValusFrom)
{
List<string> LST_DDLValues = new List<string>();
foreach (ListItem item in DDLToCollectValusFrom.Items)
{
LST_DDLValues.Add(item.Value);
}
return LST_DDLValues;
}
public List<string> GetListItems_Text(DropDownList DDLToCollectTextFrom)
{
List<string> LST_DDLTEXT = new List<string>();
foreach (ListItem item in DDLToCollectTextFrom.Items)
{
LST_DDLTEXT.Add(item.Text);
}
return LST_DDLTEXT;
}
}
public static class WithPlcHldr
{
public static void AddCtrl(PlaceHolder PlcHldrID, Control CntrID)
{
PlcHldrID.Controls.Add(CntrID);
}
}
public class WithTable
{
public class Design
{
public string RowsBGColorAlternate(int RowCounter, bool AddWithStyleAsStandAlone = false)
{
string BgCol = ""; bool bgclaltrnator;
if (RowCounter > 0)
{
RowCounter++;
bgclaltrnator = (RowCounter % 2) == 0;
if (bgclaltrnator)
BgCol = "#70878F";
else BgCol = "#E6E6B8";
}
if (AddWithStyleAsStandAlone)
return string.Format("style=\"background-color:{0};\"", BgCol);
return string.Format("background-color:{0};", BgCol);
}
}
public class ExtractData
{
public string ColumnValueFromCurrRow(DataRow DtRow, string RequestedColName)
{
return "";
}
public string DataRows_ColumnToString(DataRow Data_RowToActOn, string keyColName)
{
var tmp = Data_RowToActOn[keyColName];
return Data_RowToActOn[keyColName].ToString();
}
public int DataRowToInt(DataRow Data_RowToActOn, string keyColName)
{
string tmp = Data_RowToActOn[keyColName].ToString();
return Convert.ToInt32(tmp);
}
public bool CurrColumnIs(DataColumn Data_RowToQuestion, string ColumnName)
{
string tmp = Data_RowToQuestion.ToString();
return tmp == ColumnName;
}
public bool CurrRowIs(DataRow Data_RowToQuestion, string RowName, int CurrIndex)
{
string ColsName = Data_RowToQuestion.Table.Columns[CurrIndex].ToString();
return ColsName == RowName;
//this is curent value - by index
//string currentColumn = Data_RowToQuestion.ItemArray[CurrIndex].ToString();
}
}
}
}

Categories

Resources