How to Validate Column with Same Value? - asp.net

How to validate the column with same value, i try with this code :
protected void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
XPQuery<Inventory_Library.Inventory.t_barang_master> q = new XPQuery<Inventory_Library.Inventory.t_barang_master>(ses);
List<Inventory_Library.Inventory.t_barang_master> lst = (from o in q
where (o.nama_barang == e.OldValues["nama_barang"] && o.kode_barang == e.OldValues["kode_barang"])
select o).ToList<Inventory_Library.Inventory.t_barang_master>();
if (lst.Contains(e.OldValues["nama_barang"]))
{
e.RowError = "Nama barang yang anda masukkan telah terdaftar dalam sistem";
}
else if (lst.Contains(e.OldValues["kode_barang"]))
{
e.RowError = "Kode barang yang anda masukkan telah terdaftar dalam sistem";
}
}
but that's not work, how to solve this problem, thanks for the answer

problem solve, if you find the same problem with me, you can use this code:
protected void ASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
XPQuery<Inventory_Library.Inventory.t_kategori> q = new XPQuery<Inventory_Library.Inventory.t_kategori>(ses);
List<Inventory_Library.Inventory.t_kategori> lst = (from o in q
where (o.kategori == e.NewValues["kategori"])
select o).ToList<Inventory_Library.Inventory.t_kategori>();
if (lst.Count > 0)
{
e.RowError = "Kategori yang anda masukkan telah terdaftar dalam sistem";
}
}

Related

Dropdown is not getting selected

