i have 5 checkboxlists, and each of the checkboxlists have the same 6 checkboxes.
i have to check these checkboxlists during page_Load under certain conditions.
How do i do that.?
for (int j = 0; j < no_of_listitem; j++)
{
SqlCommand check = new SqlCommand("SELECT ISGoal1, ISGoal2,ISGoal3, ISGoal4,ISGoal5 FROM PRM2011_EMPLOYEE_GOAL WHERE EmployeeID = '" + employeeid[j] + "'", con);
SqlDataReader y = check.ExecuteReader();
while (y.Read())
{
if (null != y && y.HasRows)
{
string yes_or_no = y["ISGoal1"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList1.Items[j].Selected = true;
}
//else CheckBoxList1.Items[j].Selected = false;
yes_or_no = y["ISGoal2"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList2.Items[j].Selected = true;
}
//else CheckBoxList2.Items[j].Selected = false;
yes_or_no = y["ISGoal3"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList3.Items[j].Selected = true;
}
//else CheckBoxList3.Items[j].Selected = false;
yes_or_no = y["ISGoal4"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList4.Items[j].Selected = true;
}
//else CheckBoxList4.Items[j].Selected = false;
yes_or_no = y["ISGoal5"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList5.Items[j].Selected = true;
}
//else CheckBoxList5.Items[j].Selected = false;
}
}
y.Close();
}
employeeid[] contains id of 6 employees.no_of_listitems is 6 which is the list of thses 6 employee ids.
Create a list with your CheckBoxList in it. Then, replace the code with something like this:
for(int z = 1; z <= checkboxLists.Count; z++)
{
checkboxLists[z].Items[j].Selected = y["ISGoal" + z].ToString().Trim() == "yes";
}
Keep in mind though that this code is not type-safe. Normally, you'd want to avoid using string in your code and y["ISGoal"+z] might be null. If it is, the application will crash. This mean you want to make checks to make sure it's ok. Trying to make a ToString() or Trim() on null will make a NullPointerException. You might also want to change "yes" by bit in your database. It would be much more safe to work with. What if someone writes "true" instead of yes?
I hope it helps out. If you have any question, don't hesitate.
Related
I am developing an xamarin.forms app ,I have various fields like Item Name ,Item Number and location ,here Location of all the items are same ,by entering names or number of the items the values are generated automatically because name and number are unique but since the location number is common is for all the items I am not able to populate correct data related to a particular field ,I am using sqlite database in my project can anyone please suggest me on what basis can I generate related values ?
Here is the code
public async void OnSearch_Location(object o, EventArgs args)
{
if (location.Text == string.Empty || location.Text == null)
{
await Navigation.PushAsync(new ListValuePage("Location", filePath,
pos, list));
}
else
{
for (int p = 0; p < list.Count; p++)
{
if (list.ElementAt(p).Aisle + "." + list.ElementAt(p).Bin +
"." + list.ElementAt(p).Level == location.Text)
{
line.Text =
Convert.ToString(list.ElementAt(p).Line_Number);
location.Text = list.ElementAt(p).Aisle + "." +
list.ElementAt(p).Bin + "." + list.ElementAt(p).Level;
item.Text = list.ElementAt(p).Item_Number;
name.Text = list.ElementAt(p).Name;
if (list.ElementAt(p).Order_Qty == 0)
{
order_uom.Text = "";
}
else
{
order_qty.Text =
Convert.ToString(list.ElementAt(p).Order_Qty);
}
order_uom.Text = list.ElementAt(p).Order_UOM;
if (list.ElementAt(p).Consumption_UOM == string.Empty ||
list.ElementAt(p).Consumption_UOM == null)
{
consume_lbl.IsVisible = false;
consume_qty.IsVisible = false;
consume_uom.IsVisible = false;
}
else
{
consume_lbl.IsVisible = true;
consume_qty.IsVisible = true;
consume_uom.IsVisible = true;
if (list.ElementAt(p).Consumption_Qty == 0)
{
consume_qty.Text = "";
}
else
{
consume_qty.Text =
Convert.ToString(list.ElementAt(p).Consumption_Qty);
}
consume_uom.Text = list.ElementAt(p).Consumption_UOM;
}
}
}
}
}
I have a page that runs reports on sales for a time period. When I run it for a month with around 88 transactions, its take a while but I can live with it for now.
Problem is when I try run the page for a year or over 3 months, its takes around 30minutes then goes to an error page saying "The cms.kics.com.au isnt working.. It didnt send any data...err_empty_response".
]
First thing comes to mind is there is too much data to return and its timing out on the request.
I have increased the execution time in the web.config and also the page timeout but no luck.
<httpRuntime maxRequestLength="409600" executionTimeout="720" />
Page.Server.ScriptTimeout = 3600;
I also tried flushing the data each time it goes in the repeater but doesn't do anything.
The code behide calculates the totals for the data range works fine but when it populates the salesrepeater with all the products that was sold, I get a timeout.
Is there a way to resolve this?
I was thinking maybe a stored procedure to run in the background that calculates the total for all products and on the repeater, just to output each item.
sales by 3 months can go up to 300-400.
Please see below code.
protected void BtnFilter_Click(object sender, EventArgs e)
{
if (StartDate.SelectedDate == null && FinishDate.SelectedDate == null)
return;
startDate = DateTime.Parse(StartDate.SelectedDate.ToString()).Date;
endDate = DateTime.Parse(FinishDate.SelectedDate.ToString()).Date;
DateTime now = DAL.TimeZoneConversion.ConvertDateTime(DateTime.UtcNow, thisShop.Company.TimeZoneLocationID);
CurrentDateTimeLiteral.Text = now.ToString() + " (" + thisShop.Company.TimeZoneLocationID + ")";
DateRangeLiteral.Text = startDate.ToShortDateString() + " - " + endDate.ToShortDateString();
TaxTypeLiteral.Text = thisShop.TaxName;
TaxTypeLiteral2.Text = thisShop.TaxName;
TaxTypeLiteral3.Text = thisShop.TaxName;
TaxTypeLiteral4.Text = thisShop.TaxName;
TaxTypeLiteral5.Text = thisShop.TaxName;
TaxTypeLiteral6.Text = thisShop.TaxName;
TaxTypeLiteral7.Text = thisShop.TaxName;
TaxTypeLiteral8.Text = thisShop.TaxName;
TaxTypeLiteral9.Text = thisShop.TaxName;
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
decimal totalPAmount = 0;
decimal totalPTax = 0;
decimal totalDAmount = 0;
decimal totalDTax = 0;
decimal totalAmount = 0;
decimal totalTax = 0;
var shopOrders = (from shopOrder in scope.Extent<ORM.Shoporder>()
where shopOrder.ShopId == shopId &&
shopOrder.CreateDateTime.Date >= startDate && shopOrder.CreateDateTime.Date <= endDate && shopOrder.IsDeleted == false &&
(shopOrder.IsReceiptSent == true || shopOrder.IsReceiptSkipped == true)
orderby shopOrder.CreateDateTime descending
select shopOrder);
foreach (ORM.Shoporder thisShopOrder in shopOrders.ToList())
{
decimal orderTotal = thisShopOrder.TotalCostIncludingTax; //DAL.DataClasses.ShopOrder.CalculateOrderTotal(thisShopOrder.ShopOrderId);
totalAmount += thisShopOrder.TotalCostIncludingTax;
totalTax += thisShopOrder.TotalTaxCost;
totalPAmount += thisShopOrder.ProductCostIncludingTax;
totalPTax += thisShopOrder.ProductTaxCost;
totalDAmount += thisShopOrder.DeliveryCostIncludingTax;
totalDTax += thisShopOrder.DeliveryTaxCost;
}
TotalLiteral.Text = totalAmount.ToString("C");
TotalTaxLiteral.Text = totalTax.ToString("C");
TotalDLiteral.Text = totalDAmount.ToString("C");
TotalDTaxLiteral.Text = totalDTax.ToString("C");
TotalPLiteral.Text = totalPAmount.ToString("C");
TotalPTaxLiteral.Text = totalPTax.ToString("C");
ReportDiv.Visible = true;
Populate();
}
private void Populate()
{
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
var result = from o in scope.Extent<ORM.Shopproductvariationprice>()
where o.Shopproduct.Shopcategory.ShopId == shopId
orderby o.Name, o.PriceIncludingTax
select o;
SaleRepeater.DataSource = result.ToList();
SaleRepeater.DataBind();
}
protected void SaleRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
ORM.Shopproductvariationprice thisPrice = (ORM.Shopproductvariationprice)item.DataItem;
Literal ProductNameLiteral = (Literal)item.FindControl("ProductNameLiteral");
Literal ProductCountLiteral = (Literal)item.FindControl("ProductCountLiteral");
Literal ProductAmountIncludingTaxLiteral = (Literal)item.FindControl("ProductAmountIncludingTaxLiteral");
Literal ProductAmountExcludingTaxLiteral = (Literal)item.FindControl("ProductAmountExcludingTaxLiteral");
Literal ProductTaxLiteral = (Literal)item.FindControl("ProductTaxLiteral");
int productCount = 0;
decimal productAmount = 0;
decimal productTax = 0;
ProductNameLiteral.Text = thisPrice.Name;
var shopOrders = (from shopOrder in scope.Extent<ORM.Shoporder>()
where shopOrder.ShopId == shopId &&
shopOrder.CreateDateTime.Date >= startDate && shopOrder.CreateDateTime.Date <= endDate && shopOrder.IsDeleted == false &&
(shopOrder.IsReceiptSent == true || shopOrder.IsReceiptSkipped == true)
orderby shopOrder.CreateDateTime descending
select shopOrder);
foreach (ORM.Shoporder thisShopOrder in shopOrders.ToList())
{
foreach (ORM.Shoporderproduct thisShopOrderProduct in DAL.DataClasses.ShopOrder.GetProductsInOrder(thisShopOrder.ShopOrderId))
{
if (thisShopOrderProduct.ShopProductVariationPriceId == thisPrice.ShopProductVariationPriceId)
{
productCount += thisShopOrderProduct.Quantity;
productAmount += (thisShopOrderProduct.Quantity * thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax);
if (thisShopOrderProduct.Shopproductvariationprice.Shopproduct.IsTaxable)
{
decimal taxRate = 100 + thisShop.TaxPercent;
decimal thisProductPriceExcludingTax = thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax * 100;
thisProductPriceExcludingTax = thisProductPriceExcludingTax / taxRate;
decimal thisProductTax = thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax - thisProductPriceExcludingTax;
productTax += (thisShopOrderProduct.Quantity * thisProductTax);
}
}
}
}
ProductCountLiteral.Text = productCount.ToString();
ProductAmountIncludingTaxLiteral.Text = productAmount.ToString("C");
ProductAmountExcludingTaxLiteral.Text = (productAmount - productTax).ToString("C");
ProductTaxLiteral.Text = productTax.ToString("C");
totalProductAmount += productAmount;
totalProductTax += productTax;
totalItemsSold += productCount;
Response.Flush();
}
if (item.ItemType == ListItemType.Footer)
{
Literal TotalCountLiteral = (Literal)item.FindControl("TotalCountLiteral");
Literal TotalAmountIncludingTaxLiteral = (Literal)item.FindControl("TotalAmountIncludingTaxLiteral");
Literal TotalAmountExcludingTaxLiteral = (Literal)item.FindControl("TotalAmountExcludingTaxLiteral");
Literal TotalTaxLiteral = (Literal)item.FindControl("TotalTaxLiteral");
TotalCountLiteral.Text = totalItemsSold.ToString();
TotalAmountIncludingTaxLiteral.Text = totalProductAmount.ToString("C");
TotalAmountExcludingTaxLiteral.Text = (totalProductAmount - totalProductTax).ToString("C");
TotalTaxLiteral.Text = totalProductTax.ToString("C");
}
}
}
i am trying to make the drop down list to be visible for certain user only. for example for user =1 i want the drop down list to be visible and for user = 2 i don't want the drop down list to be visible.
i have tried this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}
}
i dont get the result that i want when i do this. why is that?? thanks in advance.
What are you trying to do please see you if condition you are checking if user==1 || user==2 || user==4
than you are showing dropdownlist and in same if condition you are checking if user==3 how is this possible if user==1 || user==2 || user==4 than it cannot be ==3 change your code like this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
}
else if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}
I'm having one grid and one link button on that grid which have rowcommand but whenever i click on that button it shows me error that there is no row at column 0.
i've debugged whole code so many time but always it's showing me that there is no column even if there is data in that specific column of dataset.
I'm new to asp.net as well as to sql so only knowing that how to put code but logic is not getting cleared please can anyone clear this query. your help is too much for me.
protected void grdManageBRProperty_RowCommand(object sender, GridViewCommandEventArgs e)
{
Session["prptIdBRP"] = e.CommandArgument.ToString();
string id = Session["prptIdBRP"].ToString();
ds = obj.sel("select tblPropertyMaster.PropertyId, tblPropertyTypeMaster.PropertyTypeName, tblSubPropertyTypeMaster.PropertySubTypeName, tblPropertyMaster.Floor, tblPropertyMaster.PlotArea, tblPropertyMaster.BuitUpArea, tblPropertyMaster.ExpectedAmount, tblCityMaster.CityName, tblLocationMaster.LocationName, tblBuilderMaster.BuilderName, tblPropertyMaster.Description, tblPropertyMaster.Remarks, tblPropertyMaster.Furniture AS Furntr, tblPropertyMaster.IsAdvertise, tblPropertyMaster.Status, tblPropertyMaster.OwnerName, tblPropertyMaster.Address, tblPropertyMaster.ContactNo, tblPropertyMaster.MobileNo, tblPropertyMaster.EmailId from tblPropertyMaster INNER JOIN tblPropertyTypeMaster ON tblPropertyMaster.PropertyTypeId=tblPropertyTypeMaster.PropertyTypeId INNER JOIN tblSubPropertyTypeMaster ON tblPropertyMaster.PropertySubTypeId=tblSubPropertyTypeMaster.PropertySubTypeId INNER JOIN tblCityMaster ON tblPropertyMaster.CityId=tblCityMaster.CityId INNER JOIN tblLocationMaster ON tblPropertyMaster.LocationId=tblLocationMaster.LocationId INNER JOIN tblBuilderMaster ON tblPropertyMaster.BuilderName=tblBuilderMaster.BuilderId where tblPropertyMaster.PropertyId= '" + id + "'");
string furn = ds.Tables[0].Rows[0]["Furntr"].ToString();
if (furn == "True")
{
rbBRPFetchFurnitureYesC.Checked = true;
}
if (furn == "False")
{
rbBRPFetchFurnitureNoC.Checked = true;
}
string stts = ds.Tables[0].Rows[0]["Status"].ToString();
if (stts == "True")
{
rbBRPFetchStatusSoldC.Checked = true;
}
if (stts == "False")
{
rbBRPFetchStatusNtSoldC.Checked = true;
}
string advrts = ds.Tables[0].Rows[0]["IsAdvertise"].ToString();
if (advrts == "True")
{
rbBRPFetchIsAdYesC.Checked = true;
}
if (advrts == "False")
{
rbBRPFetchIsAdNoC.Checked = true;
}
ddlBRPFetchTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertyTypeName"].ToString();
ddlBRPFetchSbTypOfPrptC.SelectedItem.Text = ds.Tables[0].Rows[0]["PropertySubTypeName"].ToString();
txtBRPFetchFloorC.Text = ds.Tables[0].Rows[0]["Floor"].ToString();
txtBRPFetchPlotAreaC.Text = ds.Tables[0].Rows[0]["PlotArea"].ToString();
txtBRPFetchBiultUpAreaC.Text = ds.Tables[0].Rows[0]["BuitUpArea"].ToString();
txtBRPFetchAmountC.Text = ds.Tables[0].Rows[0]["ExpectedAmount"].ToString();
ddlBRPFetchCityC.SelectedItem.Text = ds.Tables[0].Rows[0]["CityName"].ToString();
ddlBRPFetchLocationC.SelectedItem.Text = ds.Tables[0].Rows[0]["LocationName"].ToString();
ddlBRPFetchBuilderNameC.SelectedItem.Text = ds.Tables[0].Rows[0]["BuilderName"].ToString();
txtBRPFetchDescC.Text = ds.Tables[0].Rows[0]["Description"].ToString();
txtBRPFetchRemrksC.Text = ds.Tables[0].Rows[0]["Remarks"].ToString();
txtBRPFetchOwnerNameC.Text = ds.Tables[0].Rows[0]["OwnerName"].ToString();
txtBRPFetchAddressC.Text = ds.Tables[0].Rows[0]["Address"].ToString();
txtBRPFetchConNumberC.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();
txtBRPFetchMobNumberC.Text = ds.Tables[0].Rows[0]["MobileNo"].ToString();
txtBRPFetchEmailC.Text = ds.Tables[0].Rows[0]["EmailId"].ToString();
pnlBRPUpdateBySessionCriteria.Visible = true;
pnlSearchBRPByDate.Visible = false;
pnlBRPManageGrid.Visible = false;
}
As a precautionary step always first check Rows are present and then only extract values from rows.
if(ds.Tables[0].Rows.Count > 0)
{
// Your code
}
I have a function like this
public bool CheckMentorAccess()
{
bool blnAllow = false;
try
{
string strSelectMentorQuery = "SELECT COUNT(DISTINCT MLL.LED_ID) FROM M_USER_DETAILS MUD INNER JOIN M_LEADERLED MLL " + "ON MLL.LED_ID = MUD.PK_ID WHERE MLL.LEADER_ID = '" + Session["UserID"].ToString() + "' AND MUD.ACTIVE = 1 AND MLL.START_DATE <= Getdate() AND" + " MLL.END_DATE > Getdate()";
int intNoOfMembers = Convert.ToInt32(cSQLHelper.myExecuteScalar(strSelectMentorQuery));
if (intNoOfMembers > 0)
{
blnAllow = true;
}
}
catch (Exception ex)
{
ExceptionLogger.LogException(ex);
blnAllow = false;
}
// Return the value
return blnAllow;
}
And then I use if like this
if ((Int32.Parse(Session["ROLE_ID"].ToString()) == 3) && (CheckMentorAccess() == true))
{
cmbempList.Visible = true;
}
but it is throwing a null reference exception on the first line of the sample above
Can anyone help me out..
You can try
if (Session["ROLE_ID"] != null && (Int32.Parse(Session["ROLE_ID"].ToString()) == 3) && (CheckMentorAccess() == true))
{
cmbempList.Visible = true;
}
First check that Session["ROLE_ID"] exists before you use ToString.
It is always safer to use Convert.ToString.
Well, if the stack trace only points at that line, I'd guess this is the problem:
Int32.Parse(Session["ROLE_ID"].ToString())
That will throw a NullReferenceException if Session["ROLE_ID"] returns null.
(It will throw FormatException if the value exists in the session but isn't a valid integer.)
It's possible that it's the call to CheckMentor() which is failing, of course - but then your stack trace should say so. That could fail if cSQLHelper is null, for example.
Try this - check the values you are using when you call the method:
if (Session["ROLE_ID"] != null)
{
if ((Int32.Parse(Session["ROLE_ID"]) == 3) && (CheckMentorAccess()))
{
cmbempList.Visible = true;
}
}
and check in the method
public bool CheckMentorAccess()
{
if (Session["UserID"] == null)
{
throw new NullReferenceException("UserID is null");
}
bool blnAllow = false;
try
{
string strSelectMentorQuery = "SELECT COUNT(DISTINCT MLL.LED_ID) FROM M_USER_DETAILS MUD INNER JOIN M_LEADERLED MLL " + "ON MLL.LED_ID = MUD.PK_ID WHERE MLL.LEADER_ID = '" + Session["UserID"].ToString() + "' AND MUD.ACTIVE = 1 AND MLL.START_DATE <= Getdate() AND" + " MLL.END_DATE > Getdate()";
int intNoOfMembers = Convert.ToInt32(cSQLHelper.myExecuteScalar(strSelectMentorQuery));
blnAllow = intNoOfMembers > 0;
}
catch (Exception ex)
{
ExceptionLogger.LogException(ex);
blnAllow = false;
}
// Return the value
return blnAllow;
}