How to update List View Model in Asp.net MVC - asp.net-mvc

Hi I am facing issue in update records in MVC. I have created one list view model and in that i want to update some of the records but i am getting error. Please help me.
Here is my code:
public async Task<bool> AddPurchase(PurchaseOrderViewModel objModel, List<TableViewModel> tableListDto)
{
using (var txn = context.Database.BeginTransaction())
{
bool success = true;
try
{
PurchaseOrder purchase1 = new PurchaseOrder();
purchase1.LoginID = objModel.LoginID;
purchase1.SupplierID = objModel.SupplierID;
purchase1.SupplierName = objModel.SupplierName;
purchase1.LocationID = objModel.LocationID;
purchase1.Notes = objModel.Notes;
purchase1.Currency = objModel.Currency;
purchase1.TotalQuantity = objModel.TotalQuantity;
purchase1.TotalAmount = objModel.TotalAmount;
purchase1.TotalVolume = objModel.TotalVolume;
purchase1.TotalWeight = objModel.TotalWeight;
purchase1.TotalLandedCost = Convert.ToDecimal(objModel.TotalCost);
purchase1.TotalOtherCost = objModel.TotalOtherCost;
purchase1.Date_Of_Purchase = objModel.Date_Of_Purchase;
purchase1.Due_Date = objModel.Due_Date;
purchase1.Date_Arrived = objModel.Date_Arrived;
purchase1.Date_Departed = objModel.Date_Departed;
purchase1.CreatedBy = objModel.LoginID;
purchase1.CreatedOn = objModel.CreatedOn;
purchase1.UpdatedBy = objModel.LoginID;
purchase1.UpdatedOn = objModel.UpdatedOn;
purchase1.Status = StatusConstant.Active;
context.PurchaseOrders.Add(purchase1);
await context.SaveChangesAsync();
success = true;
int latest = purchase1.PurchaseID;
PO_Landed_Cost cost = new PO_Landed_Cost();
cost.LoginID = objModel.LoginID;
cost.PurchaseID = latest;
cost.Packaging_Costs = objModel.Packaging_Cost;
cost.Packaging_Costs_Date_Paid = objModel.Packaging_Costs_Date_Paid;
cost.Inspection_Costs = objModel.Inspection_Cost;
cost.Inspection_Costs_Date_Paid = objModel.Inspection_Costs_Date_Paid;
cost.Freight_And_Duty_Tax = objModel.Freight_Cost;
cost.Freight_And_Duty_Tax_Date_Paid = objModel.Freight_And_Duty_Tax_Date_Paid;
cost.Other_Costs = objModel.Other_Cost;
cost.Total_Landed_Cost = objModel.TotalOtherCost;
context.PO_Landed_Costs.Add(cost);
context.SaveChanges();
OrderDetail order = new OrderDetail();
PO_Landed_Cost_Spread spread1 = new PO_Landed_Cost_Spread();
List<DataDisplayViewModel> data = new List<DataDisplayViewModel>();
if (tableListDto != null)
{
foreach (var item in tableListDto)
{
//First we take all the basic things
var a = Convert.ToDecimal(item.Qty); //Quantity
var b = Convert.ToDecimal(purchase1.TotalQuantity); //Total Quantity
var e = Convert.ToDecimal(objModel.TotalOtherCost); //TotalOtherCost
var g = Convert.ToDecimal(item.Price); //Price
var j = Convert.ToDecimal(item.Volume); //Volume
var l = Convert.ToDecimal(item.Weight); //Weight
var c = Math.Round(Convert.ToDecimal((a / b) * 100), 2); //Total Percent(Quantity)
var f = Math.Round(Convert.ToDecimal(((c * e) / a) / 100), 2); // Quantity Unit Price(Indirect Cost)
var h = Math.Round(Convert.ToDecimal(f + g), 2); //Landed Cost Unit Price (Quantity)
var i = Math.Round(Convert.ToDecimal(h * a), 2); //New Total (Quantity)
var k = Math.Round(Convert.ToDecimal(a * j), 2); //Total Volume
var m = Math.Round(Convert.ToDecimal(a * l), 2); //Total Weight
DataDisplayViewModel datalist = new DataDisplayViewModel();
datalist.LoginID = objModel.LoginID;
datalist.PurchaseID = latest;
datalist.Stock_ID = item.Pid;
datalist.Stock_Name = item.ProductName;
datalist.Quantity = Convert.ToInt32(item.Qty);
datalist.Price = Convert.ToDecimal(item.Price);
datalist.Amount = Convert.ToDecimal(item.Amount);
datalist.Volume = Convert.ToInt32(item.Volume);
datalist.Total_Volume = Convert.ToInt32(k);
datalist.Weight = Convert.ToInt32(item.Weight);
datalist.Total_Weight = Convert.ToInt32(m);
datalist.Total_Percent = Convert.ToString(c);
datalist.Indirect_Cost_UnitPrice = Convert.ToString(f);
datalist.Landed_Cost_UnitPrice = Convert.ToString(h);
datalist.New_Amount = i;
data.Add(datalist);
}
var totalweight = data.Where(x => x.PurchaseID == latest).Select(x => x.Total_Weight).Sum();
var totalvolume = data.Where(x => x.PurchaseID == latest).Select(x => x.Total_Volume).Sum();
foreach (var item in tableListDto)
{
var z = Convert.ToInt32(item.Price);
var a = Convert.ToInt32(item.Qty); //Qty
var l = Convert.ToDecimal(item.Weight); //Weight
var j = Convert.ToDecimal(item.Volume); //Volume
var d = Math.Round(Convert.ToDecimal(((a * l) / totalweight) * 100), 2); //Total Percent Of Weight
var e = Convert.ToInt32(objModel.TotalOtherCost); //Total Other Cost
var f = Math.Round(Convert.ToDecimal(((d * e) / a) / 100), 2);
var h = Convert.ToDecimal(a + f); // Landed Cost Unit Price Of Weight
var i = Convert.ToString(h * a); // New Total Of Weight
var m = (a * j / totalvolume) * 100; //Total Percent Of Volume
var o = Math.Round(Convert.ToDecimal(((m * e) / a) / 100), 2); //Unit Price Of Volume
var q = Math.Round(Convert.ToDecimal(z + o), 2); // Landed Cost Unit Price Of Volume
var r = Convert.ToInt32(q * a); //New Total Of Volume
data.Where(x => x.PurchaseID == latest).FirstOrDefault();
data.Where(x => x.PurchaseID == latest).FirstOrDefault().Indirect_Cost_WeightUnitPrice = Convert.ToString(f);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().Landed_Cost_WeightUnitPrice = Convert.ToString(h);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().New_WeightAmount = Convert.ToDecimal(i);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().Total_Percent_Volume = Convert.ToString(m);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().Indirect_Cost_VolumeUnitPrice = Convert.ToString(o);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().Landed_Cost_VolumeUnitPrice = Convert.ToString(q);
data.Where(x => x.PurchaseID == latest).FirstOrDefault().New_VolumeAmount = Convert.ToDecimal(r);
context.Entry(data).State = EntityState.Added;
context.SaveChanges();
}
foreach (var item in data)
{
order.LoginID = objModel.LoginID;
order.PurchaseID = item.PurchaseID;
order.Stock_ID = item.Stock_ID;
order.Quantity = item.Quantity;
order.Price = item.Price;
order.Amount = item.Amount;
order.CreatedBy = objModel.LoginID;
order.CreatedOn = objModel.CreatedOn;
order.UpdatedBy = objModel.LoginID;
order.UpdatedOn = objModel.UpdatedOn;
order.Status = StatusConstant.Active;
order.Stock_Name = item.Stock_Name;
order.Volume = item.Volume;
order.Total_Volume = item.Total_Volume;
order.Weight = item.Weight;
order.Total_Weight = item.Total_Weight;
context.OrderDetails.Add(order);
context.SaveChanges();
spread1.PurchaseID = item.PurchaseID;
spread1.OrderID = order.OrderID;
spread1.LoginID = item.LoginID;
spread1.Total_Percent = item.Total_Percent;
spread1.Indirect_Cost_UnitPrice = item.Indirect_Cost_UnitPrice;
spread1.Landed_Cost_UnitPrice = item.Landed_Cost_UnitPrice;
spread1.New_Amount = item.New_Amount;
spread1.Total_Percent_Volume = item.Total_Percent_Volume;
spread1.Indirect_Cost_VolumeUnitPrice = item.Indirect_Cost_VolumeUnitPrice;
spread1.Landed_Cost_VolumeUnitPrice = item.Landed_Cost_VolumeUnitPrice;
spread1.New_VolumeAmount = item.New_VolumeAmount;
spread1.Total_Percent_Weight = item.Total_Percent_Weight;
spread1.Indirect_Cost_WeightUnitPrice = item.Indirect_Cost_WeightUnitPrice;
spread1.Landed_Cost_WeightUnitPrice = item.Landed_Cost_WeightUnitPrice;
spread1.New_WeightAmount = item.New_WeightAmount;
context.PO_Landed_Cost_Spreads.Add(spread1);
context.SaveChanges();
}
}
else
{
order.LoginID = objModel.LoginID;
order.PurchaseID = latest;
order.CreatedBy = objModel.LoginID;
order.CreatedOn = objModel.CreatedOn;
order.UpdatedBy = objModel.LoginID;
order.UpdatedOn = objModel.UpdatedOn;
order.Status = StatusConstant.Active;
context.OrderDetails.Add(order);
context.SaveChanges();
PO_Landed_Cost_Spread spread = new PO_Landed_Cost_Spread();
spread.LoginID = objModel.LoginID;
spread.PurchaseID = latest;
spread.OrderID = order.OrderID;
context.PO_Landed_Cost_Spreads.Add(spread);
context.SaveChanges();
}
txn.Commit();
}
catch (Exception ex)
{
txn.Dispose();
success = false;
}
return success;
};
}
In this code i want to update records when first i need to find some values and then i need to update in the list view model and then i need to update in the table. But i am unable to do that. Please help me in this.

