How to validate all the fields in c# in windows application? - c#-4.0

I have a windows form it has 8 textboxes , 3 combobox and a radio button.
I am using this code but it does not work.
I put the beakpoint and checked the control does not go inside if(Cnt is TextBox) It is evaluating to false. I am keeping all the controls in the panel. May be because of this I am having a problem
private void button1_Click(object sender, EventArgs e)
{
foreach (Control cnt in this.Controls)
{
if (cnt is TextBox)
{
if (cnt.Text == "")
{
MessageBox.Show("TextBox is Blank.");
cnt.BackColor = Color.Pink;
}
}
else if (cnt is ComboBox)
{
ComboBox cmb = (ComboBox)cnt;
if (cmb.SelectedItem == null)
{
MessageBox.Show("Combox is not Selected.");
cnt.BackColor = Color.Plum;
}
}
}
}

Related

Enable Custom Field on Project Quote Screen

I am using Acumatica 2020 R1. I have a custom text field on the PMQuote DAC. This field is in a custom tab on the project quotes screen. I want that field to always be editable. I put the following in my RowSelected event:
protected virtual void PMQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected del)
{
del?.Invoke(cache, e);
PMQuote quote = e.Row as PMQuote;
cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled(cache, e.Row, true);
PXUIFieldAttribute.SetEnabled<PMQuoteExt.usrMyCustomField>(cache, e.Row, true);
}
This didn't work, so I also looked in the automation steps. I didn't see any automation steps available to modify.
I then looked at Workflow. I didn't see any workflows to edit either. I tried creating a new one based on the status field. I added the user field for each status and made sure disabled was unchecked. This didn't work either.
Any ideas on how I can get that field to be enabled regardless of the document status?
Thanks for your help!
AllowUpdate is called only on the cache object, add it for the data view, example:
Base.Quote.AllowUpdate = true
Also, try to extend PXQuoteMaintExt graph extension:
public class PMQuoteMaintExtExtension : PXGraphExtension<PMQuoteMaintExt, PMQuoteMaint>
{
protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
{
sel?.Invoke(sender, e);
}
}
It manages visibility with RowSelected event:
namespace PX.Objects.PM
{
public class PMQuoteMaintExt : PXGraphExtension<PMDiscount, PMQuoteMaint>
{
protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
{
sel?.Invoke(sender, e);
var row = e.Row as PMQuote;
if (row == null) return;
VisibilityHandler(sender, row);
}
private void VisibilityHandler(PXCache sender, PMQuote row)
{
CR.Standalone.CROpportunityRevision revisionInDb = PXSelectReadonly<CR.Standalone.CROpportunityRevision,
Where<CR.Standalone.CROpportunityRevision.noteID, Equal<Required<CR.Standalone.CROpportunityRevision.noteID>>>>.Select(Base, row.QuoteID).FirstOrDefault();
CR.Standalone.CROpportunity opportunityInDb = (revisionInDb == null) ? null : PXSelectReadonly<CR.Standalone.CROpportunity,
Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, revisionInDb.OpportunityID).FirstOrDefault();
CR.Standalone.CROpportunity opportunity = PXSelect<CR.Standalone.CROpportunity,
Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, row.OpportunityID).FirstOrDefault();
var opportunityIsClosed = opportunity?.IsActive == false;
bool allowUpdate = row.IsDisabled != true && !opportunityIsClosed && row.Status != PMQuoteStatusAttribute.Closed;
if (opportunityInDb?.OpportunityID == opportunity?.OpportunityID)
Base.Caches[typeof(PMQuote)].AllowUpdate = allowUpdate;
else
{
var quoteCache = Base.Caches[typeof(PMQuote)];
foreach (var field in quoteCache.Fields)
{
if (!quoteCache.Keys.Contains(field) &&
field != quoteCache.GetField(typeof(PMQuote.opportunityID)) &&
field != quoteCache.GetField(typeof(PMQuote.isPrimary)))
PXUIFieldAttribute.SetEnabled(sender, row, field, allowUpdate);
}
}
PXUIFieldAttribute.SetEnabled<PMQuote.bAccountID>(sender, row, row.OpportunityID == null);
Base.Caches[typeof(PMQuote)].AllowDelete = !opportunityIsClosed;
foreach (var type in new[]
{
typeof(CR.CROpportunityDiscountDetail),
typeof(CR.CROpportunityProducts),
typeof(CR.CRTaxTran),
typeof(CR.CRAddress),
typeof(CR.CRContact),
typeof(CR.CRPMTimeActivity),
typeof(PM.PMQuoteTask)
})
{
Base.Caches[type].AllowInsert = Base.Caches[type].AllowUpdate = Base.Caches[type].AllowDelete = allowUpdate;
}
Base.Caches[typeof(CopyQuoteFilter)].AllowUpdate = true;
Base.Caches[typeof(RecalcDiscountsParamFilter)].AllowUpdate = true;
Base.Actions[nameof(Base.Approval.Submit)]
.SetVisible(row.Status == PMQuoteStatusAttribute.Draft);
Base.actionsFolder
.SetVisible(nameof(Base.Approval.Approve), Base.Actions[nameof(Base.Approval.Approve)].GetVisible());
Base.actionsFolder
.SetVisible(nameof(Base.Approval.Reject), Base.Actions[nameof(Base.Approval.Reject)].GetVisible());
Base.Actions[nameof(EditQuote)]
.SetVisible(row.Status != PMQuoteStatusAttribute.Draft);
Base.Actions[nameof(Base.Approval.Submit)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.Draft && !opportunityIsClosed);
Base.Actions[nameof(Base.Approval.Approve)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);
Base.Actions[nameof(Base.Approval.Reject)]
.SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);
Base.Actions[nameof(EditQuote)]
.SetEnabled(row.Status != PMQuoteStatusAttribute.Draft && row.Status != PMQuoteStatusAttribute.Closed);
Base.Actions[nameof(Base.CopyQuote)]
.SetEnabled(Base.Caches[typeof(PMQuote)].AllowInsert);
Base.Actions[nameof(PMDiscount.GraphRecalculateDiscountsAction)]
.SetEnabled((row.Status == PMQuoteStatusAttribute.Draft));
Base.Actions[nameof(Base.PrimaryQuote)].SetEnabled(!String.IsNullOrEmpty(row.OpportunityID) && row.IsPrimary == false && row.Status != PMQuoteStatusAttribute.Closed);
Base.Actions[nameof(Base.SendQuote)].SetEnabled(row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent, PMQuoteStatusAttribute.Closed));
Base.Actions[nameof(Base.PrintQuote)].SetEnabled(true);
Base.convertToProject.SetEnabled( (row.OpportunityID == null || row.IsPrimary == true) && row.QuoteProjectID == null && row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent));
PXUIFieldAttribute.SetEnabled<PMQuote.subject>(sender, row, true);
PXUIFieldAttribute.SetEnabled<PMQuote.status>(sender, row, false);
}
}
}

