After first click_event was fired, the second click_event does not fire - c#-4.0

I have two linkbuttons which are added dynamically depending on conditions, whether to display one or another. These buttons have events also.
Firstly displayed button's event fires, but when conditions change and second button displayed, it's event does not fire.
source code:
//conditions
bool wantToChangeBlogPost = false;
string textBoxOnChangeID = "";
protected void displayBlogPost()
{
SomeArraylist[] arr = valuesFromDdataBase();
foreach(BlogPost y in arr)
{
string contentStr = y.BlogMailingText;//"some content in mailing";
//div for displaying content in webpage
System.Web.UI.HtmlControls.HtmlGenericControl contentDIV = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
contentDIV.InnerHtml = contentStr;
//TB for changes
TextBox TBcontent = new TextBox();
TBcontent.Text = contentStr;
TBcontent.AutoPostBack = true;
TBcontent.TextMode = TextBoxMode.MultiLine;
TBcontent.Wrap = true;
TBcontent.ReadOnly = true;
TBcontent.EnableViewState = true;
//two different buttons for cases, whether or not want to change the text
//of blogPost
LinkButton changePost = new LinkButton();
changePost.Text = "Change MailingText";
LinkButton savePost = new LinkButton();
savePost.Text = "Save Changes";
//id 's are needed for controls
TBcontent.ID = "content-" + y.Id;
contentDIV.ID = "contentDIV-" + y.Id;
changePost.ID = "changePost-" + y.Id;
savePost.ID = "savePost-" + y.Id;
changePost.CommandArgument = "content-" + y.Id;
savePost.CommandArgument = "content-" + y.Id;
//Add these controls to the placeholder, which is defined in asmx:
//initially add only the contentDiv
myPlaceHolder.Controls.Add(contentDiv);
///////////////////////////
// HERE IS THE PROBLEM: //
///////////////////////////
//Conditions determing when to display one or another linkbutton and
//TBcontent
if (wantToChangeBlogPost == true && textBoxOnChangeID == "content-" + y.Id)
{
savePost.Click += new EventHandler(save_click);
//HERE IS THE PROBLEM: this event never fires :(
contentDIV.InnerHtml = "";
TBcontent.ReadOnly = false;
TBcontent.Visible = true;
// this button is displayd when someone has clicked on button
//'changePost'
myPlaceHolder.Controls.Add(savePost);
}
else
{
changePost.Click += new EventHandler(changePost_Click);
contentDIV.InnerHtml = contentStr;
TBcontent.ReadOnly = true;
TBcontent.Visible = false;//initially the TB is not visible
//initially the bool is false and
// this button is displayd
myPlaceHolder.Controls.Add(changePost);
}
}
//event methods for both buttons
//AFTER THIS METHOD COMPLETED I WANT TO DISPLAY THE ANOTHER LINKBUTTON
//'savePost' WITH ANOTHER EVENT 'save_click'
protected void changePost_Click(object sender, EventArgs e)
{
LinkButton LB = sender as LinkButton;
//CONDITIONS
textBoxOnChangeID = LB.CommandArgument;
wantToChangeBlogPost = true;
//GO TO THE DISPLAYING METHOD AGAIN
displayBlogPost();
}
//THIS METHOD NEVER EVEN FIRES! WHY??????
protected void save_click(object sender, EventArgs e)
{
LinkButton LB = sender as LinkButton;
//CONDITIONS
textBoxOnChangeID = "";
wantToChangeBlogPost = false;
//some logic to send changed data to the database to upload
//datatable
uploadWithChangedDataInTextBox();
//GO TO THE DISPLAYING METHOD AGAIN
displayBlogPost();
}
}

if you are adding controls dynamically then you have to recreate those on every post back keeping the id same then only the event wiil fire
or if ur adding the controls throught any other method like client side then u can call
__doPostBack(eventTarget,eventArg) and check for the id on the server side and then call sm function accordingly

Related

Closing Case in Acumatica through API