When I pass the string value to the dropdown, it is not getting selected. I am not sure why?
I've tried passing the value eg:ddlInitialIncidentType.Items.FindByValue("1").Selected = true; directly which works fine.
protected void btnIncTypeSave_Click(object sender, EventArgs e) {
string value;
if (rbIncTypeY.Checked == true) {
//getting the value number from the Label
value = label.Text;
ddlInitialIncidentType.ClearSelection();
//here I want to select the dropdown with the value number
ddlInitialIncidentType.Items.FindByValue(value).Selected = true;
}
}
Note: I am assigning the value to the label in the below method
function prioritySelection(sender) {
var e = document.getElementById(sender.id);
e = e.value;
if (e == 2 || e == 4 || e == 1 || e == 3)
{
$('#<%=lblInitialIncidentTypeCurrent.ClientID%>').html(e); $find("ContentPlaceHolder1_ContentPlaceHolder2_ModalPopupIncidentTypeChange").show();
}
protected void btnIncTypeSave_Click(object sender,EventArgs e)
{ string value; if (rbIncTypeY.Checked==true) {
value=label.Text; // did you check here that value gets value or not?} }
In your javascript code you have used the ID of the Label control as lblInitialIncidentTypeCurrent where as in your server side code your are using some other Label control.
Replace this
value = label.Text;
with
value = lblInitialIncidentTypeCurrent.Text;
There was some problem by using the Label to store the value.
But by using HiddenField it is solved.
Thanks all for the answers provided.
below is the code for it,
//aspx.cs
<asp:HiddenField ID="hdtest" runat="server" />
protected void btnIncTypeSave_Click(object sender, EventArgs e)
{
string value;
if (rbIncTypeY.Checked ==true)
{
value = hdnIncType.Value;
ddlInitialIncidentType.ClearSelection();
ddlInitialIncidentType.Items.FindByValue(value).Selected = true;
ModalPopupIncidentTypeChange.Hide();
rbIncTypeY.Checked = false;
}
}
//aspx
function prioritySelection(sender) {
var e = document.getElementById(sender.id);
e = e.value;
if (e == 2 || e == 4 || e == 1 || e == 3) {
$('#<%=hdtest.ClientID%>').val(e);
$find("ContentPlaceHolder1_ContentPlaceHolder2_ModalPopupIncidentTypeChange").show();
}
}

Telerik Load on demand RadOrgChart not loading nodes after 3 levels

In Telerik Load on demand RadOrgChart, I'm Loading data through server.
It will take up to 2 levels of data on every time click of each node. but data is coming properly from server,but problem is nodes not generated for those data. what should I do to get it properly?
private void CreateTeams() {
teams = new DataTable();
teams.Columns.Add("UniqueID");
teams.Columns.Add("ReportsTo");
teams.Columns.Add("Collapsed");
var myList = (List < NodeViewModel > ) Session["items"];
foreach(var nodeitem in myList) {
if (nodeitem.IsManager == true && nodeitem.level == 0) {
teams.Rows.Add(new string[] {
nodeitem.EmployeeBadge, null, "0"
});
} else {
teams.Rows.Add(new string[] {
nodeitem.EmployeeBadge, nodeitem.ManagerBadge, "1"
});
}
}
}
protected void Page_Load(object sender, EventArgs e) {
if (Request.Cookies["badgeName"] != null) {
var value = Request.Cookies["badgeName"].Value;
EmployeeRepository obj = new EmployeeRepository();
var myList = (List < NodeViewModel > ) Session["items"];
try {
obj.CreateLevel(new NodeViewModel() {
EmployeeBadge = value
}, myList);
logger.Info("OrgChart:Page_Load()::success");
} catch (Exception ex) {
logger.Error(string.Concat("OrgChart:Page_Load()::", ex.Message));
logger.Error(string.Concat("OrgChart:Page_Load()::", ex.StackTrace));
}
Response.Cookies["badgeName"].Expires = DateTime.Now.AddDays(-1);
}
CreateTeams();
CreateEmployees();
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "UniqueID";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "ReportsTo";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataCollapsedField = "Collapsed";
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataGroupCollapsedField = "Collapsed";
//RadOrgChart1.RenderedFields.NodeFields.Add(new Telerik.Web.UI.OrgChartRenderedField() { DataField = "Team" });
RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = teams;
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "EmployeeID";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "UniqueID";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataTextField = "Name";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataImageUrlField = "ImageUrl";
RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataSource = employees;
RadOrgChart1.DataBind();
}

How to count the no of records in gridview which have some particular data in a coloumn

How to count the no of records in Gridview which have some particular data in a column
name result
======== ======
krishna pass
sanjay pass
ajay fail
out put needed in grid view - above Gridview already present,according to that grid i have to make another grid to count results
result no
====== =====
pass 2
fail 1
in data row bound , i calculated
protected void GVKeywordReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow pr = ((DataRowView)e.Row.DataItem).Row;
int oldPos = Convert.ToInt32(pr["oldposition"]);
int newPos = Convert.ToInt32(pr["newposition"]);
GVKeywordReport.HeaderRow.Cells[3].Text = txtfrmdate.Text;
GVKeywordReport.HeaderRow.Cells[4].Text = txtEndDate.Text;
GVKeywordReport.HeaderRow.BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#B3B300");
e.Row.Cells[5].BackColor = ColorTranslator.FromHtml("#FFFFFF");
if (oldPos == newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF950E");
e.Row.Cells[6].Text = "No Change";
nc= nc+1;
}
else if (oldPos > newPos)
{
e.Row.BackColor = ColorTranslator.FromHtml("#FFFFCC");
e.Row.Cells[6].Text = "Improved";
imprv= imprv+1;
}
else
{
e.Row.BackColor = ColorTranslator.FromHtml("#FF0000");
e.Row.Cells[6].Text = "Decreased";
decrs=decrs+1;
}
// e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#7DA647");
}
txt_TargetReached.Text = "0";
txtDecreased.Text =Convert.ToString(decrs);

Filtering on multiple parameters

I want to filter on multiple parameters in crystal reports through combo box but the problem is one filter is active at a time.
Here is the code of index change of both combo boxes:
protected void drpUserName_SelectedIndexChanged(object sender, EventArgs e)
{
username = drpUserName.SelectedValue;
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("LeaveReport.rpt"));
rd.SetParameterValue("username", username);
rd.SetParameterValue("status", status);
rd.SetDatabaseLogon("cde_portal", "credyna", "SERVER\\SQLEXPRESS", "lbs");
CrystalReportViewer1.ReportSource = rd;
}
protected void drpStatus_SelectedIndexChanged(object sender, EventArgs e)
{
status = drpStatus.SelectedValue;
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("LeaveReport.rpt"));
rd.SetParameterValue("status", status);
rd.SetParameterValue("username", username);
rd.SetDatabaseLogon("cde_portal", "credyna", "SERVER\\SQLEXPRESS", "lbs");
CrystalReportViewer1.ReportSource = rd;
}
And here is record selection formula:
If {?username} = "-1" Then // -1 for all values
{tblEmployee.Employeer_UserName} <> {?username} // return all records
Else
{tblEmployee.Employeer_UserName} = {?username} // return selected records
and IF {?status} = "-1" Then
{tblLeave.leave_status} <> {?status}
Else
{tblLeave.leave_status} = {?status}
One more thing in above formula: if I check {?username} first and then check {?status} in this case {?username} filtering is working, but if I check {?status} first then {?status}, filtering works fine.
you can do this by this way...
protected void drpUserName_SelectedIndexChanged(object sender, EventArgs e)
{
string strSelection = "1=1";
rd.SetParameterValue("username", drpUserName.SelectedValue);
rd.SetParameterValue("status", drpStatus.SelectedValue);
if (drpUserName.SelectedValue != "-1")
{
strSelection = strSelection + "And {tblEmployee.Employeer_UserName}=" + "\""+ drpUserName.SelectedValue+"\"";
}
if ( drpStatus.SelectedValue != "-1")
{
strSelection = strSelection + "And {tblLeave.leave_status}=" +"\""+ drpStatus.SelectedValue+"\"" ;
}
rd.RecordSelectionFormula = strSelection;
rd.SetDatabaseLogon("cde_portal", "credyna", "SERVER\\SQLEXPRESS", "lbs");
CrystalReportViewer1.ReportSource = rd;
}
protected void drpStatus_SelectedIndexChanged(object sender, EventArgs e)
{
string strSelection = "1=1";
rd.SetParameterValue("username", drpUserName.SelectedValue);
rd.SetParameterValue("status", drpStatus.SelectedValue);
if (drpUserName.SelectedValue != "-1")
{
strSelection = strSelection + "And {tblEmployee.Employeer_UserName}=" + "\"" + drpUserName.SelectedValue + "\"";
}
if (drpStatus.SelectedValue != "-1")
{
strSelection = strSelection + "And {tblLeave.leave_status}=" + "\"" + drpStatus.SelectedValue + "\"";
}
rd.RecordSelectionFormula = strSelection;
rd.SetDatabaseLogon("cde_portal", "credyna", "SERVER\\SQLEXPRESS", "lbs");
CrystalReportViewer1.ReportSource = rd;
}