Related

Why does head change in this Linked List?

Why does the head change here?
I thought assigning oddPointer to head would allow me to traverse through the list without changing head. This does not seem to be the case. When I log(head) it appears as 1->3->5, why is it not 1->2->3->4->5?
Is there a way to complete this without changing head?
// JavaScript
var oddEvenList = function (head) {
let oddList = new ListNode(-1);
let oddCopy = oddList;
let cnt = 0;
let oddPointer = head;
while (oddPointer) {
cnt++;
if (cnt % 2 !== 0) {
oddList.next = oddPointer; // -1,1,3,5
oddList = oddList.next;
}
oddPointer = oddPointer.next;
}
console.log(oddList);
console.log(oddCopy);
console.log(head);
console.log(oddPointer);
return -1;
}
function ListNode(val, next) {
this.val = (val === undefined ? 0 : val)
this.next = (next === undefined ? null : next)
}
let a1 = new ListNode(1);
let a2 = new ListNode(2);
let a3 = new ListNode(3);
let a4 = new ListNode(4);
let a5 = new ListNode(5)
a1.next = a2;
a2.next = a3;
a3.next = a4;
a4.next = a5;
console.log(oddEvenList(a1));

How to check if enabling custom invoice numbers results in duplicate invoice Numbers

I am working on integrating quick books with mvc and I have to work on one task which is to check if enabling custom invoice numbers results in duplicate Invoice .
I have tried creating invoice in quick books
public Invoice PostInvoice(InvoiceViewModel model)
{
Intuit.Ipp.Data.Invoice invoice = new Intuit.Ipp.Data.Invoice();
invoice.Deposit = new Decimal(0.00);
invoice.DepositSpecified = true;
invoice.DocNumber = "QBOInvoice" + DateTime.Now.ToString("MMddHHmmss");
invoice.CustomerRef = new ReferenceType { Value = model.qboCustomer.Id };
// invoice.CustomerMemo = new MemoRef { Value = reference };
invoice.DueDate = DateTime.UtcNow.Date;
invoice.DueDateSpecified = true;
invoice.TotalAmtSpecified = true;
invoice.ApplyTaxAfterDiscount = false;
invoice.ApplyTaxAfterDiscountSpecified = true;
invoice.PrintStatus = PrintStatusEnum.NotSet;
invoice.PrintStatusSpecified = true;
invoice.EmailStatus = EmailStatusEnum.NotSet;
invoice.EmailStatusSpecified = true;
invoice.BalanceSpecified = true;
invoice.TxnDate = DateTime.UtcNow.Date;
invoice.TxnDateSpecified = true;
invoice.ShipAddr = model.Address;
invoice.BillAddr = model.Address; //new PhysicalAddress() { Line1 = "BillMohali", Line2 = "Sector 70 ", City = "Mohali", PostalCode = "160071" };
//invoice.ShipAddr = new PhysicalAddress() {Line1="Mohali", Line2="Sector 70 ",City="Mohali",PostalCode="160071" };
//invoice.BillAddr = new PhysicalAddress() { Line1 = "BillMohali", Line2 = "Sector 70 ", City = "Mohali", PostalCode = "160071" };
Intuit.Ipp.Data.Line line = new Intuit.Ipp.Data.Line();
SalesItemLineDetail lineSalesItemLineDetail = new SalesItemLineDetail();
List<Intuit.Ipp.Data.Line> lineList = new List<Intuit.Ipp.Data.Line>();
foreach (var item in model.qbolineitems)
{
lineSalesItemLineDetail = new SalesItemLineDetail();
line = new Intuit.Ipp.Data.Line();
//Line Sales Item Line Detail - ServiceDate
lineSalesItemLineDetail.ServiceDate = DateTime.Now.Date;
lineSalesItemLineDetail.ServiceDateSpecified = true;
lineSalesItemLineDetail.Qty = item.invoiceitem.quantity.Value;
lineSalesItemLineDetail.QtySpecified = true;
lineSalesItemLineDetail.ItemRef = new ReferenceType { Value = item.item.qboItemCode.Value.ToString(), name = item.item.qboItemName };
lineSalesItemLineDetail.AnyIntuitObject = item.invoiceitem.SalePrice.Value / item.invoiceitem.quantity.Value;
lineSalesItemLineDetail.ItemElementName = ItemChoiceType.UnitPrice;
line.AnyIntuitObject = lineSalesItemLineDetail;
line.Description = item.item.qboItemName;
line.Amount = item.invoiceitem.SalePrice.Value;
line.AmountSpecified = true;
// line.Id = item.item.qboItemCode.Value.ToString();
line.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
line.DetailTypeSpecified = true;
//if (_connect.Country == "US")
//{
lineSalesItemLineDetail.TaxInclusiveAmt = item.invoiceitem.SalePrice.Value;
lineSalesItemLineDetail.TaxCodeRef = new ReferenceType { Value = "TAX" };
//}
//else
//{
//_connect = (Connect)Session["Connect"];
// objQBO = new QBOWrapper("jagjeetkr7#gmail.com", Request.Url.GetLeftPart(UriPartial.Authority) + "/Home/Callback", _connect, true);
//var taxcode = objQBO.getTaxCodeList().Where(x => x.Active).FirstOrDefault();
//lineSalesItemLineDetail.TaxCodeRef = new ReferenceType { Value = taxcode.Id };
//var dis = item.invoiceitem.SalePrice.Value / (Convert.ToDecimal(taxcode.SalesTaxRateList.TaxRateDetail[0].TaxRateRef.Value) + 1);
//line.Amount = item.invoiceitem.SalePrice.Value - dis;
//lineSalesItemLineDetail.TaxInclusiveAmt = item.invoiceitem.SalePrice.Value;
lineSalesItemLineDetail.TaxInclusiveAmtSpecified = false;
invoice.GlobalTaxCalculationSpecified = false;
invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.NotApplicable;
//SendInsideFunctionEmail("Failed to create surcharge invoice for : " + reference, "Please create a surcharge invoice manually and send a receipt to the customer. Also,please assign the tax code for this account selected in qbo.", _generalSettings.AccountsEmail);
// }
lineList.Add(line);
}
//invoice.TotalAmt = new Decimal(0.90);
//invoice.Balance = new Decimal(0.90);
// xlic.Add(li);
invoice.TotalAmt = model.Total;
invoice.Balance = model.BalanceDue;
invoice.Line = lineList.ToArray();
_connect = (Connect)Session["Connect"];
objQBO = new QBOWrapper("jagjeetkr7#gmail.com", Request.Url.GetLeftPart(UriPartial.Authority) + "/Home/Callback", _connect, true);
//objQBO = new QBOWrapper("jagjeetkr7#gmail.com", Request.Url.GetLeftPart(UriPartial.Authority) + "/Home/Callback", _connect, true);
invoice = objQBO.CreateInvoice(invoice);
return invoice;
}
I expect that generating custom invoice numbers results in duplicate invoice but not finding a way to implement that

