How can I bind the button text on form dynamically?
I want to give the user a feature where he can change the button text dynamically from the database.
So, from database, I am getting value as a dataset
Now the problem is, how can I bind this text to my button control on my form.
Can you please help me with this.
Thanks in advance.
First convert your Dataset to DataTable and use the below code . I have tested this code according to your question.
DataTable _ds = _commonDAC.GetButtonName(1); // i assume you are getting dataset form here
foreach (DataRow row in _ds.Rows)
{
string ControlName = row["ControlName"].ToString();
if( ControlName == "bttnLeftMessageOnMachine")
bttnLeftMessageOnMachine.Text = row["EventText"].ToString();
if (ControlName == "bttnSpokeToPerson")
bttnSpokeToPerson.Text = row["EventText"].ToString();
if (ControlName == "bttnHomeKitchenNotReady")
bttnHomeKitchenNotReady.Text = row["EventText"].ToString();
if (ControlName == "bttnInstallerNotReady")
bttnInstallerNotReady.Text = row["EventText"].ToString();
if (ControlName == "bttnNoAnswer")
bttnNoAnswer.Text = row["EventText"].ToString();
if (ControlName == "bttnBusyPhoneLine")
bttnBusyPhoneLine.Text = row["EventText"].ToString();
if (ControlName == "bttnPhLineNotOperation")
bttnPhLineNotOperation.Text = row["EventText"].ToString();
if (ControlName == "bttnCustomerWillCallInstaller")
bttnCustomerWillCallInstaller.Text = row["EventText"].ToString();
if (ControlName == "bttnIncorrectPhNo")
bttnIncorrectPhNo.Text = row["EventText"].ToString();
if (ControlName == "bttnOrderOnHold")
bttnOrderOnHold.Text = row["EventText"].ToString();
if (ControlName == "bttnOtherNoteRequired")
bttnOtherNoteRequired.Text = row["EventText"].ToString();
}
Related
Making a winforms application and I want the name of the table in my SQL query to be equal to a variable I have called TreeCodeName. This is my code:
private void button1_Click(object sender, EventArgs e)
{
string TreeNodeName = treeView1.SelectedNode.Name.ToString();
if ((TreeNodeName == "BOOKS") || (TreeNodeName == "CARDS") || (TreeNodeName == "COMPUTERS") || (TreeNodeName == "CONSOLES") || (TreeNodeName == "DEVICES") || (TreeNodeName == "DONORS") || (TreeNodeName == "MAGAZINES") || (TreeNodeName == "MOTHERBOARDS") || (TreeNodeName == "OTHERS") || (TreeNodeName == "PARTS") || (TreeNodeName == "PERIPHERALS") || (TreeNodeName == "POWER_SUPPLY") || (TreeNodeName == "PROCESSORS") || (TreeNodeName == "RAMS") || (TreeNodeName == "SOFTWARE") || (TreeNodeName == "STORAGE") || (TreeNodeName == "TERMINALS"))
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * From Table Where Title = #Title";
command.Parameters.AddWithValue("#Title", TreeNodeName);
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
}
Whenever I try to test this, I run into an error that says there was a syntax error on FROM. Any way to salvage this?
Hello my question is as stated. I have a randomly generated dungeon with a player and random blocks. All the rooms in the dungeon are saved in the ROOMS 2D array which contains the data for the rooms. You have a current Row and current Col which is where the player is at. What i need to know is how to say IF there is no room above the current position then change the outside wall graphic to close the exits/doors where there is no room. I have this somewhat working but everyway i change it there is always one room which just will not work if i try to add the code. What i have now is abunch of if statements saying IF ROOMS[currentRow + 1][currentCol](< that would be equal to down) so if one row up exists then change the graphic by doing gotoAndStop. So how or which is the best way to determine if a position exists because with this, it will randomly comeback with errors like "term is undefined and has no properties." Also i have really dirty code, sorry im new, ill try to clean it up later but if any of you feel like it, i wont stop you haha!
Im grateful for any replies! Here is my room class
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Room extends MovieClip{
var room1:Array = new Array();
var room2:Array = new Array();
var room3:Array = new Array();
var room4:Array = new Array();
var room5:Array = new Array();
var room6:Array = new Array();
var room7:Array = new Array();
var room8:Array = new Array();
var room9:Array = new Array();
var room10:Array = new Array();
var currentRow:int = 0;
var currentCol:int = 0;
var box:Box;
var boxes:Array;
var ROOMS:Array;
var onTop:Boolean;
var moved:Boolean;
private var player:Player;
private var walls:Walls;
private var blocker1:Blocker;
private var blocker2:Blocker;
private var blocker3:Blocker;
private var blocker4:Blocker;
private var arrowImage:ArrowSymbol;
public function Room(){
init();
createRooms();//add the walls + boxes of first room to the first array value // later make floors array that contains all the rooms and room array that contains all the boxes and enemies + events
stage.addChild(ROOMS[currentRow][currentCol]);
Constants.wallsRef = ROOMS[currentRow][currentCol];
addEventListener(Event.ENTER_FRAME, update);
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}
function init(){
Constants.stageRef=stage;
player = new Player();
//add walls
walls = new Walls();
Constants.wallsRef=walls;
blocker1 = new Blocker();//BLOCKER WHEN PLAYER TOUCHES IT CHANGES ROOM
blocker1.x = 350;
blocker1.y = 1;
stage.addChild(blocker1);
blocker2 = new Blocker();
blocker2.x = 350;
blocker2.y = 619;
stage.addChild(blocker2);
blocker3 = new Blocker();
blocker3.x = -30;
blocker3.y = 300;
blocker3.rotation = 90;
stage.addChild(blocker3);
blocker4 = new Blocker();
blocker4.x = 700;
blocker4.y = 300;
blocker4.rotation = 90;
stage.addChild(blocker4);
Constants.blockerRef1 = blocker1;
Constants.blockerRef2 = blocker2;
Constants.blockerRef3 = blocker3;
Constants.blockerRef4 = blocker4;
//add player
player.x = 300;
player.y = 200;
stage.addChild(player);
arrowImage = new ArrowSymbol();
arrowImage.x = 630;
arrowImage.y = 30;
box = new Box();
boxes = new Array();
ROOMS = new Array([room2],
[room6, room1, room5], /// THIS IS THE MAP OF THE FLOOR /// GOING UP ON THE GAME IS GOING DOWN ON IT
[room7, room8],
[room3, room9],
[room4]);//THIS WILL EVENTUALLY BE COMPLETELY RANDOMIZED//
onTop = false;
moved = false;
}
function update(e:Event){
arrowCount.text = " " + Constants.arrowNumRef;//arrow amount left
closeUnnecessaryExits();
//UP
if(Constants.blockerRef1.hitTestPoint(player.x,player.y) && moved != true){
stage.removeChild(ROOMS[currentRow][currentCol]);//remove the room you are in so the new room doesnt overlap
currentRow++;//change where the player is in
stage.addChild(ROOMS[currentRow][currentCol]);//add new room
Constants.wallsRef = ROOMS[currentRow][currentCol];//add colision
player.y = 600;
stage.addChild(arrowCount);
stage.addChild(arrowImage);
trace();
moved = true;
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//DOWN
if(Constants.blockerRef2.hitTestPoint(player.x,player.y) && moved != true){
//this will be where i want to change rooms
stage.removeChild(ROOMS[currentRow][currentCol]);
currentRow--;
Constants.wallsRef = ROOMS[currentRow][currentCol];
stage.addChild(ROOMS[currentRow][currentCol]);
player.y = 10;//change to 600
moved = true;
trace("changed rooms");
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//LEFT
if(Constants.blockerRef3.hitTestPoint(player.x,player.y) && moved != true){
stage.removeChild(ROOMS[currentRow][currentCol]);//remove the room you are in so the new room doesnt overlap
currentCol--;//change where the player is in
stage.addChild(ROOMS[currentRow][currentCol]);//add new room
Constants.wallsRef = ROOMS[currentRow][currentCol];//add colision
player.x = 600;
stage.addChild(arrowCount);
stage.addChild(arrowImage);
moved = true;
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//RIGHT
if(Constants.blockerRef4.hitTestPoint(player.x,player.y) && moved != true){
//this will be where i want to change rooms
stage.removeChild(ROOMS[currentRow][currentCol]);
currentCol++;
Constants.wallsRef = ROOMS[currentRow][currentCol];
stage.addChild(ROOMS[currentRow][currentCol]);
player.x = 10;//change to 600
moved = true;
trace("changed rooms");
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
}
function createRooms(){
for(var r = 0; r <ROOMS.length; r++){
walls = new Walls();
addRandomBlocks();
for(var c = 0; c < ROOMS[r].length; c++){
walls = new Walls();
addRandomBlocks();
ROOMS[r][c] = walls;
}
trace(ROOMS[r][c]);
}
}
// [room2, NaN],
// [room6, room1, room5], /// THIS IS THE MAP OF THE FLOOR /// GOING UP ON THE GAME IS GOING DOWN ON IT
// [room7, room8],
// [room3, room9],
// [room4]);
function closeUnnecessaryExits(){
trace("ROW: " + currentRow + " COL: " + currentCol);
var up = ROOMS[currentRow + 1];
var down = ROOMS[currentRow - 1];
var right = ROOMS[currentRow][currentCol + 1];
var left = ROOMS[currentRow][currentCol - 1];
//check to see which outside wasall to use
if(ROOMS[currentRow + 1] == null && up && right && left){
ROOMS[currentRow][currentCol].gotoAndStop(2);
}else if(down == null && left == null && right && up){
ROOMS[currentRow][currentCol].gotoAndStop(3);
}else if(down == null && left == null && up == null && right){
ROOMS[currentRow][currentCol].gotoAndStop(4);
}else if(left == null && down && right && up){// IF HAVING PROBLEMS THEN MAKE THIS MAKE SURE ALL OTHER SIDES ARE TRUE
ROOMS[currentRow][currentCol].gotoAndStop(5);
}else if(down == null && left == null && right == null && up){
ROOMS[currentRow][currentCol].gotoAndStop(6);
}else if(down && up == null && right == null && left == null){
ROOMS[currentRow][currentCol].gotoAndStop(7);
}else if(ROOMS[currentRow + 1][currentCol] == null && ROOMS[currentRow - 1][currentCol] && left && right){
ROOMS[currentRow][currentCol].gotoAndStop(8);
trace("works 1");
}else if(left && right && ROOMS[currentRow - 1][currentCol] == null && ROOMS[currentRow + 1][currentCol] == null){
ROOMS[currentRow][currentCol].gotoAndStop(9);
trace("works 2");
}else if(left && ROOMS[currentRow - 1][currentCol] && right == null && ROOMS[currentRow + 1][currentCol] == null){
ROOMS[currentRow][currentCol].gotoAndStop(10);// LEFT DOWN
trace("works 3");
}else if(left && ROOMS[currentRow + 1][currentCol] && ROOMS[currentRow - 1][currentCol] == null && right == null){
ROOMS[currentRow][currentCol].gotoAndStop(11);//BROKEN left up
trace("working 4");
}else if(left && ROOMS[currentRow + 1][currentCol] == null && ROOMS[currentRow - 1][currentCol] == null && right == null){
ROOMS[currentRow][currentCol].gotoAndStop(12);
trace("works 5");
}else if(right == null && left && up && down){
ROOMS[currentRow][currentCol].gotoAndStop(13);
trace("works 6");
}
}
function addRandomBlocks(){
for(var e=0; e <Math.random() * 10; e++){
//trace("started block");
box = new Box();
box.x = Math.random() * (615 - 100) + 100;
box.y = Math.random() * (500 - 120) + 120;
//colision for block to block
for(var col = 0; col < boxes.length; col++){
if(box.hitTestObject(boxes[col])){
onTop = false;/// THIS NEEDS TO BE TRUE FOR THE DETECTION TO WORK
//trace("THIS BOX IS ON TOP OF ANOTHER");
}
}
if(onTop == false){
boxes.push(box);
walls.addChild(box);
trace("BOX CREATED " + onTop);
//trace(boxes);
}
}
}
}
}
You could streamline your code by creating some simple functions that deal with assigning and accessing values in your 2D array. One that checks if an element within a 2D array exists might look like:
function cellExists(array:Array, x:int, y:int):Boolean {
return array[y] !== undefined && array[y][x] !== undefined;
}
Used like, in your example:
if (cellExists(ROOMS, currentCol, currentRow)) {
//
}
Although with this type of task you would benefit greatly from implementing a class that handles grid + cell data, something along the lines of this to get you started:
public class Grid {
private var _content:Vector.<Vector.<Cell>>;
public function Grid(columns:int, rows:int) {
// Fill _content with empty slots based on columns, rows.
}
public function getCell(x:int, y:int):Cell {}
public function cellExists(x:int, y:int):Boolean {}
}
I would like to show desktop view when user uses Ipad.
I use DisplayModeProvide, but sometimes Elmah keep this error:
System.NullReferenceException: in System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath
This is my code:
if (DisplayModeProvider.Instance != null)
if (DisplayModeProvider.Instance.Modes != null)
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
("iPad", StringComparison.OrdinalIgnoreCase) >= 0)
});
Can someone help me?
We had the same issue, try checking for a null UserAgent
if (DisplayModeProvider.Instance != null)
if (DisplayModeProvider.Instance.Modes != null)
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("")
{
ContextCondition = (context => context.Request.UserAgent != null && context.GetOverriddenUserAgent().IndexOf
("iPad", StringComparison.OrdinalIgnoreCase) >= 0)
});
I am developing a LiveCycle form that has a table on it that can have a variable amount of rows. I want to only validate it if there is data in one of the columns but not all of them. So I would skip the validation if the row is blank or all the columns in that row are filled in.
Any ideas how to do this. How would I loop through the rows of a table.
Thanks in advance,
Paul
I would tweat your answer a little bit by replacing resolveNodes that is quite slow.
In order to get row count you can use instanceManager TrainerForm._TrainerTable.count
To get a specific item from row list use <RowName>.all.item(index). Be carefull while using this construct because it requires a least one row. Row is a shourtcat for Row[0].
Here is your code with with my upgrades:
var rowCount = TrainerForm.TrainerTable._TrainerData.count;
for (var i=0;i<rowCount;i++)
{
if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.rawValue == null &&
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.rawValue == null &&
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.selectedIndex == -1 &&
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.rawValue == null )
;//check the case where all rows are blank which is valid
else
{
if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.rawValue == null)
{
TrainerTableValid = false;
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerName.ui.#textEdit.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.rawValue == null)
{
TrainerTableValid = false;
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerPrepHrs.ui.#numericEdit.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.selectedIndex == -1)
{
TrainerTableValid = false;
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerArea.ui.#choiceList.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.rawValue == null)
{
TrainerTableValid = false;
TrainerForm.TrainerTable.TrainerData.all.item(i).TrainerActivity.ui.#textEdit.border.fill.color").value = "255,0,0";
}
}
}
You can put your script in validate event of your cells or whole row. The result of validation script is determined by the last line result (true or false); To make validations failure visible you can set form level validation (File->Form Properties->Form Validation->Color Failed Fields).
Another approach (that I personally prefer) is setting field as required using code fieldName.manadatory = "error" when some conditions are met. In order to make field optional just put fieldName.manadatory = "disabled".
Here is what I ended up doing. First I made all fields optional. Then I execute this code from a click event of a button.
var fields = xfa.resolveNodes("TrainerForm.TrainerTable.TrainerData[*]");
for (var i=0;i<fields.length;i++)
{
if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerName.rawValue == null &&
TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerPrepHrs.rawValue == null &&
TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerArea.selectedIndex == -1 &&
TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerActivity.rawValue == null )
;//check the case where all rows are blank which is valid
else
{
if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerName.rawValue == null)
{
TrainerTableValid = false;
xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerName.ui.#textEdit.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerPrepHrs.rawValue == null)
{
TrainerTableValid = false;
xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerPrepHrs.ui.#numericEdit.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerArea.selectedIndex == -1)
{
TrainerTableValid = false;
xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerArea.ui.#choiceList.border.fill.color").value = "255,0,0";
}
if (TrainerForm.TrainerTable.resolveNode("TrainerData[" + i + "]").TrainerActivity.rawValue == null)
{
TrainerTableValid = false;
xfa.resolveNode("TrainerForm.TrainerTable.TrainerData[" + i + "].TrainerActivity.ui.#textEdit.border.fill.color").value = "255,0,0";
}
}
}
I have made a validation to prevent data into being inserted to the DB when it's empty but it still enters a blank form to the database?
protected void Button1_Click(object sender, EventArgs e)
{
ProjectTestEntities User_save = new ProjectTestEntities();
User ins = new User();
ins.name = TextBox1.Text;
ins.email = TextBox2.Text;
ins.phone = TextBox3.Text;
ins.gender = RadioButtonList1.SelectedValue;
ins.password = TextBox4.Text;
if (ins.name == null || ins.email == null || ins.gender == null || ins.password == null)
{
Label1.Text = "Incomplete input";
}
else
{
User_save.Users.AddObject(ins);
User_save.SaveChanges();
}
}
Try using string.IsNullOrEmpty()
if (string.IsNullOrEmpty(ins.name == null) ||
string.IsNullOrEmpty(ins.email == null) ||
string.IsNullOrEmpty(ins.gender == null) ||
string.IsNullOrEmpty(ins.password == null))
{
Label1.Text = "Incomplete input";
}
else
{
User_save.Users.AddObject(ins);
User_save.SaveChanges();
}