How to add filters with customer data source of telerik reporting?

I set my report‘s data source in the backstage of the page that display the report.The code is below:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string acceptedStatus = QuoteStatusEnum.Accepted.ToString();
string rejectedStatus = QuoteStatusEnum.Rejected.ToString();
string canceledStatus = QuoteStatusEnum.Canceled.ToString();
IList<QuoteRequest> list = ServiceFactory.QuoteRequestService.QueryItems(p => (p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus) ||
(p.QuoteRequestStatus.QuoteRequestStatusName == rejectedStatus) ||
(p.QuoteRequestStatus.QuoteRequestStatusName == canceledStatus)).OrderBy(p => p.CreatedBy).ToList();
var data = from d in list
select new
{
ClientName = d.Client.CompanyName,
Client = d.Client.ClientID,
CompanyName = d.Client.CompanyName,
QuoteNumber = d.QuoteNumber,
PropertyAddress = d.Property.PropertyAddressLine1 + (string.IsNullOrEmpty(d.Property.PropertyAddressLine2) ? "" : " ," + d.Property.PropertyAddressLine2),
QuotePrice = d.QuotePrice.HasValue ? d.QuotePrice.Value : 0,
ClientContact = ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).FirstName + " " + ServiceFactory.ContactService.Read(p => p.ContactID == d.ClientContactID).LastName,
IsConverted = d.QuoteRequestStatus.QuoteRequestStatusName == "Accepted" ? "Yes" : "No",
ModifiedDate = d.ModifiedDate ?? DateTime.Now.AddYears(-10)
};
int pastDueCount = list.Count(p => p.ClientDueDate < DateTime.Today);
var instanceReporSouce = new InstanceReportSource();
instanceReporSouce.ReportDocument = new CompletedQuotesReport();
instanceReporSouce.ReportDocument.Reports.First().DataSource = data;
ReportViewer1.ReportSource = instanceReporSouce;
}
}
Now, I want to add some filter to the report.just like the effect that add filter in the design view by using "Fields.XX=parameter.value" expression,For there is no data source in the report now,so it can't be use 'Fields.XX......' expressions.How can i achieve my goal by programs in the backstage. BTW,I try to add parameter by code:
instanceReporSouce.ReportDocument.Reports.First().ReportParameters.Add(new ReportParameter("TotalAccepted", ReportParameterType.String, "TotalAccepted:" + list.Count(p => p.QuoteRequestStatus.QuoteRequestStatusName == acceptedStatus)));
I can get the parameters. but still can't filter data. How can i solve this problem?
Any suggestion is appreciated,
Best regards,
Tang.
private void RegisterByDept_NeedDataSource(object sender, EventArgs e)
{
string groupBy = string.Empty;
string sortBy = string.Empty;
Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
var payoutUID = report.Parameters["payoutUID"].Value.ToString();
// some code here...
}

Resources