Automatically Slicing Large TIFF File with Photoshop and Save Slices into TIFF Files?

I have a TIFF file. I want to slice it automatically (specifying the number of slices in horizontal and vertical) and save them into TIFF files (I don't want to change the format to png or ...)
I know that in photoshop you can choose the slice tool>>right click>>Divide Slice>>Save for web
However, the "Save for web" doesn't offer saving in TIFF Format and also I don't think it can work for large file (which is the case here).
Anything that can help (script, plugin) is welcome
With the help of some online codes, I created the script below which is capable of automatically slicing a big TIFF into smaller Tiff files:
#target photoshop
function main(){
if(!documents.length) return;
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,380,290],"+
"panel0:Panel{bounds:[10,10,270,180] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[60,10,220,40] , text:'File Chop' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,40,250,130] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext1:StaticText{bounds:[10,10,111,30] , text:'Accross' ,properties:{scrolling:undefined,multiline:undefined}},"+
"statictext2:StaticText{bounds:[140,10,230,27] , text:'Down' ,properties:{scrolling:undefined,multiline:undefined}},"+
"across:DropDownList{bounds:[10,30,100,50]},"+
"down:DropDownList{bounds:[140,30,230,50]},"+
"saveFiles:Checkbox{bounds:[10,60,230,80] , text:'Save and Close new files?'}},"+
"button0:Button{bounds:[10,140,110,160] , text:'Ok' },"+
"button1:Button{bounds:[150,140,250,160] , text:'Cancel' }}};"
var win = new Window(dlg,'File Chop');
if(version.substr(0,version.indexOf('.'))>9){
win.panel0.title.graphics.font = ScriptUI.newFont("Georgia","BOLD",20);
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [1.00, 1.00, 1.00, 1]);
g.backgroundColor = myBrush;
var myPen =g.newPen (g.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1);
}
win.center();
for(var i=1;i<31;i++){
win.panel0.panel1.across.add ('item', i);
win.panel0.panel1.down.add ('item', i);
}
win.panel0.panel1.across.selection=0;
win.panel0.panel1.down.selection=0;
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
{
if(!documents.length)return;
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
doc.flatten();
var tilesAcross = parseInt(win.panel0.panel1.across.selection.index)+1;
var tilesDown =parseInt(win.panel0.panel1.down.selection.index)+1;
var tileWidth = parseInt(doc.width/tilesAcross);
var tileHeight = parseInt(doc.height/tilesDown);
var SaveFiles = win.panel0.panel1.saveFiles.value;
ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight,SaveFiles);
app.preferences.rulerUnits = startRulerUnits;
}
}
}
}
main();
function ProcessFiles(Down,Across,offsetX,offsetY,SaveFiles){
try{
var newName = activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
}catch(e){var newName="UntitledChop"}
var Path='';
try{
Path = activeDocument.path;
}catch(e){Path = "~/Desktop";}
if(SaveFiles){
Path = Folder(decodeURI(Path) +"/FileChop");
if(!Path.exists) Path.create();
}
TLX = 0; TLY = 0; TRX = offsetX; TRY = 0;
BRX = offsetX; BRY = offsetY; BLX = 0; BLY = offsetY;
for(var a = 0; a < Down; a++){
for(var i = 0;i <Across; i++){
var NewFileName = newName +"#"+a+"-"+i;
app.activeDocument.duplicate (NewFileName, true);
activeDocument.selection.select([[TLX,TLY],[TRX,TRY],[BRX,BRY],[BLX,BLY]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
app.activeDocument.selection.deselect();
if(SaveFiles){
var saveFile = File(decodeURI(Path+"/"+NewFileName+".tiff"));
SaveTIFF(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
activeDocument = documents[0];
TLX = offsetX * (i+1) ; TRX = TLX + offsetX; BRX = TRX; BLX = TLX;
}
TLX = 0; TLY = offsetY * (a +1); TRX = offsetX; TRY = offsetY * (a +1);
BRX = offsetX; BRY = TRY + offsetY; BLX = 0; BLY = (offsetY * (a +1)+offsetY);
}
if(SaveFiles){
Path.execute()
}
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}

Join a Line and Ellipse

I did find how to bind a line to an ellipse through XAML, but I'm not very familiar with binding, and though I've researched it, I still don't understand how to get binding to work with user input.
Is there a way, programmatically to have an ellipse joined to the end of a line so when the line rotates on a diameter, the ellipse rotates with it? Everything I wrote for this is done in the code, not XAML.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void geo()
{
freeCanvas.Children.Clear();
double one, two, three, four, ang;
if(double.TryParse(txtOne.Text, out one))
if(double.TryParse(txtTwo.Text, out two))
if(double.TryParse(txtThree.Text, out three))
if (double.TryParse(txtFour.Text, out four))
if(double.TryParse(txtAngle.Text, out ang))
{
RotateTransform ans = new RotateTransform();
ans.Angle = ang;
ans.CenterX = 75;
ans.CenterY = 150;
Line lineA = new Line();
lineA.Stroke = Brushes.Black;
lineA.StrokeThickness = 2;
lineA.X1 = 75;
lineA.Y1 = 150;
lineA.X2 = 75;
lineA.Y2 = 250;
lineA.HorizontalAlignment = HorizontalAlignment.Center;
lineA.VerticalAlignment = VerticalAlignment.Top;
freeCanvas.Children.Add(lineA);
Line lineB = new Line();
lineB.Stroke = Brushes.Black;
lineB.StrokeThickness = 2;
lineB.X1 = 75;
lineB.Y1 = 50;
lineB.X2 = 75;
lineB.Y2 = 150;
//lineB.HorizontalAlignment = HorizontalAlignment.Center;
//lineB.VerticalAlignment = VerticalAlignment.Top;
lineB.RenderTransform = ans;
freeCanvas.Children.Add(lineB);
Line lineC = new Line();
lineC.Stroke = Brushes.Black;
lineC.StrokeThickness = 2;
lineC.X1 = -25;
lineC.Y1 = 150;
lineC.X2 = 175;
lineC.Y2 = 150;
lineC.HorizontalAlignment = HorizontalAlignment.Center;
lineC.VerticalAlignment = VerticalAlignment.Top;
freeCanvas.Children.Add(lineC);
PathFigure pthFigure = new PathFigure();
pthFigure.StartPoint = new Point(-25, 150);
ArcSegment arcSeg = new ArcSegment();
arcSeg.Point = new Point(175, 150);
arcSeg.Size = new Size(100, 100);
arcSeg.IsLargeArc = true;
arcSeg.SweepDirection = SweepDirection.Clockwise;
arcSeg.RotationAngle = 90;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(arcSeg);
pthFigure.Segments = myPathSegmentCollection;
PathFigureCollection pthFigureCollection = new PathFigureCollection();
pthFigureCollection.Add(pthFigure);
PathGeometry pthGeometry = new PathGeometry();
pthGeometry.Figures = pthFigureCollection;
Path arcPath = new Path();
arcPath.Stroke = new SolidColorBrush(Colors.Black);
arcPath.StrokeThickness = 1.5;
arcPath.Data = pthGeometry;
//arcPath.Fill = new SolidColorBrush(Colors.Yellow);
freeCanvas.Children.Add(arcPath);
Ellipse ellA = new Ellipse();
ellA.Width = 10;
ellA.Height = 10;
ellA.Stroke = Brushes.Black;
ellA.Fill = Brushes.Lime;
TranslateTransform ella1 = new TranslateTransform(70, 145);
ellA.RenderTransform = ella1;
freeCanvas.Children.Add(ellA);
Ellipse ellB = new Ellipse();
ellB.Width = 10;
ellB.Height = 10;
ellB.Stroke = Brushes.Black;
ellB.Fill = Brushes.Yellow;
TranslateTransform ellb1 = new TranslateTransform(70, 45);
ellB.RenderTransform = ellb1;
freeCanvas.Children.Add(ellB);
}
}
private void btnTest_Click(object sender, RoutedEventArgs e)
{
geo();
}
}
}
Never mind, I figured it out. I posted the segment of code that provided the answer.
Rads = Math.PI * ang / 180;
x1 = Math.Sin(Rads) * 80;
y1 = Math.Cos(Rads) * 80;
x2 = Math.Sin(Rads) * 30;
y2 = Math.Cos(Rads) * 30;
Ellipse ellA = new Ellipse();
ellA.Width = 10;
ellA.Height = 10;
ellA.Stroke = Brushes.Black;
ellA.Fill = Brushes.Lime;
TranslateTransform ella1 = new TranslateTransform(70 + x1, 145 - y1);
ellA.RenderTransform = ella1;
freeCanvas.Children.Add(ellA);
Ellipse ellB = new Ellipse();
ellB.Width = 10;
ellB.Height = 10;
ellB.Stroke = Brushes.Black;
ellB.Fill = Brushes.Yellow;
TranslateTransform ellb1 = new TranslateTransform(70 + x2, 145 - y2);
ellB.RenderTransform = ellb1;
freeCanvas.Children.Add(ellB);

Autocomplete on phone - AS3

I've made an autocomplete that work very well in the swf file.
very simple, when the user write the first letter, a suggestion is made with words.
I've published my project for IOS.
When I'm trying it on the Iphone, nothing is suggested when I'm typing the first letter.
I have to write the first letter and then clicked on "enter" in order to display the suggestions...
I don't want the users to "validate" in order to have the suggestion but simply by typing a letter.
Do you know what could be the problem ? Anyone can help me ?
Weirdly, I've tried on an Android device, and it's working perfectly well ! (like my swf).
Here is my code :
urlLoader.load(new URLRequest("test.txt"));
urlLoader.addEventListener(Event.COMPLETE, loadComplete);
inputField.addEventListener(KeyboardEvent.KEY_UP, suggest);
function loadComplete(e:Event):void
{
suggestions = e.target.data.split(",");
}
function suggest(e:KeyboardEvent):void
{
suggested = [];
for (var i:int = 0; i < textfields.length; i++)
{
removeChild(textfields[i]);
}
textfields = [];
for (var j:int = 0; j < suggestions.length; j++)
{
if (suggestions[j].indexOf(inputField.text.toLowerCase()) == 0)
{
var term:TextField = new TextField();
term.width = 300;
term.height = 20;
term.x = 70;
term.y = (20 * suggested.length) + 314;
term.border = true;
term.borderColor = 0x353535;
term.background = true;
term.backgroundColor = 0xFF9900;
term.textColor = 0x4C311D;
term.defaultTextFormat = format;
term.addEventListener(MouseEvent.MOUSE_UP, useWord);
term.addEventListener(MouseEvent.MOUSE_OVER, hover);
term.addEventListener(MouseEvent.MOUSE_OUT, out);
term.addEventListener(MouseEvent.CLICK, tellMe);
addChild(term);
textfields.push(term);
suggested.push(suggestions[j]);
term.text = suggestions[j];
}
}
if (inputField.length == 0)
{
suggested = [];
for (var k:int = 0; k < textfields.length; k++)
{
removeChild(textfields[k]);
}
textfields = [];
}
if(e.keyCode == Keyboard.DOWN && currentSelection < textfields.length-1)
{
currentSelection++;
textfields[currentSelection].textColor = 0x4C311D;
}
if(e.keyCode == Keyboard.UP && currentSelection > 0)
{
currentSelection--;
textfields[currentSelection].textColor = 0x4C311D;
}
if(e.keyCode == Keyboard.ENTER)
{
inputField.text = textfields[currentSelection].text;
suggested = [];
for (var l:int = 0; l < textfields.length; l++)
{
removeChild(textfields[l]);
}
textfields = [];
currentSelection = 0;
}
}
function useWord(e:MouseEvent):void
{
inputField.text = e.target.text;
suggested = [];
for (var i:int = 0; i < textfields.length; i++)
{
removeChild(textfields[i]);
}
textfields = [];
}
Thank you
EDIT
Here's my new code with Stagetext
var myTextField:StageText = new StageText();
var stageTextInitOptions:StageTextInitOptions;
var urlLoader:URLLoader = new URLLoader();
var suggestions:Array = new Array();
var suggested:Array = new Array();
var textfields:Array = new Array();
var format:TextFormat = new TextFormat();
var currentSelection:int = -1;
var searchChannel:SoundChannel = new SoundChannel();
myTextField.returnKeyLabel = ReturnKeyLabel.SEARCH;
myTextField.addEventListener(KeyboardEvent.KEY_UP, suggest);
stageTextInitOptions = new StageTextInitOptions(false);
myTextField = new StageText(stageTextInitOptions);
myTextField.softKeyboardType = SoftKeyboardType.DEFAULT;
myTextField.returnKeyLabel = ReturnKeyLabel.DONE;
myTextField.autoCorrect = true;
myTextField.fontSize = 20;
myTextField.color = 0x000000;
myTextField.fontWeight = "bold";
myTextField.stage = this.stage;
myTextField.viewPort = new Rectangle(25, 108, stage.stageWidth-40, 28);
urlLoader.load(new URLRequest("Sports2.txt"));
urlLoader.addEventListener(Event.COMPLETE, loadComplete);
myTextField.addEventListener(KeyboardEvent.KEY_UP, suggest);
KeyboardEvent.KEY_UP, KeyboardEvent.KEY_DOWN, TextEvent.TEXT_INPUT doesn't really works at iOS. KeyboardEvent.KEY_DOWN is dispatching only on some keys. I saw only key "Enter".

Resources