Can we use some kind of array to control the fields on the form? - textbox

I have a asp.net form with 20 textbox controls(VB2012 and 2008R2). Is there an array function for me to change the property of all the fields or do I have to spell it out separately. Example changing the back color and making the control editable when the edit button is clicked.
Thanks
~ Nita

I did this sometime ago:
void SetEnabled(bool enable)
{
textBox1.enabled = enable;
textBox1.enabled = enable;
textBox2.enabled = enable;
textBox3.enabled = enable;
textBox4.enabled = enable;
textBox5.enabled = enable;
... repeat until textBox20
textBox20.enabled = enable;
}
to call it, for example:
SetEnabled(true);
or
SetEnabled(false);

Related

Dynamically add panel control to a dynamic tabsheet (C++ Builder Rad Studio)?

I have a problem getting the tabPage->Name value, because it will generate when user click the button, first block of my code will create new tabsheet inside PageControl3 and then I use the static int tabNumber; by if condition to generate the tabPage->Caption and then I use the caption for tabPage->Name dynamically.
I need the name of that tabsheet to pass it on the Error line.
static int tabNumber;
if (tabNumber >= 1) ++tabNumber;
else tabNumber = 1;
PageControl3->Visible = true;
TTabSheet *tabPage = new TTabSheet(PageControl3);
tabPage->PageControl = PageControl3;
tabPage->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabPage->Name = UnicodeString("ts") + tabPage->Caption;
The second part of my code should create new TPanel inside current tabpage->Name that was created in the above part of my code, BUT it wont work.
TPanel *panelPage = new TPanel(tabPage->Name); // Error Line
panelPage->Align = alClient;
panelPage->Name = UnicodeString("panel") + tabPage->Caption;
Error massage:
[bcc32 Error] mainUnit.cpp(50): E2285 Could not find a match for 'TPanel::TPanel(const UnicodeString)'
So I not know how to access the tabPage->Name value, because that was create dynamically?
DB Baxter The constructor requires a component variable/object and not a string with the text of the name. Such as TPanel *panelPage = new TPanel(tabPage); Will that work for you? Do you need to make the panel's parent tabPage?
By helping DB Baxter, I think the correct and complete answer for create dynamic TPanel inside the dynamic TTabSheet will requires a component variable/object and then for displaying the TPanel we should use the whatever->show(); command, the full code can bee like this:
static int tabNumber = 0;
if (tabNumber >= 1) {
++tabNumber;
} else {
tabNumber = 1;
PageControl3->Visible = true;
}
// create new tab sheet inside PageControl3
TTabSheet *tabSheet = new TTabSheet(PageControl3);
tabSheet->PageControl = PageControl3;
tabSheet->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabSheet->Name = UnicodeString("ts") + tabSheet->Caption;
// create new panel inside the current tab sheet
TPanel *panelBox = new TPanel(tabSheet);
panelBox->Parent = tabSheet;
panelBox->Align = alClient;
panelBox->Name = UnicodeString("panelPage") + IntToStr(tabNumber);
panelBox->BevelOuter = bvNone;
panelBox->ShowCaption = true;
panelBox->Caption = UnicodeString("panel") + tabSheet->Caption;
panelBox->Show();
I hope this code can help anyone to generate the dynamic tab sheet with panel, by the way if you want add some frame to it the following code should use:
// adding the registration frame to the panel
TregFrame *newRegistration = new TregFrame(panelBox);
newRegistration->Parent = panelBox;
newRegistration->Align = alClient;
Note: don't forget to include your frame in your working file, for example #include "registrationFrame.h".

Figure doesn't show correct string on event

