If from date is selected in calendar Extender, I need to clear previous dates than from date from To Date Calendar as shown in figure. Please provide your comments
Use this CSS property on your any .css class
.ajax__calendar_day_disabled
{
background-color:#ccc !important;
color:#eee !important;
}
use above css class in date textbox like CssClass="disable_past_dates"
and use script
function getElementsByClassName(a, b) { var c = []; var d = a.getElementsByTagName("*"); for (var e = 0; e < d.length; e++) { if (d[e].className.indexOf(b) != -1) { c.push(d[e]) } } return c } function DisableDates(a) { if (a._element.className.indexOf("disable_past_dates") != -1) { var b = getElementsByClassName(a._days, "ajax__calendar_day"); var c = (new Date).setHours(0, 0, 0, 0); for (var d = 0; d < b.length; d++) { try { if (b[d].date.setHours(0, 0, 0, 0) >= c) { b[d].className = "ajax__calendar_day" } else { b[d].className = "ajax__calendar_day ajax__calendar_day_disabled" } } catch (e) { } } } if (a._element.className.indexOf("disable_future_dates") != -1) { var b = getElementsByClassName(a._days, "ajax__calendar_day"); var c = (new Date).setHours(0, 0, 0, 0); for (var d = 0; d < b.length; d++) { try { if (b[d].date.setHours(0, 0, 0, 0) <= c) { b[d].className = "ajax__calendar_day" } else { b[d].className = "ajax__calendar_day ajax__calendar_day_disabled" } } catch (e) { } } } } AjaxControlToolkit.CalendarBehavior.prototype.show = function (a) { this._ensureCalendar(); if (!this._isOpen) { var b = new Sys.CancelEventArgs; this.raiseShowing(b); if (b.get_cancel()) { return } this._isOpen = true; this._popupBehavior.show(); if (this._firstPopUp) { this._switchMonth(null, true); switch (this._defaultView) { case AjaxControlToolkit.CalendarDefaultView.Months: this._switchMode("months", true); break; case AjaxControlToolkit.CalendarDefaultView.Years: this._switchMode("years", true); break } this._firstPopUp = false } this.raiseShown(); DisableDates(this) } }; AjaxControlToolkit.CalendarBehavior.prototype._cell_onclick = function (a) { a.stopPropagation(); a.preventDefault(); if (!this._enabled) return; var b = a.target; var c = this._getEffectiveVisibleDate(); Sys.UI.DomElement.removeCssClass(b.parentNode, "ajax__calendar_hover"); switch (b.mode) { case "prev": case "next": this._switchMonth(b.date); break; case "title": switch (this._mode) { case "days": this._switchMode("months"); break; case "months": this._switchMode("years"); break } break; case "month": if (b.month == c.getMonth()) { this._switchMode("days") } else { this._visibleDate = b.date; this._switchMode("days") } break; case "year": if (b.date.getFullYear() == c.getFullYear()) { this._switchMode("months") } else { this._visibleDate = b.date; this._switchMode("months") } break; case "day": if (this._element.className.indexOf("disable_past_dates") != -1) { if (b.date.setHours(0, 0, 0, 0) >= (new Date).setHours(0, 0, 0, 0)) { this.set_selectedDate(b.date); this._switchMonth(b.date); this._blur.post(true); this.raiseDateSelectionChanged() } } else if (this._element.className.indexOf("disable_future_dates") != -1) { if (b.date.setHours(0, 0, 0, 0) <= (new Date).setHours(0, 0, 0, 0)) { this.set_selectedDate(b.date); this._switchMonth(b.date); this._blur.post(true); this.raiseDateSelectionChanged() } } else { this.set_selectedDate(b.date); this._switchMonth(b.date); this._blur.post(true); this.raiseDateSelectionChanged() } break; case "today": this.set_selectedDate(b.date); this._switchMonth(b.date); this._blur.post(true); this.raiseDateSelectionChanged(); break } DisableDates(this) };
This will disabled all the past dates but not clears it.
try this one,
CntrlID.MinDate = DateTime.Now;
CntrlID.MaxDate = DateTime.Today.AddMonths(12);
CntrlID.MaxDate = DateTime.Today.AddYears(100);
Related
I am trying to add a listing group tree in google ads api V10 but it is returning internal error. Here is my code:
public GoogleAwApi.AdGroupCriterionReturnValue MutateProductPartitionsForAdGroupGA(GoogleAwApi.AdGroupCriterionOperation[] operations, long clientId)
{
var result = new GoogleAwApi.AdGroupCriterionReturnValue();
AdGroupCriterionServiceClient service = this.AdGroupCriterionServiceGA;
List<AdGroupCriterionOperation> operationsGA = new List<AdGroupCriterionOperation>();
List<GoogleAwApi.AdGroupCriterion> results = new List<GoogleAwApi.AdGroupCriterion>();
List<GoogleAwApi.ApiError> partialFailures = new List<GoogleAwApi.ApiError>();
foreach (var item in operations)
{
try
{
var operand = (GoogleAwApi.BiddableAdGroupCriterion)item.operand;
// Start creating the criteron...
GoogleAdsResources.AdGroupCriterion adGroupCriterion = new GoogleAdsResources.AdGroupCriterion()
{
// The resource name the criterion will be created with. This will define the ID
// for the ad group criterion.
AdGroup = ResourceNames.AdGroup(clientId, item.operand.adGroupId),
//ResourceName = ResourceNames.AdGroupCriterion(clientId, item.operand.adGroupId, item.operand.criterion.id),
Status = Google.Ads.GoogleAds.V10.Enums.AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled
};
switch (operand.userStatus)
{
case GoogleAwApi.UserStatus.ENABLED:
adGroupCriterion.Status = AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled;
break;
case GoogleAwApi.UserStatus.REMOVED:
adGroupCriterion.Status = AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Removed;
break;
case GoogleAwApi.UserStatus.PAUSED:
adGroupCriterion.Status = AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Paused;
break;
default:
adGroupCriterion.Status = AdGroupCriterionStatusEnum.Types.AdGroupCriterionStatus.Enabled;
break;
}
string cType = item.operand.criterion.GetType().Name;
if (operand.biddingStrategyConfiguration != null)
{
var bids = operand.biddingStrategyConfiguration.bids;
var thidBid = (GoogleAwApi.CpcBid)bids[0];
adGroupCriterion.CpcBidMicros = thidBid.bid.microAmount;
adGroupCriterion.EffectiveCpcBidSource = Google.Ads.GoogleAds.V10.Enums.BiddingSourceEnum.Types.BiddingSource.AdGroup;
}
adGroupCriterion.ApprovalStatus = APIHelper.MapApprovalStatus(operand.approvalStatus);
adGroupCriterion.BidModifier = operand.bidModifier;
var criterion = (GoogleAwApi.ProductPartition)item.operand.criterion;
adGroupCriterion.CriterionId = criterion.id;
ListingGroupTypeEnum.Types.ListingGroupType lType = ListingGroupTypeEnum.Types.ListingGroupType.Unknown;
if (criterion.partitionType == GoogleAwApi.ProductPartitionType.SUBDIVISION)
{
lType = ListingGroupTypeEnum.Types.ListingGroupType.Subdivision;
adGroupCriterion.ResourceName = ResourceNames.AdGroupCriterion(clientId, item.operand.adGroupId, item.operand.criterion.id);
}
if (criterion.partitionType == GoogleAwApi.ProductPartitionType.UNIT)
{
lType = ListingGroupTypeEnum.Types.ListingGroupType.Unit;
}
var casevalue = (GoogleAwApi.ProductDimension)criterion.caseValue;
var lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Unknown;
var cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Unknown;
var lValue = "";
Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo listingDimensionInfo = null;
if (casevalue != null)
{
//Get listing Group Info
switch (casevalue.ProductDimensionType)
{
case "ProductType":
if (casevalue != null)
{
string[] caseValueItems = casevalue.ToString().Split(',');
if (caseValueItems.Length == 2)
{
if (caseValueItems[0].Contains("PRODUCT_TYPE_L1"))
lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level1;
if (caseValueItems[0].Contains("PRODUCT_TYPE_L2"))
lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level2;
if (caseValueItems[0].Contains("PRODUCT_TYPE_L3"))
lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level3;
if (caseValueItems[0].Contains("PRODUCT_TYPE_L4"))
lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level4;
if (caseValueItems[0].Contains("PRODUCT_TYPE_L5"))
lLevel = Google.Ads.GoogleAds.V10.Enums.ProductTypeLevelEnum.Types.ProductTypeLevel.Level5;
string[] lValueItems = caseValueItems[1].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
if (String.IsNullOrEmpty(lValue))
{
//isEverythingElse
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductType = new Google.Ads.GoogleAds.V10.Common.ProductTypeInfo
{ Level = lLevel }
};
}
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductType = new Google.Ads.GoogleAds.V10.Common.ProductTypeInfo
{ Level = lLevel, Value = lValue }
};
}
}
break;
case "Brand":
if (casevalue != null)
{
string[] caseValueItems = casevalue.ToString().Split(',');
if (caseValueItems.Length == 2)
{
string[] lValueItems = caseValueItems[1].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
}
if (caseValueItems.Length == 1)
{
string[] lValueItems = caseValueItems[0].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
}
//isEverythingElse
if (String.IsNullOrEmpty(lValue))
{
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductBrand = new Google.Ads.GoogleAds.V10.Common.ProductBrandInfo()
};
}
else
{
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductBrand = new Google.Ads.GoogleAds.V10.Common.ProductBrandInfo
{ Value = lValue }
};
}
}
break;
case "Custom":
if (casevalue != null)
{
string[] caseValueItems = casevalue.ToString().Split(',');
if (caseValueItems.Length == 2)
{
if (caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_0"))
cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index0;
if (caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_1"))
cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index1;
if (caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_2"))
cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index2;
if (caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_3"))
cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index3;
if (caseValueItems[0].Contains("CUSTOM_ATTRIBUTE_4"))
cIndex = Google.Ads.GoogleAds.V10.Enums.ProductCustomAttributeIndexEnum.Types.ProductCustomAttributeIndex.Index4;
string[] lValueItems = caseValueItems[1].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
if (String.IsNullOrEmpty(lValue))
{
//isEverythingElse
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductCustomAttribute = new Google.Ads.GoogleAds.V10.Common.ProductCustomAttributeInfo
{ Index = cIndex }
};
}
else
{
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductCustomAttribute = new Google.Ads.GoogleAds.V10.Common.ProductCustomAttributeInfo
{ Index = cIndex, Value = lValue }
};
}
}
}
break;
case "OfferId":
if (casevalue != null)
{
string[] caseValueItems = casevalue.ToString().Split(',');
if (caseValueItems.Length == 2)
{
string[] lValueItems = caseValueItems[1].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
}
if (caseValueItems.Length == 1)
{
string[] lValueItems = caseValueItems[0].Split(':');
if (lValueItems.Length == 2)
lValue = lValueItems[1].Trim();
}
if (String.IsNullOrEmpty(lValue))
{
//isEverythingElse
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductItemId = new Google.Ads.GoogleAds.V10.Common.ProductItemIdInfo()
};
}
else
{
listingDimensionInfo = new Google.Ads.GoogleAds.V10.Common.ListingDimensionInfo()
{
ProductItemId = new Google.Ads.GoogleAds.V10.Common.ProductItemIdInfo
{ Value = lValue }
};
}
}
break;
default:
break;
}
}
Google.Ads.GoogleAds.V10.Common.ListingGroupInfo ListingGroup = new Google.Ads.GoogleAds.V10.Common.ListingGroupInfo()
{
Type = lType, // SubDivision OR Unit
CaseValue = listingDimensionInfo
};
if (criterion.id != -1)
ListingGroup.ParentAdGroupCriterion = ResourceNames.AdGroupCriterion(clientId, item.operand.adGroupId, criterion.parentCriterionId);
adGroupCriterion.ListingGroup = ListingGroup;
adGroupCriterion.CriterionId = criterion.id;
if (item.#operator == GoogleAwApi.Operator.ADD) { operationsGA.Add(new AdGroupCriterionOperation() { Create = adGroupCriterion }); }
if (item.#operator == GoogleAwApi.Operator.REMOVE) { operationsGA.Add(new AdGroupCriterionOperation() { Remove = adGroupCriterion.ResourceName }); }
if (item.#operator == GoogleAwApi.Operator.SET) { operationsGA.Add(new AdGroupCriterionOperation() { Update = adGroupCriterion }); }
}
catch (Exception ex)
{
string except = ex.Message;
}
}
try
{
// Issues a mutate request to process Ads.
MutateAdGroupCriteriaResponse retVal = service.MutateAdGroupCriteria(
new MutateAdGroupCriteriaRequest()
{
CustomerId = clientId.ToString(),
Operations = { operationsGA },
PartialFailure = true,
ValidateOnly = false,
ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.MutableResource // required to bring back a complete mutated object to report on.
});
if (retVal.Results[0].AdGroupCriterion != null)
results.Add(APIHelper.MapAdGroupCriterion(retVal.Results[0].AdGroupCriterion));
if (retVal.PartialFailureError != null)
{
var ApiError = new ApiErrorGA();
ApiError.errorString = retVal.PartialFailureError.Message;
ApiError.ApiErrorType = retVal.PartialFailureError.GetType().ToString();
partialFailures.Add(ApiError);
}
}
catch (GoogleAdsException ex)
{
string except = ex.Message;
}
result.ListReturnValueType = "AdGroupAdService";
result.value = results.ToArray();
result.partialFailureErrors = partialFailures.ToArray();
return result;
}
I need the code to be able to create new trees and also replace existing one.
I have tried a lot of different possibilities of trying to get it to work but all return internal error which really doesn't give me any pointers on what the issue is. Any help will be appreciated.
i've this code to insert in DB the data from the "hours1, hours2, hours3" that cames from an excel import, but this makes the code bigger by the way im doing, this is my code, how can i simplfy the part of the hours1,hours2 == nulls.. ?
switch (colNames.IndexOf(item2))
{
case 0:
if (model.Hours == null)
{
item.Hours = 0;
}
else
{
item.Hours = (decimal)model.Hours;
item.Hours_Remaining = (decimal)model.Hours;
}
break;
case 1:
if (model.Hours1 == null)
{
item.Hours = 0;
}
else
{
item.Hours = (decimal)model.Hours1;
item.Hours_Remaining = (decimal)model.Hours;
}
break;
case 2:
if (model.Hours2 == null)
{
item.Hours = 0;
}
else
{
item.Hours = (decimal)model.Hours2;
item.Hours_Remaining = (decimal)model.Hours;
}
break;
case 3:
if (model.Hours == null)
{
item.Hours = 0;
}
else
{
item.Hours = (decimal)model.Hours3;
item.Hours_Remaining = (decimal)model.Hours;
}
break;
}
you can have a private method like this
private void NameOfPrivateMethod(object objValue,Hours hours,Item item)
{
if (objValue == null)
{
item.Hours = 0;
}
else
{
item.Hours = (decimal)objValue;
item.Hours_Remaining = (decimal)hours;
}
}
and use it like this (you need to make some changes to it according to your need)
NameOfPrivateMethod(model.Hours1, model.Hours,Item)
I don't know, if StackOverflow is the right place to ask about Performance issues, but I haven't found any better community for this issue yet.
Basically we have two sample programs, one is an addin and one is a winforms program referencing the Word interop.
Both have implemented the same method called GetTabsFromParagraph:
public class SlowExample
{
public static void GetTabsFromParagraph(Paragraph para, Style style, List<Tabulator> tabList, bool getTabsForCase = false)
{
foreach (TabStop tab in para.TabStops)
{
if (tab.CustomTab)
{
bool showTab = true;
foreach (TabStop ts in style.ParagraphFormat.TabStops)
{
if (Math.Abs(ts.Position - tab.Position) < 0.001 &&
ts.Alignment == tab.Alignment)
{
showTab = false;
break;
}
}
if (showTab || getTabsForCase)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung =
tab.Alignment == WdTabAlignment.wdAlignTabLeft
? TabulatorAusrichtung.Links
: TabulatorAusrichtung.Rechts,
Tabulatorart = TabulatorArt.Tabulator,
Position = tab.Position
};
tabList.Add(t);
}
}
}
if (!getTabsForCase)
{
foreach (TabStop ts in style.ParagraphFormat.TabStops)
{
if (ts.CustomTab)
{
bool showTab = true;
foreach (TabStop tab in para.TabStops)
{
if (Math.Abs(tab.Position - ts.Position) > 0.0001 || tab.Alignment != ts.Alignment)
{
showTab = false;
break;
}
}
if (showTab)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung = TabulatorAusrichtung.Geloescht,
Tabulatorart = TabulatorArt.Tabulator,
Position = ts.Position
};
tabList.Add(t);
}
}
}
}
if (Math.Abs(para.LeftIndent - style.ParagraphFormat.LeftIndent) > 0.001 || getTabsForCase)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung = TabulatorAusrichtung.Links,
Tabulatorart = TabulatorArt.Einzug,
Position = para.LeftIndent
};
tabList.Add(t);
}
if (Math.Abs(para.RightIndent - style.ParagraphFormat.RightIndent) > 0.001 || getTabsForCase)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung = TabulatorAusrichtung.Rechts,
Tabulatorart = TabulatorArt.Einzug,
Position = para.RightIndent
};
tabList.Add(t);
}
if (Math.Abs(para.FirstLineIndent - style.ParagraphFormat.FirstLineIndent) > 0.001 || getTabsForCase)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung = TabulatorAusrichtung.ErstzeilenEinzug,
Tabulatorart = TabulatorArt.Einzug,
Position = para.FirstLineIndent
};
tabList.Add(t);
}
}
public class Tabulator
{
private TabulatorArt m_Tabulatorart;
private TabulatorAusrichtung m_Tabulatorausrichtung;
private float m_Position;
private bool m_UebernahmeInFolgedokument = false;
public float Position
{
get { return m_Position; }
set { m_Position = value; }
}
public float PositionOrg
{
get;
set;
}
public float PositionInCm
{
get
{
return (m_Position / 28.35F);
}
set
{
m_Position = value * 28.35F;
}
}
public TabulatorArt Tabulatorart
{
get { return m_Tabulatorart; }
set { m_Tabulatorart = value; }
}
public TabulatorAusrichtung Tabulatorausrichtung
{
get { return m_Tabulatorausrichtung; }
set { m_Tabulatorausrichtung = value; }
}
public TabulatorAusrichtung TabulatorausrichtungOrg
{
get;
set;
}
public bool UebernahmeInFolgedokument
{
get { return m_UebernahmeInFolgedokument; }
set { m_UebernahmeInFolgedokument = value; }
}
}
public enum TabulatorArt
{
Invalid = 0,
Tabulator = 1,
Einzug = 2
}
public enum TabulatorAusrichtung
{
Invalid = 0,
Links = 1,
Rechts = 2,
ErstzeilenEinzug = 3,
Geloescht = 4,
}
}
In each of the both programs, I load up a Application, open up a document with a few paragraphs and tabs and run this method for each paragraph like this:
private void TestSlowMethod(Word.Document document)
{
Word.Paragraphs documentParagraphs = document.Paragraphs;
List<Tabulator> tabList = new List<Tabulator>();
long swElapsedMilliseconds = 0;
foreach (Word.Paragraph documentParagraph in documentParagraphs)
{
Word.Style style = documentParagraph.get_Style();
Stopwatch sw = new Stopwatch();
sw.Start();
SlowExample.GetTabsFromParagraph(documentParagraph, style, tabList, true);
sw.Stop();
swElapsedMilliseconds += sw.ElapsedMilliseconds;
Debug.WriteLine(sw.ElapsedMilliseconds + "\r\n");
}
MessageBox.Show("Total ms: " + swElapsedMilliseconds);
Debug.WriteLine("Done...");
}
What I found out is the addin is running throw all of this 10-20 times faster.
Addin: 20-30 ms per call
WinForms tool: 200-300 ms per call
Why is that? My assumption would be, that the addin runs in the same context / process than the word application. But is that the real reason?
And can we fix that? Our software moved from addin to WPF + Interop-Word.
Thanks in advance!
Some performance fixes:
Check getTabsForCase sooner here:
if (tab.CustomTab)
{
bool showTab = true;
if (getTabsForCase) //insert this here, no need to run if getTabsForCase.
foreach (TabStop ts in style.ParagraphFormat.TabStops)
{
if (Math.Abs(ts.Position - tab.Position) < 0.001 &&
ts.Alignment == tab.Alignment)
{
showTab = false;
break;
}
}
if (showTab || getTabsForCase)
{
Tabulator t = new Tabulator
{
Tabulatorausrichtung =
tab.Alignment == WdTabAlignment.wdAlignTabLeft
? TabulatorAusrichtung.Links
: TabulatorAusrichtung.Rechts,
Tabulatorart = TabulatorArt.Tabulator,
Position = tab.Position
};
tabList.Add(t);
}
}
Similarly, put the check on getTabsForCase before all calculations in if statements:
//see getTabsForCase goes first
if (getTabsForCase || Math.Abs(para.LeftIndent - style.ParagraphFormat.LeftIndent) > 0.001)
Fix all of those conditionals to have getTabsForCase first - then the rest of the statement won't need to evaluate.
Country: Bahrain( i am selecting)
Amount:1000
Bank charges: 100(i am entering)
Vat:5%(entering) result:50(autogenerate)
Discount:6%(entering) result:60(autogenerate)
Total:1070(autogenerate)
This is working fine.I am getting the Total(with VAT).
Country:India(i am selecting)
Amount:1000
Bank charges: 100(i am entering)
Discount:5%(entering) result:50(autogenerate)
Total:(here i am not getting the amount)(may be because i set the visibility of VAT field false)
Here i am hidding the field VAT by using vattr.Visible=false. What should i do in order to sort out this issue?
Code behind:
protected void lstCountryy_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstCountryy.SelectedItem.Text == "U.A.E" || lstCountryy.SelectedItem.Text == "BAHRAIN" || lstCountryy.SelectedItem.Text=="SAUDI ARABIA")
{
vattr.Visible = true;
trdeclaration.Visible = false;
}
else
{
vattr.Visible = false;
trdeclaration.Visible = true;
}
}
Javascript:
function calculate(amount) {
var bankcharge = document.getElementById("<%=txtBankCharge.ClientID%>").value;
var vat = document.getElementById("<%=txtvatt.ClientID%>").value;
var discount = document.getElementById("<%=txtDiscount.ClientID%>").value;
var sum = 0;
$(".amt").each(function () {
if (isNaN(this.value))
{
alert("Please enter numbers only");
return false;
}
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
}
});
if (bankcharge.length > 0) {
if (isNaN(bankcharge)) {
alert("Bank charge should be numbers only !!");
return false;
}
else {
sum = sum + parseFloat(bankcharge);
}
}
if (vat.length > 0)
{
if (isNaN(vat)) {
alert("VAT should be numbers only !!");
return false;
}
else {
sum = sum + parseFloat(vat);
}
}
if (discount.length > 0) {
if (isNaN(discount)) {
alert("Discount amount should be numbers only !!");
return false;
}
else {
sum = sum - parseFloat(discount);
}
}
var atemp = sum.toString().split(".");
if (atemp.length > 1) {
sum = sum.toFixed(2);
}
document.getElementById("<%=txtTotal.ClientID%>").value = sum;
document.getElementById("<%=txtAmountInWords.ClientID%>").value = convertNumberToWords(sum);
}
function vatCalc()//added by chetan
{
var sum = 0;
$(".amt").each(function () {
if (isNaN(this.value)) {
alert("Please enter numbers only");
return false;
}
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
}
});
var _txt2 = document.getElementById('<%= txtvat.ClientID %>');
var _txt3 = document.getElementById('<%= txtvatt.ClientID %>');
var t1=0, t2=0;
//if(_txt1.value != "") t1=_txt1.value;
if(_txt2.value != "") t2=_txt2.value;
_txt3.value = (sum * parseFloat(t2) )/ 100;
}
function discountCalc()
{
var sum = 0;
$(".amt").each(function () {
if (isNaN(this.value)) {
alert("Please enter numbers only");
return false;
}
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
}
});
var _txt2 = document.getElementById('<%= txtDiscountText.ClientID %>');
var _txt3 = document.getElementById('<%= txtDiscount.ClientID %>');
var t1=0, t2=0;
//if(_txt1.value != "") t1=_txt1.value;
if(_txt2.value != "") t2=_txt2.value;
_txt3.value = (sum * parseFloat(t2)) / 100;
}
The problem is here:
if (vat.length > 0)
{
if (isNaN(vat)) {
alert("VAT should be numbers only !!");
return false;
}
else {
sum = sum + parseFloat(vat);
}
}
I wanted to write this condition in such a way that when use selects bahrain,vat should be visible and should be calculated.
when user selects india,vat should be hidden and will yield the total amount.
Finally i got solution.This w orked perfectly.
if (lstCountryy.SelectedValue == "U.A.E" || lstCountryy.SelectedValue == "BAHRAIN" || lstCountryy.SelectedValue == "SAUDI ARABIA")
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "float");
trdeclaration.Visible = false;
//txtvat.Enabled = true;
}
else
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "none");
trdeclaration.Visible = true;
}
I am new in coding and I am having the following issue. When I run the select if there are no rows I receive the following error
but in that case, i want to make an insert
how can I do this? This is my entire code:
private DataRow verifica_pontajul()
{
string query = String.Format("select PR_ID,WORKER_Name,PR_Come,PR_Go, CURRENT_TIMESTAMP from `ppresence` {0}",
(Functii.marca == "admin" ? "" :
String.Format("WHERE PR_WorkerPTR='{0}' ORDER BY PR_ID DESC LIMIT 1 ", this.marca)
));
return conn.dt(query,0).Rows[0];
}
public class liniepontaj
{
public long idlinie = 0;
private string angajat = "";
public DateTime DataIntrare = new DateTime();
private DateTime DataIesire = new DateTime();
public DateTime DataReferinta = new DateTime();
private bool isIntrare = false;
public bool facintrare = false;
public bool faciesire = false;
public liniepontaj() { }
public liniepontaj(DataRow rand)
{
this.idlinie = long.Parse(rand.ItemArray[0].ToString());
this.angajat = rand.ItemArray[1].ToString();
this.DataIntrare = (DateTime)rand.ItemArray[2];
try {
this.DataIesire = (DateTime)rand.ItemArray[3];
}
catch (Exception) { this.DataIesire = new DateTime(1, 1, 1, 0, 0, 0); }
this.DataReferinta = (DateTime)rand.ItemArray[4];
if (this.DataIesire == null || this.DataIesire != new DateTime(1, 1, 1, 0, 0, 0)) { isIntrare = true; } else { isIntrare = false; }
TimeSpan t1 = DataReferinta - DataIntrare;
TimeSpan t2 = DataReferinta - DataIesire;
if ((t1.TotalMinutes < 15 && !this.isIntrare))
{
faciesire = false;
facintrare = false;
}
else if (t2.TotalMinutes < 15 && this.isIntrare)
{
faciesire = false;
facintrare = false;
}
else
{
facintrare = isIntrare;
faciesire = !isIntrare;
}
}
}
Where should i modify? To have the properly insert functional?
Basically, you just need to validate if there is any data inside Rows.
var dt = conn.dt(query, 0);
if (dt.Rows.Count == 0) return null;
else return dt.Rows[0];
Check for rowcount and if greater than or equal to 1 and then proceed else insert