Adding Duration in dateTimePicker

I have two DateTimePickers one as Start Time and other one as end time.
I also have a text box that has duration.
I would like to know how can I add the duration to start time datetimePicker to automatically get the end time in the endTime dateTimePicker?
Though I believe your Service Duration is a combobox, I've still used textbox as per your question.
Call textchanged. When text in textbox changes, the time is added to dateTimePicker2
private void textBox1_TextChanged(object sender, EventArgs e)
{
int mins = Convert.ToInt32(textBox1.Text);
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(mins);
}
For combobox, call textchanged as well.
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == -1 || comboBox1.Text == null)
{
dateTimePicker2.Value = dateTimePicker1.Value;
}
else if (comboBox1.Text == "15")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(15);
}
else if (comboBox1.Text == "30")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(30);
}
else if (comboBox1.Text == "60")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(60);
}
}

KeyPressed in textbox not working

I tried to get the code below working, but to no avail.
I have to make a login window, and except from the Log in button I want by pressing the Enter key in password textbox the result to be the same. C# 2010.
private void button1_Click(object sender, EventArgs e)
{
int ok=0;
if (textBox1.Text == "administrator" && textBox2.Text == "administrator")
{
ok = 1;
this.Hide();
Admin admin = new Admin();
admin.ShowDialog();
}
if (textBox1.Text == "jucator" && textBox2.Text == "jucator")
{
ok = 1;
this.Hide();
}
if (ok == 0)
{
label2.Text = "nume user sau parola incorecta";
label2.Visible = true;
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, new EventArgs());
}
}
You should use the KeyUp event It's more reliable in you case.
Then check for the pressed key.
e.g.:
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//DoLogin... in your case it would be
button1_Click(null,null);
e.Handled = true;
}
else
{
e.Handled = false;
}
}
On a side note: I really discourage you to use that Log In method, comparing strings to a hardcoded strings is really a waste, there're better scenarios specially in an environment where you have multiple users Otherwise why would you require a login?

How to change text of a cell at runtime in XtraReport?

How to change text of a cell at runtime in XtraReport?
I am using "DevExpress v2011 vol 1".
I have a few cells and I can change their text one by one using PreviewClick event as below.
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbccc"; e.PreviewControl.Refresh();
}
But, in that event I need to change text of other cells simultaneously. I tried below and got no luck
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbcc";
otherCell1.Text = "rrrttcwwww"
e.PreviewControl.Refresh();
}
Best Regards,
Orgil.D
You can handle the DataSourceRowChanged event of the XtraReport Class
private void rpt_DataSourceRowChanged(object sender, DataSourceRowEventArgs e)
{
MyClass xx = bidingSource[e.CurrentRow] as MyClass ;
if (string.IsNullOrWhiteSpace(xx.WorkDescription))
{
xrTableCell25.Visible = false;
xrTableRow3.Visible = false;
xrTableCell25.Text = "456";
}
else
{
xrTableCell25.Visible = true;
xrTableRow3.Visible = true;
xrTableCell25.Text = "123";
}
}

change the Text of Button

I have a Button in datagridview and its text is Start so when I Click on it the text now should be Stop and when I click again the text should be Start.
So i have written code but its didnt work for me
private void dgvCampaign_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is Button)
{
Button btn = e.Control as Button;
if(btn.Text=="Start")
btn.Text = "Stop";
else
btn.Text = "Start";
}
}
try to use CellContentClick event
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString().Length > 0)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString() == "Start")
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Stop";
}
else
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}
else
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}

Resources