Web service and AdomdDataReader - web-services

I created Web service with this Web Method:
public void Add( string kurs11, string aktivnost11, string godina11, string mesec11, string dan11, string sat11, string brst11)
{
AdomdConnection cn = new AdomdConnection("location=localhost;Initial Catalog=MZ");
AdomdCommand cmd = new AdomdCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT t.*,Predict ([Modul]) as [Modul] From [Ph D] NATURAL PREDICTION JOIN (SELECT #kurs as [Id Kursa], #aktivnost as [Aktivnost], #godina as [Godina], #mesec as [Mesec],#dan as [Dan ime],#sat as [Sat],#brst as [Broj Studenata]) AS t ";
AdomdParameter kurs1;
kurs1 = cmd.CreateParameter();
kurs1.Direction = ParameterDirection.Input;
kurs1.ParameterName = "kurs";
cmd.Parameters.Add(kurs1);
cmd.Parameters["kurs"].Value = kurs11;
AdomdParameter aktivnost1;
aktivnost1 = cmd.CreateParameter();
aktivnost1.Direction = ParameterDirection.Input;
aktivnost1.ParameterName = "aktivnost";
cmd.Parameters.Add(aktivnost1);
cmd.Parameters["aktivnost"].Value = aktivnost11;
AdomdParameter godina1;
godina1 = cmd.CreateParameter();
godina1.Direction = ParameterDirection.Input;
godina1.ParameterName = "godina";
cmd.Parameters.Add(godina1);
cmd.Parameters["godina"].Value = godina11;
AdomdParameter mesec1;
mesec1 = cmd.CreateParameter();
mesec1.Direction = ParameterDirection.Input;
mesec1.ParameterName = "mesec";
cmd.Parameters.Add(mesec1);
cmd.Parameters["mesec"].Value = mesec11;
AdomdParameter dan1;
dan1 = cmd.CreateParameter();
dan1.Direction = ParameterDirection.Input;
dan1.ParameterName = "dan";
cmd.Parameters.Add(dan1);
cmd.Parameters["dan"].Value = dan11;
AdomdParameter sat1;
sat1 = cmd.CreateParameter();
sat1.Direction = ParameterDirection.Input;
sat1.ParameterName = "sat";
cmd.Parameters.Add(sat1);
cmd.Parameters["sat"].Value = sat11;
AdomdParameter brst1;
brst1 = cmd.CreateParameter();
brst1.Direction = ParameterDirection.Input;
brst1.ParameterName = "brst";
cmd.Parameters.Add(brst1);
cmd.Parameters["brst"].Value = brst11;
cn.Open();
AdomdDataReader reader = cmd.ExecuteReader();
}
But, when I invoke this method I get empty page. How can I see the results?
This query returns results in table, for example like this
kurs aktivost godina mesec dan sat brst modul
1 edit 2013 2 Friday 12 75 forum

Related

Transpose a table using power query

I have the following table (as result of many steps) :
I want to get a result as below : as I need to transpose the table :
This will do. In your case NumberOfColumns is at least 19.
For explanation of essential line
ToTable = Table.FromRows( List.Split( Source[Column.1.2], NumberOfColumns) )
visit The BI Accountant
let
NumberOfColumns = 3
, Source = Table.FromRecords({
[Column.1 = "country", Column.1.2 = "afghanistan"],
[Column.1 = "capital", Column.1.2 = "kabul"],
[Column.1 = "currency", Column.1.2 = "afghani"],
[Column.1 = "country", Column.1.2 = "slovakia"],
[Column.1 = "capital", Column.1.2 = "bratislava"],
[Column.1 = "currency", Column.1.2 = "eur"]
})
, ToTable = Table.FromRows( List.Split( Source[Column.1.2], NumberOfColumns) )
, OldHeader = Table.ColumnNames(ToTable)
, NewHeader = List.FirstN(Source[Column.1],NumberOfColumns)
, RenameHeaders = Table.RenameColumns(ToTable, List.Zip({OldHeader, NewHeader}))
in
RenameHeaders
before:
after:

Problem customize the height of column bar

The column bar is too small. And I couldn't adjust their height. The screen shot is attached here: https://prnt.sc/p09hj9.
I have tried all the methods of column series at https://www.amcharts.com/docs/v4/reference/columnseries/.
am4core.ready(function() {
// Create chart instance
var chart = am4core.create("historical_monthly_chart_range", am4charts.XYChart);
// Push data into the charts
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var series = chart.series.push(new am4charts.LineSeries());
series.name = "Price Range";
valueAxis.title.text = 'Price (S$ psf)';
series.dataFields.dateX = "date";
series.dataFields.openValueY = "min";
series.dataFields.valueY = "max";
series.tooltipText = "{date} \n Maximum: {max} \n Average: {average} \n Minimum: {min} \n Volume: {value}";
// Setting the appearance
series.tooltip.background.cornerRadius = 20;
series.tooltip.background.strokeOpacity = 0;
series.tooltip.pointerOrientation = "vertical";
series.tooltip.label.minWidth = 40;
series.tooltip.label.minHeight = 40;
series.tooltip.label.textAlign = "left";
series.tooltip.label.textValign = "middle";
series.fillOpacity = 0.5;
series.tensionX = 0.8;
series.fill = am4core.color("#697e69");
var series2 = chart.series.push(new am4charts.LineSeries());
series2.name = "Minimum Price";
series2.dataFields.dateX = "date";
series2.dataFields.valueY = "min";
series2.stroke = am4core.color("#697e69");
series2.tensionX = 0.8;
var series_average = chart.series.push(new am4charts.LineSeries());
series_average.name = "Average Price";
series_average.dataFields.valueY = "average";
series_average.dataFields.dateX = "date";
series_average.stroke = am4core.color("#000");
/* Bar chart series */
var barSeries = chart.series.push(new am4charts.ColumnSeries());
barSeries.dataFields.valueY = "value";
barSeries.dataFields.dateX = "date";
barSeries.fill = am4core.color("#000");
barSeries.columns.width = am4core.percent(60);
chart.cursor = new am4charts.XYCursor();
chart.cursor.xAxis = dateAxis;
chart.legend = new am4charts.Legend();
});
There is a bounty on this issue from AM charts however one workaround can be using scrollbar in Y axis like this following:
chart.scrollbarY = new am4core.Scrollbar();
This is not the best solution i agree but you can use it to slightly zoom with the buttons and scale and see
let me know if it works!

save order prestashop web service

I'm newbie with prestashop webservice, I'm trying to save orders in prestashop
database but i'm getting this error : table ps_orders doesn't exist, which is normal because prefix of my tables is different than ps_ :
here is my code :
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://localhost/prestashop');
define('PS_WS_AUTH_KEY', 'CQP84L4R3GB6IV99E5WSP4JPSWXDYE1R');
require_once('./PSWebServiceLibrary.php');
try{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$xml = $webService->get( array('url' => PS_SHOP_PATH.'/api/carts?schema=blank') );
$resources = $xml->children()->children();
$id_currency = 3;
$id_lang = 2;
$id_product = 2571;
// $attribute_product =
$id_address = 8;
$qte_product = 1;
$id_customer = 3;
$id_carrier = 3;
$date_now = date('Y-m-d H:i:s');
$name_product = 'produit 111 ';
// $reference_product = ;
$price_product = 320;
$tax_inclu_product = 320;
$tax_excl_product = 320;
$order_module = 'cashondelivery';
$order_payment = 'Cash on delivery (COD)';
$total_paid = 355;
$total_paid_real = 355;
$total_products = $price_product;
$total_products_wt = $price_product;
$id_status = 5; // status de la commande : livré, en cours
$total_discounts =0;
$total_discounts_tax_incl = $total_discounts;
$total_discounts_tax_excl = $total_discounts;
$total_paid_tax_incl = 355;
$total_paid_tax_excl = 355;
$total_shipping = 35 ; //frais selon la ville de livraison
$total_shipping_tax_incl = $total_shipping;
$total_shipping_tax_excl = $total_shipping;
$xml->cart->id_currency = $id_currency;
$xml->cart->id_lang = $id_lang;
$xml->cart->associations->cart_rows->cart_row[0]->id_product = $id_product;
// $xml->cart->associations->cart_rows->cart_row[0]->id_product_attribute = $attribute_product;
$xml->cart->associations->cart_rows->cart_row[0]->id_address_delivery = $id_address;
$xml->cart->associations->cart_rows->cart_row[0]->quantity = $qte_product;
// Others
$xml->cart->id_address_delivery = $id_address;
$xml->cart->id_address_invoice = $id_address;
$xml->cart->id_customer = $id_customer;
$xml->cart->id_carrier = $id_carrier;
$xml->cart->date_add = $date_now;
$xml->cart->date_upd = $date_now;
// Adding the new customer's cart
$opt = array( 'resource' => 'carts' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_cart = $xml->cart->id;
// ORDER
$xml = $webService->get(array('url' => PS_SHOP_PATH .'/api/orders/?schema=blank'));
// Adding dinamic and required fields
// Required
$xml->order->id_address_delivery = $id_address; // Customer address
$xml->order->id_address_invoice = $id_address;
$xml->order->id_cart = $id_cart;
$xml->order->id_currency = $id_currency;
$xml->order->id_lang = $id_lang;
$xml->order->id_customer = $id_customer;
$xml->order->id_carrier = $id_carrier;
$xml->order->module = $order_module;
$xml->order->payment = $order_payment;
$xml->order->total_paid = $total_paid;
$xml->order->total_paid_real = $total_paid_real;
$xml->order->total_products = $total_products;
$xml->order->total_products_wt = $total_products_wt;
$xml->order->conversion_rate = 1;
// Others
$xml->order->valid = 1;
$xml->order->current_state = 1;
$xml->order->total_discounts = $total_discounts;
$xml->order->total_discounts_tax_incl = $total_discounts_tax_incl;
$xml->order->total_discounts_tax_excl = $total_discounts_tax_excl;
$xml->order->total_paid_tax_incl = $total_paid_tax_incl;
$xml->order->total_paid_tax_excl = $total_paid_tax_excl;
$xml->order->total_shipping = $total_shipping;
$xml->order->total_shipping_tax_incl = $total_shipping_tax_incl;
$xml->order->total_shipping_tax_excl = $total_shipping_tax_excl;
// Order Row. Required
$xml->order->associations->order_rows->order_row[0]->product_id = $id_product;
//$xml->order->associations->order_rows->order_row[0]->product_attribute_id = $attribute_product;
$xml->order->associations->order_rows->order_row[0]->product_quantity = $qte_product;
// Order Row. Others
$xml->order->associations->order_rows->order_row[0]->product_name = $name_product;
// $xml->order->associations->order_rows->order_row[0]->product_reference = $reference_produc;
$xml->order->associations->order_rows->order_row[0]->product_price = $price_product;
$xml->order->associations->order_rows->order_row[0]->unit_price_tax_incl = $tax_inclu_product;
$xml->order->associations->order_rows->order_row[0]->unit_price_tax_excl = $tax_excl_product;
// Creating the order
$opt = array( 'resource' => 'orders' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_order = $xml->order->id;
echo "Customer 1 : ".$id_customer." address: ".$id_address." cart: ".$id_cart." Order: .".$id_order;
} catch (PrestaShopWebserviceException $e) {
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$e->getMessage();
}

Create vTiger Sales Order fails due to MANDATORY_FIELDS_MISSING "message":"Mandatory Fields Missing

I'm trying to create a SalesOrder via WebServices but it always fails due to missing mandatory fields.
I'm sending the following fields.
The error message does not specify the missing fields
I'm using vTiger 6.0.0
How can I figure it out
salesOrder.subject = fullDescription
salesOrder.sostatus = "delivered"
salesOrder.account_id ='11x28'
salesOrder.bill_street = shipping.address.street
salesOrder.bill_city = shipping.address.city
salesOrder.bill_state = shipping.address.state
salesOrder.bill_code = shipping.address.postalCode
salesOrder.bill_country = shipping.address.postalCode
salesOrder.ship_street = shipping.address.street
salesOrder.ship_city = shipping.address.city
salesOrder.ship_state = shipping.address.state
salesOrder.ship_code = shipping.address.postalCode
salesOrder.ship_country = shipping.address.postalCode
salesOrder.invoicestatus = "Created"
salesOrder.productid = selectedServices[0].id
salesOrder.quantity = 1
salesOrder.listprice = selectedServices[0].unit_price
//
salesOrder.comment= ""
salesOrder.tax1 = ""
salesOrder.tax2 = "10.000"
salesOrder.tax3 = "6.000"
salesOrder.pre_tax_total = "876.00"
salesOrder.currency_id = "21x1"
salesOrder.conversion_rate = "1.000"
salesOrder.tax4 = ""
salesOrder.duedate = "2014-12-12"
salesOrder.carrier = "FedEx"
salesOrder.pending = ""
salesOrder.txtAdjustment = "-21.00000000"
salesOrder.salescommission = "5.000"
salesOrder.exciseduty = "0.000"
salesOrder.hdnGrandTotal = "995.16000000"
salesOrder.hdnSubTotal = "876.00000000"
salesOrder.hdnTaxType = "group"
salesOrder.hdndiscountamount = "0"
salesOrder.hdnS_H_Percent = "21"
salesOrder.discount_percent = "25.000"
salesOrder.discount_amount = ""
salesOrder.terms_conditions = "- Unless "
salesOrder.enable_recurring = "0"
I was missing the LineItems. Please notice that it has to be CamelCase
"LineItems": [
{
"productid": "25x142",
"listprice": "299.00000000",
"quantity": "1"
}
],
you missed the mandatory field "Assigned TO"

Importing XML into SQL using Linq to XML, is there a more efficient way?

I have XML that I need to put in a SQL database. I am using LINQ to XML get the data I want out of the XML.
It seems to me that I waste a lot of time by mapping variables with Linq to XML and then saving those variables. I am wondering if I can combine these steps.
This is an example query. I perform this one many times and other ones on similar data.
Maybe somehow make the LINQ to XML create my LINQ objects directly instead of LINQ creating its own objects behind the scenes.
Here's my code.
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(newURI);
request2.AllowAutoRedirect = true;
request2.PreAuthenticate = true;
request2.Credentials = credentialCache;
request2.AutomaticDecompression = DecompressionMethods.GZip;
request2.Method = "GET";
HttpWebResponse response2 = null;
try
{
response2 = (HttpWebResponse)request2.GetResponse();
HttpStatusCode statusCode2 = response2.StatusCode;
using (Stream responseData2 = response2.GetResponseStream())
{
// TODO: Handle HTTP status code and response data here
XDocument userInfo = XDocument.Load(responseData2);
XNamespace userInfoNamespace = "http://www.digitalmeasures.com/schema/data";
XNamespace dmdNamespace = "http://www.digitalmeasures.com/schema/data-metadata";
var Records = from Record in userInfo.Descendants(userInfoNamespace + "Record")
select new
{
college = Record.Element(dmdNamespace + "IndexEntry").Attribute("entryKey").Value,
department = Record.Element(dmdNamespace + "IndexEntry").ElementsAfterSelf(dmdNamespace + "IndexEntry").FirstOrDefault().IsEmpty ? Record.Element(dmdNamespace + "IndexEntry").ElementsAfterSelf(dmdNamespace + "IndexEntry").FirstOrDefault().Attribute("entryKey").Value : "blank",
prefix = (string)Record.Descendants(userInfoNamespace + "PREFIX").SingleOrDefault(),
fname = (string)Record.Descendants(userInfoNamespace + "FNAME").SingleOrDefault(),
pfname = (string)Record.Descendants(userInfoNamespace + "PFNAME").SingleOrDefault(),
mname = (string)Record.Descendants(userInfoNamespace + "MNAME").SingleOrDefault(),
lname = (string)Record.Descendants(userInfoNamespace + "LNAME").SingleOrDefault(),
suffix = (string)Record.Descendants(userInfoNamespace + "SUFFIX").SingleOrDefault(),
alt_name = (string)Record.Descendants(userInfoNamespace + "ALT_NAME").SingleOrDefault(),
endpos = (string)Record.Descendants(userInfoNamespace + "ENDPOS").SingleOrDefault(),
email = (string)Record.Descendants(userInfoNamespace + "EMAIL").SingleOrDefault(),
building = (string)Record.Descendants(userInfoNamespace + "BUILDING").SingleOrDefault(),
ophone1 = (string)Record.Descendants(userInfoNamespace + "OPHONE1").SingleOrDefault(),
ophone2 = (string)Record.Descendants(userInfoNamespace + "OPHONE2").SingleOrDefault(),
ophone3 = (string)Record.Descendants(userInfoNamespace + "OPHONE3").SingleOrDefault(),
dphone1 = (string)Record.Descendants(userInfoNamespace + "DPHONE1").SingleOrDefault(),
dphone2 = (string)Record.Descendants(userInfoNamespace + "DPHONE2").SingleOrDefault(),
dphone3 = (string)Record.Descendants(userInfoNamespace + "DPHONE3").SingleOrDefault(),
fax1 = (string)Record.Descendants(userInfoNamespace + "FAX1").SingleOrDefault(),
fax2 = (string)Record.Descendants(userInfoNamespace + "FAX2").SingleOrDefault(),
fax3 = (string)Record.Descendants(userInfoNamespace + "FAX3").SingleOrDefault(),
website = (string)Record.Descendants(userInfoNamespace + "WEBSITE").SingleOrDefault(),
gender = (string)Record.Descendants(userInfoNamespace + "GENDER").SingleOrDefault(),
ethnicity = (string)Record.Descendants(userInfoNamespace + "ETHNICITY").SingleOrDefault(),
citizen = (string)Record.Descendants(userInfoNamespace + "CITIZEN").SingleOrDefault(),
bio = (string)Record.Descendants(userInfoNamespace + "BIO").SingleOrDefault(),
teaching_interests = (string)Record.Descendants(userInfoNamespace + "TEACHING_INTERESTS").SingleOrDefault(),
research_interests = (string)Record.Descendants(userInfoNamespace + "RESEARCHINTERETS").SingleOrDefault(),
expertise = (string)Record.Descendants(userInfoNamespace + "EXPERTISE").SingleOrDefault(),
upload_photo = (string)Record.Descendants(userInfoNamespace + "UPLOAD_PHOTO").SingleOrDefault(),
upload_cv = (string)Record.Descendants(userInfoNamespace + "UPLOAD_CV").SingleOrDefault(),
};
foreach (var recordItem in Records)
{
PCI a = new PCI();
a.COLLEGE = recordItem.college;
a.DEPARTMENT = recordItem.department;
a.PREFIX = recordItem.prefix;
a.FNAME = recordItem.fname;
a.PFNAME = recordItem.pfname;
a.MNAME = recordItem.mname;
a.LNAME = recordItem.lname;
a.SUFFIX = recordItem.suffix;
a.ALT_NAME = recordItem.alt_name;
a.ENDPOS = recordItem.endpos;
a.EMAIL = recordItem.email;
a.BUILDING = recordItem.building;
a.OPHONE1 = recordItem.ophone1;
a.OPHONE2 = recordItem.ophone2;
a.OPHONE3 = recordItem.ophone3;
a.DPHONE1 = recordItem.dphone1;
a.DPHONE2 = recordItem.dphone2;
a.DPHONE3 = recordItem.dphone3;
a.FAX1 = recordItem.fax1;
a.FAX2 = recordItem.fax2;
a.FAX3 = recordItem.fax3;
a.WEBSITE = recordItem.website;
a.GENDER = recordItem.gender;
a.ETHNICITY = recordItem.citizen;
a.CITIZEN = recordItem.citizen;
a.BIO = recordItem.bio;
a.TEACHING_INTERESTS = recordItem.teaching_interests;
a.RESEARCH_INTERESTS = recordItem.research_interests;
a.EXPERTISE = recordItem.expertise;
a.UPLOAD_PHOTO = recordItem.upload_photo;
a.UPLOAD_CV = recordItem.upload_cv;
faimdc.PCIs.InsertOnSubmit(a);
faimdc.SubmitChanges();
}
}
Instead of projecting to an anonymous type you can create the PCI class directly and you would not have to copy everything. Something like:
var Records = from Record in userInfo.Descendants(userInfoNamespace + "Record")
select new PCI
{
COLLEGE = Record.Element(dmdNamespace + "IndexEntry").Attribute("entryKey").Value,
DEPARTMENT = Record.Element(dmdNamespace + "IndexEntry").ElementsAfterSelf(dmdNamespace + "IndexEntry").FirstOrDefault().IsEmpty ? Record.Element(dmdNamespace + "IndexEntry").ElementsAfterSelf(dmdNamespace + "IndexEntry").FirstOrDefault().Attribute("entryKey").Value : "blank",
…
}
You probably also want the submit to be called once and outside the loop rather than in the loop.