I want to close the case in Partners Portal remotely using Web API, whenever I close the case in my (client) side. I was able to implement the code but ran into below issue.
It is changing the status and resolution of the case in Partners Portal but Close Case button is enabled and it is visible in My Open Case bucket. Please let me know if I can close the case remotely using Web API or if I am missing anything.
protected virtual void CRCase_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var caseRow = (CRCase)e.Row;
if (caseRow != null)
{
if (caseRow.Status == "C") // Closed
{
string cloud9CaseCD = null;
cloud9CaseCD = CRCaseForCreate.Current.CaseCD;
string acumaticaCaseCD = string.Empty;
CSAnswers aCCaseNoAttribute = PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>,
And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>>>>.Select(new PXGraph(), CRCaseForCreate.Current.NoteID, "ACCASENO");
if (aCCaseNoAttribute != null)
{
acumaticaCaseCD = aCCaseNoAttribute.Value;
if(!string.IsNullOrEmpty(acumaticaCaseCD))
{
SP203000WS.Screen context = new SP203000WS.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "https://sso.acumatica.com/Soap/SP203000.asmx";
PartnerPortalCreds loginCreds = GetCreds();
string username = loginCreds.PARTPRTUSE;
string password = loginCreds.PARTPRTPAS;
SP203000WS.LoginResult result = context.Login(username, password);
SP203000WS.Content CR306000 = context.GetSchema();
context.Clear();
SP203000WS.Content[] CR306000Content = context.Submit
(
new SP203000WS.Command[]
{
new SP203000WS.Value
{
Value = acumaticaCaseCD,
LinkedCommand = CR306000.Case.CaseID
},
new SP203000WS.Value
{
Value = "C",
LinkedCommand = new SP203000WS.Field { FieldName="Status", ObjectName="Case"}
},
new SP203000WS.Value
{
Value = "RD",
LinkedCommand = new SP203000WS.Field { FieldName="Resolution", ObjectName="Case"}
},
CR306000.Actions.Submit,
CR306000.Case.CaseID
}
);
context.Logout();
}
}
}
}
}
Tried below code using CloseCase Action: -
protected virtual void CRCase_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var caseRow = (CRCase)e.Row;
if (caseRow != null)
{
if (caseRow.Status == "C") // Closed
{
string cloud9CaseCD = null;
cloud9CaseCD = CRCaseForCreate.Current.CaseCD;
string acumaticaCaseCD = string.Empty;
CSAnswers aCCaseNoAttribute = PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>,
And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>>>>.Select(new PXGraph(), CRCaseForCreate.Current.NoteID, "ACCASENO");
if (aCCaseNoAttribute != null)
{
acumaticaCaseCD = aCCaseNoAttribute.Value;
if (!string.IsNullOrEmpty(acumaticaCaseCD))
{
SP203010WS.Screen context = new SP203010WS.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "https://sso.acumatica.com/Soap/SP203010.asmx";
PartnerPortalCreds loginCreds = GetCreds();
string username = loginCreds.PARTPRTUSE;
string password = loginCreds.PARTPRTPAS;
SP203010WS.LoginResult result = context.Login(username, password);
SP203010WS.Content CR306000 = context.GetSchema();
context.Clear();
var commands1 = new SP203010WS.Command[]
{
new SP203010WS.Value
{
Value = acumaticaCaseCD,
LinkedCommand = CR306000.Case.CaseID
},
new SP203010WS.Value
{
Value = "Yes",
LinkedCommand = CR306000.Case.ServiceCommands.DialogAnswer, Commit = true
},
CR306000.Actions.CloseCase
};
var data = context.Submit(commands1);
context.Logout();
}
}
}
}
}
In the below image you can see that the case is already closed but Close Case menu button is still visible.
Close Case Confirmation Dialogbox on Partners Portal. How should I answer this dialogbox programatically while closing the case using Web API.
Have you tried to invoke Close action via Web API instead of changing values of the Status and Resolution fields? As far as I know, Close button on the Partner Portal updates support case Status to Open and Reason to Pending Closure. Then it's up to support personnel to manually close the case.
Finally found the solution. Updated the code for CloseCase (second code snippet). This will mark the case as Pending Closure in Partners Portal.

Arguments and changing the value