In the following code I create 3 boxes with the text 1 to 3, in a fourth box I'd like to show the text of the box my mouse is hovering over. So i set an onMouseEnter FProperty for each of the boxes where I change the string of the fourth box and tell it to redraw.
bool redraw = false;
str s = "0";
Figure getTextbox() {
return computeFigure(bool() {bool temp = redraw; redraw = false; return temp; },
Figure() {
return text(str() {return s; });
});
}
list[Figure] boxes = [];
for (i <- [1..4]) {
boxes += box(text(toString(i)), onMouseEnter(void () {s = toString(i); redraw = true; }));
}
Figure changer = box(getTextbox());
render(vcat(boxes + changer));
However, for some odd reason all three boxes will tell the onMouseEnter method to change the text of the fourth box into "3" (the value of the last box) instead of their individual value.
Any clue why? Thanks!
Ah yes, this is the variable capturing closure problem with for loops, also known from other languages which have this particular feature like Javascript. This is the code with the issue:
for (i <- [1..4]) {
boxes += box(text(toString(i)), onMouseEnter(void () {s = toString(i); redraw = true; }));
}
The variable i is bound by the void closure and not its value. So every time the function which is created and passed to onMouseEnter it will read the latest value of the i variable. Since the callback is called after the loop terminates, all calls to the mouse enter function will have the value 3.
To fix this and "do what you want", the following code would work I believe:
for (i <- [1..4]) {
newS = toString(i);
boxes += box(text(toString(i)), onMouseEnter(void () {s = newS; redraw = true; }));
}
This works because for every pass of the for loop a new environment is created which binds the newS variable. So you'll get a fresh newS for every loop instead of the reused i.

Pagination issue in Report Viewer 11 in MVC Application

I am using ReportViewer 11 to display a report inside an iframe (aspx page is loaded into iframe). It displays first page properly. But when I click on next page, it loads the first page again. Even if I type in page number manually into the textbox, it loads first page only. It seems like, it doesn't fire the pagenavigation event in the server side. If I set the currentpage property to 2 in code behind, then also it loads page 1 only no matter what settings I provide.
Searched for this for days. Got no solution.
Any help will be appreciated.
Thanks
Apply this logic
Store the records in container1
Pass the records to container2
print 5 records(or may be more) from container2
when "next" button is pressed print next 5 from container2
and so on.
I dont know whether this will help you, but records from database can be paginated in this way.
I have tried this logic too. But the main problem is that ReportViewer.CurrentPage is 0 always (in my case) even when the "next" button is pressed. So it will again show the container1 records. This is my code:
public void SetReportData(ref ReportViewer objRptVwr, ReportParameter[] rptParam, string moduleName, string reportName, string dsName, System.Data.DataTable dtFinal){
objRptVwr.Reset();
objRptVwr.ProcessingMode = ProcessingMode.Local;
objRptVwr.LocalReport.ReportPath = HttpContext.Current.Server.MapPath("~/ReportViewer/" + moduleName + "/" + reportName + ".rdlc");
if (rptParam != null)
objRptVwr.LocalReport.SetParameters(rptParam);
objRptVwr.ShowPrintButton = true;
objRptVwr.ShowParameterPrompts = true;
objRptVwr.AsyncRendering = false;
objRptVwr.InteractivityPostBackMode = InteractivityPostBackMode.AlwaysSynchronous;
objRptVwr.ShowBackButton = true;
objRptVwr.SizeToReportContent = false;
objRptVwr.PageCountMode = PageCountMode.Actual;
objRptVwr.ShowExportControls = true;
objRptVwr.ShowPageNavigationControls = true;
objRptVwr.ShowToolBar = true;
objRptVwr.ShowWaitControlCancelLink = false;
objRptVwr.ShowZoomControl = true;
objRptVwr.LocalReport.EnableExternalImages = true;
objRptVwr.ExportContentDisposition = ContentDisposition.AlwaysInline;
ReportDataSource reportDataSource = new ReportDataSource(dsName, (System.Data.DataTable)dtFinal);
objRptVwr.LocalReport.DataSources.Clear();
objRptVwr.LocalReport.DataSources.Add(reportDataSource);
objRptVwr.LocalReport.Refresh();
}
What I did that the generated buttons will be according to the list size.
Each buttons(may be li tag) will have a textfield containing value like 0,5,10 and so on dynamically(In case of 5 elements per page).
A button is clicked, the value of that textfield(e.g index) I got and shifted the resulset position to index and print the records upto 5 elements.

onFullSync action, show updated info - DHTMLX Grid + RoR

