I need your help in how can I change this controller code of opencart 2.3 extension to be compatible for opencart 3.X,
I have changed the tpl files in admin/view/template/extension/payment/ to twig with their parameters
also I changed the 'token=' to user_token in the controller
file path
admin/controller/extension/payment/
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
)");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_content_top'] = $this->language->get('text_content_top');
$data['text_content_bottom'] = $this->language->get('text_content_bottom');
$data['text_column_left'] = $this->language->get('text_column_left');
$data['text_column_right'] = $this->language->get('text_column_right');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_paymentdescription'] = $this->language->get('text_paymentdescription');
$data['text_title'] = $this->language->get('text_title');
$data['text_testmode'] = $this->language->get('text_testmode');
$data['text_testgrouptoken'] = $this->language->get('text_testgrouptoken');
$data['text_prodgrouptoken'] = $this->language->get('text_prodgrouptoken');
$data['text_maxpayment'] = $this->language->get('text_maxpayment');
$data['text_creditpayment'] = $this->language->get('text_creditpayment');
$data['text_windowselecttype'] = $this->language->get('text_windowselecttype');
$data['text_optionredirect'] = $this->language->get('text_optionredirect');
$data['text_optionpopup'] = $this->language->get('text_optionpopup');
$data['text_optioniframe'] = $this->language->get('text_optioniframe');
$data['text_height'] = $this->language->get('text_height');
$data['text_width'] = $this->language->get('text_width');
$data['text_hideitemlist'] = $this->language->get('text_hideitemlist');
$data['text_createtoken'] = $this->language->get('text_createtoken');
$data['text_invoicelang'] = $this->language->get('text_invoicelang');
$data['text_english'] = $this->language->get('text_english');
$data['text_hebrew'] = $this->language->get('text_hebrew');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_exemptvat'] = $this->language->get('text_exemptvat');
$data['text_chargevat'] = $this->language->get('text_chargevat');
$data['text_exempt'] = $this->language->get('text_exempt');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_redirecturl'] = $this->language->get('text_redirecturl');
$data['text_sortorder'] = $this->language->get('text_sortorder');
$data['text_ipn'] = $this->language->get('text_ipn');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['entry_code'] = $this->language->get('entry_code');
$data['entry_layout'] = $this->language->get('entry_layout');
$data['entry_position'] = $this->language->get('entry_position');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_add_module'] = $this->language->get('button_add_module');
$data['button_remove'] = $this->language->get('button_remove');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['pending_order_status'] = $this->language->get('pending_order_status');
$data['processing_order_status'] = $this->language->get('processing_order_status');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
/* End Breadcrumb Block*/
$data['action'] = $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'); // URL to be directed when the save button is pressed
$data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'); // URL to be redirected when cancel button is pressed
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['icredit_complete_order_status_id'])) {
$data['icredit_complete_order_status_id'] = $this->request->post['icredit_complete_order_status_id'];
} else {
$data['icredit_complete_order_status_id'] = $this->config->get('icredit_complete_order_status_id');
}
if (isset($this->request->post['icredit_pending_order_status_id'])) {
$data['icredit_pending_order_status_id'] = $this->request->post['icredit_pending_order_status_id'];
} else {
$data['icredit_pending_order_status_id'] = $this->config->get('icredit_pending_order_status_id');
}
if (isset($this->request->post['icredit_processing_order_status_id'])) {
$data['icredit_processing_order_status_id'] = $this->request->post['icredit_processing_order_status_id'];
} else {
$data['icredit_processing_order_status_id'] = $this->config->get('icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.tpl', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
?>
Your controller file should look like this:
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; ");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true)
);
$data['action'] = $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true);
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['payment_icredit_complete_order_status_id'])) {
$data['payment_icredit_complete_order_status_id'] = $this->request->post['payment_icredit_complete_order_status_id'];
} else {
$data['payment_icredit_complete_order_status_id'] = $this->config->get('payment_icredit_complete_order_status_id');
}
if (isset($this->request->post['payment_icredit_pending_order_status_id'])) {
$data['payment_icredit_pending_order_status_id'] = $this->request->post['payment_icredit_pending_order_status_id'];
} else {
$data['payment_icredit_pending_order_status_id'] = $this->config->get('payment_icredit_pending_order_status_id');
}
if (isset($this->request->post['payment_icredit_processing_order_status_id'])) {
$data['payment_icredit_processing_order_status_id'] = $this->request->post['payment_icredit_processing_order_status_id'];
} else {
$data['payment_icredit_processing_order_status_id'] = $this->config->get('payment_icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.twig', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
I'm not sure it is will works because i do not see another files.
In your twig file you must find this strings:
icredit_complete_order_status_id
icredit_pending_order_status_id
icredit_processing_order_status_id
and replace with:
payment_icredit_complete_order_status_id
payment_icredit_pending_order_status_id
payment_icredit_processing_order_status_id
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!
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"
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
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.