A newbie, please excuse the terms and explanation.
I have a program that accepts arguments which are in seconds. This in turn runs a timer that shows on the form. I want to give the user the ability to pause the timer for a set amount of time. I am having difficulty in trying to add time after the user Clicks the button as the method that runs the timer and countdown I have a method that gets the parameters of the argument.
I would like to maybe just get the parameters/arguments globally and then use them in all the different methods or threads. I am trying to do this in c# and wpf.
Code below:
public partial class MainWindow : Window
{
//int TimeOutPeriod = Int32.Parse("3600");
//private Timer timer;
System.Timers.Timer timer = new System.Timers.Timer();
public MainWindow()
{
InitializeComponent();
//timer = new Timer(1000);
timer = new System.Timers.Timer(1000);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
string[] param = Environment.GetCommandLineArgs();
int TimeOutPeriod = Int32.Parse(param[1]);
ProgressBar1.Maximum = TimeOutPeriod;
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
string [] param = Environment.GetCommandLineArgs();
int TimeOutPeriod = Int32.Parse(param[1]);
int InYourFaceDisplay = Int32.Parse(param[2]);
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
{
if (ProgressBar1.Value < TimeOutPeriod)
{
ProgressBar1.Value += 1;
RebootCDown.Content = "Machine will reboot in : " + (TimeOutPeriod - ProgressBar1.Value) + " Secs";
if ((TimeOutPeriod - ProgressBar1.Value) < InYourFaceDisplay)
{
this.Activate();
}
}
else
{
ShutDownWindows("0");
timer.Stop();
this.Close();
}
}));
}
private void SnoozeNow_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ShowInTaskbar = false;
ni.Icon = new System.Drawing.Icon("C:\\temp\\RebootIco.ico");
ni.Visible = true;
ShowInTaskbar = false;
ni.ShowBalloonTip(5000, "Test App", "Notify icon is working! Right click to access the context menu.", System.Windows.Forms.ToolTipIcon.Info);
Task.Delay(10000);
ShowInTaskbar = true;
}
}

Control Validating issue when WPF control hosted in ElementHost is clicked on WinForm Application

I have a winform application on which there is a mix of Winform and a WPF control hosted on ElementHost. When the winform textbox goes into Validating because the WPF control is clicked, and there is validating error, the ElementHost keeps firing Focus event which makes my application stuck.
Please advice if there is a way to resolve it.
I have created a sample application to replicate the issue.
I have a Form1 containing 2 winform textboxes (textbox1, textbox2) and a WPF control hosted on ElementHost.
textbox1_validating event handler checks if input is not "1", then the event is cancelled by setting the event argument e.Cancel to true. This works well if textbox1 goes into validating because other winform control is clicked.
However, if textbox1 goes into validating due to WPF control gains focus, the cancel event does not work. ElementHost keeps firing Focus event causing textbox1_validating been called again and again.
UserControl Code:
<UserControl x:Class="WpfControlLibrary1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="54" d:DesignWidth="295" >
<Grid Height="43">
<TextBox Height="20" HorizontalAlignment="Left" Name="textBox1" VerticalAlignment="Top" Width="106" Text="Default1" />
<TextBox Height="20" HorizontalAlignment="Left" Margin="130,0,0,0" Name="textBox2" VerticalAlignment="Top" Width="73" Text="Default2" />
</Grid>
WinForm Code:
public partial class Form1 : Form
{
public static bool HasError = false;
public Form1()
{
InitializeComponent();
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (textBox1.Text != "1" && textBox1.Text != "")
{
MessageBox.Show("Input is invalid, expecting \"1\". ");
HasError = true;
e.Cancel = true;
}
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this._durationCtrlHost = new WindowsFormsApplication1.DurationCtrlHost();
this._durationCtrl = new WpfControlLibrary1.UserControl1();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 23);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(242, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter);
this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox1_Validating);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(121, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(240, 20);
this.textBox2.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(90, 13);
this.label1.TabIndex = 4;
this.label1.Text = "WinformTextbox1";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(25, 63);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(90, 13);
this.label2.TabIndex = 5;
this.label2.Text = "WinformTextbox2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(24, 104);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 13);
this.label3.TabIndex = 6;
this.label3.Text = "WPFControl";
//
// _durationCtrlHost
//
this._durationCtrlHost.Location = new System.Drawing.Point(120, 90);
this._durationCtrlHost.Name = "_durationCtrlHost";
this._durationCtrlHost.Size = new System.Drawing.Size(271, 60);
this._durationCtrlHost.TabIndex = 3;
this._durationCtrlHost.Child = this._durationCtrl;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(420, 282);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this._durationCtrlHost);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
}
public class DurationCtrlHost : ElementHost
{
private const int WM_SETFOCUS = 0x0007;
private const int WM_KILLFOCUS = 0x0008;
private int SetFocusFiredCount = 0;
private int KillFocusFiredCount = 0;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SETFOCUS)
{
SetFocusFiredCount++;
if (Form1.HasError)
return;
}
else if (m.Msg == WM_KILLFOCUS)
{
KillFocusFiredCount++;
}
base.WndProc(ref m);
}
}