I have a Ruby on Rails project where I use a DHTMLX Grid.
Is there a way of showing, using the event handler "onFullSync" provided by the grid API, to show updated data?
Let me explain a little better... I know I can do something like:
dp.attachEvent("onFullSync", function(){
alert("update complete");
})
But what I want is something more complex. I want to, after each completed update, alter a div adding the information like this:
Field 2 was updated to XYZ and field 3 was updated to XER on line X
Field 1 was updated to 123 and field 3 was updated to XSD on line Y
Is this possible?
Thanks
There is a onAfterUpdate event that can be used similar to onFullSync
http://docs.dhtmlx.com/api__dataprocessor_onafterupdate_event.html
It will fire after each data saving operation ( if you are saving 5 rows - it will fire 5 times )
Still, info about updated columns will not be available here.
Also, you can try onEditCell event of grid. It fires after changing data in db, but before real saving in database. Here you can get all necessary info - row, column, old value and new value.
http://docs.dhtmlx.com/api__link__dhtmlxtreegrid_oneditcell_event.html
So, what I end up doing was:
After creating the grid I created an array:
var samples = [];
Then, as per #Aquatic suggestion, I added to "onEditCell" event the following line:
samples[samples.length] = grid.cells(rId, 5).getValue();
This allowed me to add to the array the value present on column 5 of the row changed. Then, on "onFullSync" event I hide or show the div created on the view with the messages (I distinguish if it's on row or more changed on the grid).
//Deals with messages after update
dp.attachEvent("onFullSync", function(){
unique_samples = uniq_fast(samples.sort());
if (unique_samples.length == 1){
$('#updated-samples').text("");
$(".messages").show();
$('#updated-samples').text("A seguinte amostra foi actualizada: " + unique_samples[0]);
//to clear the array
samples = [];
} else if (unique_samples.length > 1){
$('#updated-samples').text("");
$(".messages").show();
$('#updated-samples').text("As seguintes amostras foram actualizadas: " + unique_samples.sort().join(", "));
//to clear the array
samples = [];
} else {
$('#updated-samples').text("");
$(".messages").hide();
//to clear the array
samples = [];
}
})
The problem with using "onEditCell" is that everytime a field is changed on that row I get a repeated value on my "samples" array, I I had to remove duplicate from that array. For that I used one of the suggestions at this answer
// remove duplicates in array
function uniq_fast(a) {
var seen = {};
var out = [];
var len = a.length;
var j = 0;
for(var i = 0; i < len; i++) {
var item = a[i];
if(seen[item] !== 1) {
seen[item] = 1;
out[j++] = item;
}
}
return out;
}
Then I have on the beginning of the view, to show the messages:
<div class="alert alert-success messages" id="updated-samples">
And that's it. I could be not the most efficient way but it works for what I wanted. I will leave the question open a few more days to see if any other option appears.

How can I protect an excel sheet, except for a particular cell using Open XML 2.0?

I am generating a report using OpenXML and exporting it to excel. I want to protect the excel sheet except for a particular cell.
If anyone has worked on this before, kindly help
Thanks,
Amolik
PageMargins pageM = worksheetPart.Worksheet.GetFirstChild<PageMargins>();
SheetProtection sheetProtection = new SheetProtection();
sheetProtection.Password = "CC";
sheetProtection.Sheet = true;
sheetProtection.Objects = true;
sheetProtection.Scenarios = true;
ProtectedRanges pRanges = new ProtectedRanges();
ProtectedRange pRange = new ProtectedRange();
ListValue<StringValue> lValue = new ListValue<StringValue>();
lValue.InnerText = "A1:E1"; //set cell which you want to make it editable
pRange.SequenceOfReferences = lValue;
pRange.Name = "not allow editing";
pRanges.Append(pRange);
worksheetPart.Worksheet.InsertBefore(sheetProtection, pageM);
worksheetPart.Worksheet.InsertBefore(pRanges, pageM);
ref : http://social.msdn.microsoft.com/Forums/en-US/a6f7502d-3867-4d5b-83a9-b4e0e211068f/how-to-lock-specific-columns-in-xml-workbook-while-exporting-dataset-to-excel?forum=oxmlsdk
Have you tried using the OpenXML Productivity Toolkit?
from what I can see you have to add a
new CellFormat
with attribute
ApplyProtection = true
to
CellFormats
append
new Protection
with attribute
Locked = false
to the the CellFormat you created.
CellFormat is a element of CellFormats which is a element of Stylesheet
then to the Worksheet you add a
new SheetProtection(){ Password = "CC1A", Sheet = true, Objects = true, Scenarios = true };
I havent tried this, but it should be easy enought to find out what you need to do with the Productivity Toolkit. I hope this points you and anyone trying to do this in the right direction.

Resources