Irregular jump of code while returning datatable

Hi I have a c# code for an MDI Form such as this -
private void tlstrpmenuAppointments_Click(object sender, EventArgs e)
{
Appointments AppointmentsObject = new Appointments(Controller.Ulink1);
AppointmentsObject.MdiParent = FrmMainConsole.ActiveForm;
AppointmentsObject.Show();
}
This MDI has a child form named Appointments which includes the following code -
private void Appointments_Load(object sender, EventArgs e)
{
cmbSearchColoumn.SelectedIndex = 0;
lblDoctorName.Text =lblDoctorName.Text+" "+ dt.Rows[0].ItemArray[1].ToString() + " " + dt.Rows[0].ItemArray[2].ToString() + " " + dt.Rows[0].ItemArray[3].ToString();
//Load todays Time Slots-
DataTable temp = new DataTable();
// **THE PROBLEM LIES IN THE FOLLOWING STATEMENT**
temp = appointmentsCLObject.GetTimeSlots(docid);
// THIS CALLS THE BAL STATED BELOW THIS CODE.
cmbTimeSlotsAvailable.DisplayMember = temp.Columns[1].ToString();
cmbTimeSlotsAvailable.ValueMember = temp.Columns[0].ToString();
cmbTimeSlotsAvailable.DataSource = temp;
cmbTimeSlotsAvailable.SelectedIndex = 0;
//Loading Patient Lists for Consulting.
dt1 = appointmentsCLObject.GetAppointments(DateTime.Now, Convert.ToInt16(cmbTimeSlotsAvailable.SelectedValue), docid);
dtgridAppointments.DataSource = dt1;
}
The BAL is AS Follows -
public DataTable GetTimeSlots(int Docid)
{
DateTime dt=new DateTime();
dt = DateTime.Now;
DataTable dtable= appointmentMLObject.GetTimeSlots(Docid,(int)dt.DayOfWeek);
DataTable ReturnTable = new DataTable();
foreach (DataRow rw in dtable.Rows)
{
ReturnTable.Rows.Add(rw[0].ToString(),rw[1].ToString()+" "+rw[2].ToString());
}
// **PROBLEM START**
return ReturnTable;
}
**When the return statement is called the code does not return to its calling method! (??)
Instead it returns to the MDI which has created the object of this child form.
It returns to the statement
AppointmentsObject.Show();
And shows me the form with no data in it.

Add New Row in GridView winform on Button Click

Add New Row in GridView winform on Button Click.
Need to have single button in grid rather than DataGridViewButtonColumn
you can add it by using
GridView1.DataSource = datatable;
and then add new row by this
datatable.Rows.Add();
this will add new row and give control id into add().
use this
public partial class Form1 : Form
{
Button textBoxDgv1 = new Button();
Label labelDgv1 = new Label();
the next is on the Form_Load event
private void Form1_Load(object sender, EventArgs e)
{
labelDgv1.Text = "Delete";
labelDgv1.Height = 20;
labelDgv1.AutoSize = false;
labelDgv1.BorderStyle = BorderStyle.FixedSingle;
labelDgv1.TextAlign = ContentAlignment.MiddleCenter;
int Xdgv1 = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X;
labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgv1;
labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height);
this.dataGridView1.Controls.Add(labelDgv1);
and one more section is in dataGridView1_CellPainting
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
int sum = 0;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[3].Value != string.Empty)
{
sum += Convert.ToInt32(this.dataGridView1[3, i].Value);
}
}
textBoxDgv1.Text = sum.ToString();
int Xdgvx = this.dataGridView1.GetCellDisplayRectangle(2, -1, true).Location.X;
labelDgv1.Width = this.dataGridView1.Columns[2].Width + Xdgvx;
labelDgv1.Location = new Point(0, this.dataGridView1.Height - textBoxDgv1.Height);
textBoxDgv1.Width = this.dataGridView1.Columns[3].Width;
Xdgvx = this.dataGridView1.GetCellDisplayRectangle(3, -1, true).Location.X;
textBoxDgv1.Location = new Point(Xdgvx, this.dataGridView1.Height - textBoxDgv1.Height);
}

Resources