I am working on WCF web services and SQL server 2012. I have facing problem of below mention WCF service namely Print_Invoice can not work after published it on server IIS, but it can be run on locally successful please how I can solve this problem.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Print_Invoice(int Duty_Slip_Id)
{
try
{
List<Common.DTO.InvoiceDTO>data=new List<InvoiceDTO>();
ReportDocument rd = new ReportDocument();
using (T_FleetEntities e = new T_FleetEntities())
{
var v = e.Print_Invoice(Duty_Slip_Id);
if (v != null)
{
v.ToList().ForEach(o => data.Add(new Common.DTO.InvoiceDTO()
{
PNR_No = o.PRN_NO == (object)DBNull.Value ? string.Empty : (string)o.PRN_NO,
Inv_Date = Convert.ToString(o.Inv_Date.ToString() == (object)DBNull.Value ? string.Empty : o.Inv_Date.ToString()),
Date_In = Convert.ToString(o.Date_In.ToString() == (object)DBNull.Value ? string.Empty : o.Date_In.ToString()),
Date_Out = Convert.ToString(o.Date_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Date_Out.ToString()),
Time_Out = Convert.ToString(o.Time_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Time_Out.ToString()),
Tot_Days = Convert.ToString(o.Tot_Days.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Days.ToString()),
Time_In = Convert.ToString(o.Time_In.ToString() == (object)DBNull.Value ? string.Empty : o.Time_In.ToString()),
Km_In = Convert.ToString(o.Km_In.ToString() == (object)DBNull.Value ? string.Empty : o.Km_In.ToString()),
Km_Out = Convert.ToString(o.Km_Out.ToString() == (object)DBNull.Value ? string.Empty : o.Km_Out.ToString()),
Tot_Hrs = Convert.ToString(o.Tot_Hrs.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Hrs.ToString()),
Tot_Km = Convert.ToString(o.Tot_Km.ToString() == (object)DBNull.Value ? string.Empty : o.Tot_Km.ToString()),
Extra_Hr_Amt = Convert.ToString(o.Extra_Hr_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Hr_Amt.ToString()),
Extra_Km_Amt = Convert.ToString(o.Extra_Km_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Km_Amt.ToString()),
Night_Allow = Convert.ToString(o.Night_Allow.ToString() == (object)DBNull.Value ? string.Empty : o.Night_Allow.ToString()),
Out_Stn_Allow = Convert.ToString(o.Out_Stn_Allow.ToString() == (object)DBNull.Value ? string.Empty : o.Out_Stn_Allow.ToString()),
Pkg_Id = Convert.ToString(o.Pkg_Id.ToString() == (object)DBNull.Value ? string.Empty : o.Pkg_Id.ToString()),
Rate = Convert.ToString(o.Basic_Rate.ToString() == (object)DBNull.Value ? string.Empty : o.Basic_Rate.ToString()),
//Comp_Id = Convert.ToString(o.com.ToString() == (object)DBNull.Value ? string.Empty : o.Comp_Id.ToString()),
Extra_Hr = Convert.ToString(o.Extra_Hr.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Hr.ToString()),
Extra_Km = Convert.ToString(o.Extra_Km.ToString() == (object)DBNull.Value ? string.Empty : o.Extra_Km.ToString()),
//F_Cat_Id = Convert.ToString(o.F_Cat_Id.ToString() == (object)DBNull.Value ? string.Empty : o.F_Cat_Id.ToString()),
//F_Type_Id = Convert.ToString(o.F_Type_Id.ToString() == (object)DBNull.Value ? string.Empty : o.F_Type_Id.ToString()),
//Feedback = Convert.ToString(o.Feedback.ToString() == (object)DBNull.Value ? string.Empty : o.Feedback.ToString()),
Gross_Amt = Convert.ToString(o.Gross_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Gross_Amt.ToString()),
Inter_State_Tax = Convert.ToString(o.Inter_State_Tax.ToString() == (object)DBNull.Value ? string.Empty : o.Inter_State_Tax.ToString()),
//Inv_Status = Convert.ToString(o.Inv_Status.ToString() == (object)DBNull.Value ? string.Empty : o.Inv_Status.ToString()),
Other_Rec = Convert.ToString(o.Other_Rec.ToString() == (object)DBNull.Value ? string.Empty : o.Other_Rec.ToString()),
Parking = Convert.ToString(o.Parking.ToString() == (object)DBNull.Value ? string.Empty : o.Parking.ToString()),
Serv_Tax_Amt = Convert.ToString(o.Serv_Tax_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Serv_Tax_Amt.ToString()),
Toll = Convert.ToString(o.Toll.ToString() == (object)DBNull.Value ? string.Empty : o.Toll.ToString()),
Total_Amt = Convert.ToString(o.Total_Amt.ToString() == (object)DBNull.Value ? string.Empty : o.Total_Amt.ToString()),
Comp_Nm = Convert.ToString(o.Comp_Nm.ToString() == (object)DBNull.Value ? string.Empty : o.Comp_Nm.ToString()),
Company_Email = Convert.ToString(o.Company_Email.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Email.ToString()),
Rep_Guest = Convert.ToString(o.Rep_Guest.ToString() == (object)DBNull.Value ? string.Empty : o.Rep_Guest.ToString()),
Company_Addr = Convert.ToString(o.Company_Addr.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Addr.ToString()),
Company_Nm = Convert.ToString(o.Company_Nm.ToString() == (object)DBNull.Value ? string.Empty : o.Company_Nm.ToString())
}));
}
string strReportPath;
strReportPath =HttpContext.Current.Server.MapPath("PrintInvoice.rpt");
rd.Load(Path.Combine(strReportPath));
rd.SetDataSource(data);
rd.ExportToDisk(ExportFormatType.PortableDocFormat, HttpContext.Current.Server.MapPath("files/Invoice.pdf"));
//Stream strem =rd.ExportToStream( CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
//strem.Seek(0, SeekOrigin.Begin);
// File(strem, "application/pdf", "files/Invoice.pdf");
}
string path = HttpContext.Current.Server.MapPath("files/Invoice.pdf");
return new JavaScriptSerializer().Serialize(path);
}
catch (Exception ex)
{
return new JavaScriptSerializer().Serialize(ex);
throw;
}
}
Related
I have search like as below picture:
I create query by below code:
StringBuilder query = new StringBuilder();
string OrderBy = null;
switch (sortOrder)
{
case "orderCode_desc":
OrderBy = " OrderCode desc";
break;
case "mobile":
OrderBy = "Mobile";
break;
case "mobile_desc":
OrderBy = "Mobile desc";
break;
case "date":
OrderBy = "OrderDate";
break;
case "date_desc":
OrderBy = "OrderDate desc";
break;
case "orderCode":
default:
OrderBy = "OrderCode";
break;
}
if (filters.SelectedProducts.NotNullString())
{
var SelectedProducts = filters.SelectedProducts.Split(',');
query.Append("(");
for (int i = 0; i < SelectedProducts.Length; i++)
{
query.AppendFormat("uag.oag.ordDet.ProductID == {0}" , SelectedProducts[i]);
if (i != SelectedProducts.Length - 1)
{
query.Append(" || ");
}
}
query.Append(") && ");
}
if (filters.DateFrom != null && filters.DateTo != null)
{
query.AppendFormat("(uag.oag._order.order.OrderDate >= {0} && uag.oag._order.order.OrderDate <= {1} )", filters.DateFrom.Date, filters.DateTo.Date);
}
if (filters.DateFrom != null && filters.DateTo == null)
{
query.AppendFormat("( uag.oag._order.order.OrderDate >= {0} )", filters.DateFrom.Date);
}
if (filters.DateFrom == null && filters.DateTo != null)
{
query.AppendFormat("( uag.oag._order.order.OrderDate <= {0} )", filters.DateTo.Date);
}
string _query = query.ToString();
_query = _query.EndsWith("&& ") ? _query.Remove(_query.Length - 3) : _query;
orders = db.orders
.Join(db.order_statuses, order => order.OrderStatusID, OrderStatus => OrderStatus.OrderStatusID, (order, OrderStatus) => new { order, OrderStatus })
.Join(db.order_details, _order => _order.order.OrderID, ordDet => ordDet.OrderID, (_order, ordDet) => new { _order, ordDet })
.Join(db.agents_info, oag => oag._order.order.AgentID, ag => ag.AgentInfoID, (oag, ag) => new { oag, ag })
.Join(db.users, uag => uag.ag.UserID, u => u.UserID, (uag, u) => new { uag, u })
.AsQueryable()
.Where(_query)
.Select(m => new OrderList
{
OrderID = m.uag.oag._order.order.OrderID,
OrderCode = m.uag.oag._order.order.OrderCode,
OrderDate = m.uag.oag._order.order.OrderDate,
OrderStatus = m.uag.oag._order.OrderStatus.OrderStatusTitle,
TotalPrice = m.uag.oag._order.order.TotalPrice,
Mobile = m.u.Mobile
}).OrderBy(OrderBy).Skip(PageSize * (page - 1)).Take(PageSize).ToList();
I get an error:
Operator '>=' incompatible with operand types 'DateTime' and 'Int32'
here is the same problem, and his problem was solved by use a parameterized query. I used parameterized query but problem does not solved.
How can i solved this problem?
Per the documentation you need to use a public constructor to create a DateTime object, so something like
query.AppendFormat("(uag.oag._order.order.OrderDate >= {0} && uag.oag._order.order.OrderDate <= {1})",
filters.DateFrom.Date.ToString(#"Da\teTi\me(yyyy,M,d)"),
filters.DateTo.Date.ToString(#"Da\teTi\me(yyyy,M,d)"));
I have the code below that is returning data for me. If result equals "Success" then there is data. I am not getting any data
back but getting a null. Data is diplayed on a web grid and when the webgrid sees that the data is Null, the page crashes.
How can I handle null from here?
public Chemicalsdetails GetChemicalDataGeneratedForMonth(string branchcode, string departmentnumber, string previousMonth, string currentMonth)
{
string result = string.Empty;
result = _chemmeterprocessor.CopyPreviousMonthData(branchcode, departmentnumber, previousMonth, currentMonth);
Chemicalsdetails objChem = null;
if (result == "Success")
{
objChem = new Chemicalsdetails();
List<Chemicaltransactiondto> objAllData = new List<Chemicaltransactiondto>();
objAllData = _chemmeterprocessor.GetAllChemicalEntries(branchcode, departmentnumber, currentMonth);
objChem.GetAllChemicalsInformation = objAllData;
}
else
{
Chemicalsdetails objNoData = new Chemicalsdetails();
}
return objChem;
}
Check for null after you retrieve your data.
public Chemicalsdetails GetChemicalDataGeneratedForMonth(string branchcode, string departmentnumber, string previousMonth, string currentMonth)
{
string result = string.Empty;
result = _chemmeterprocessor.CopyPreviousMonthData(branchcode, departmentnumber, previousMonth, currentMonth);
Chemicalsdetails objChem = null;
List<Chemicaltransactiondto> objAllData = new List<Chemicaltransactiondto>();
//****Check for "Success"
if (result == "Success")
{
//****Retrieve chemical data
objAllData = _chemmeterprocessor.GetAllChemicalEntries(branchcode, departmentnumber, currentMonth);
//****End Retrieve chemical data
}
//****Check for non-null data.
if ((result == "Success") && (objAllData!=null))
{
objChem = new Chemicalsdetails();
objChem.GetAllChemicalsInformation = objAllData;
}
else
{
Chemicalsdetails objNoData = new Chemicalsdetails();
}
return objChem;
}
I have a web forms application with a service reference
and I need to rewrite only the front-end of it in mvc4
I'm having trouble with search button (still new to programming)
this is the code of it in web forms
private void btnSearch_Click(object sender, EventArgs e)
{
ClearViewers();
btnSearch.Enabled = false;
btnSyncronise.Enabled = false;
PersonalInformation localInfo = null;
PersonInfo[] registryInfo = null;
needsUpdate = false;
Cursor = Cursors.WaitCursor;
try
{
if ((String.IsNullOrEmpty(txtPersonalNumber.Text)) || (txtPersonalNumber.Text.Length != 11) || (Regex.Match(txtPersonalNumber.Text, "^\\d{11}$").Success == false))
{
MessageBox.Show(#"blabla" + Environment.NewLine + #"blablabla" + Environment.NewLine + #"blabla", #"blabla", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using (PersonalInfoServiceClient proxy = new PersonalInfoServiceClient())
{
try
{
localInfo = proxy.GetLocalInfoForPerson(txtPersonalNumber.Text.Trim());
if (localInfo != null)
{
ssStatusLocal.ForeColor = Color.Green;
ssStatusLocal.Text = #"found personal ID";
lblFirstName.Text = localInfo.FirstName;
lblLastName.Text = localInfo.LastName;
lblMiddleName.Text = localInfo.MiddleName;
lblBirthDate.Text = String.Format("{0:MM/dd/yyyy}", localInfo.BirthDate);
if (localInfo.PersonStatus == PersonStatus.Active)
lblStatus.Text = #"active";
else if (localInfo.PersonStatus == PersonStatus.Rejected)
lblStatus.Text = #"passive";
else if (localInfo.PersonStatus == PersonStatus.Dead)
lblStatus.Text = #"dead";
else
lblStatus.Text = #"unknown";
lblSex.Text = (Convert.ToInt32(localInfo.Sex) == 1) ? #"male" : #"female";
lblAddress.Text = localInfo.Address;
lbBirthPlace.Text = localInfo.BirthPlace;
lbCitizenShip.Text = (string.IsNullOrEmpty(localInfo.CitizenShip) && string.IsNullOrEmpty(localInfo.CitizenShipCode)) ? localInfo.CitizenShip : localInfo.CitizenShip + " / " + localInfo.CitizenShipCode;
lbDoubleCitizenShip.Text = (string.IsNullOrEmpty(localInfo.DoubleCitizenShip) && string.IsNullOrEmpty(localInfo.DoubleCitizenShipCode)) ? localInfo.DoubleCitizenShip : localInfo.DoubleCitizenShip + " / " + localInfo.DoubleCitizenShipCode;
lblRegion.Text = localInfo.RegionName;
if (localInfo.Photo != null)
{
MemoryStream MS = new MemoryStream(localInfo.Photo);
pictureBox2.Image = Image.FromStream(MS);
}
documentInformationBindingSource1.DataSource = localInfo.Documents;
}
else
{
ssStatusLocal.ForeColor = Color.Red;
ssStatusLocal.Text = #"personal ID not found";
}
}
catch
{
ssStatusLocal.ForeColor = Color.Red;
ssStatusLocal.Text = #"error";
throw;
}
try
{
registryInfo = proxy.GetRegistryInfoForPerson(txtPersonalNumber.Text.Trim());
if (registryInfo != null && registryInfo.Length > 0)
{
ssStatusCivil.ForeColor = Color.Green;
ssStatusCivil.Text = #"found personal ID";
btnSyncronise.Enabled = true;
RegistryPersonInfos list = new RegistryPersonInfos();
foreach (PersonInfo personInfo in registryInfo)
{
RegistryPersonInfo registryPersonInfo = new RegistryPersonInfo()
{
BirthDate = personInfo.BirthDate
,
IsDead = (personInfo.IsPersonDead) ? "yes" : "no"
,
FirstName = personInfo.FirstName
,
LastName = personInfo.LastName
,
MiddleName = personInfo.MiddleName
,
DocumentStatusName = personInfo.DocumentStatusStr
,
DocumentStatus = personInfo.DocumentStatusEnum.ToString()
,
PersonalNumber = personInfo.PrivateNumber
,
DocumentRejectDate = personInfo.RejectedDate
,
DocumentType = (personInfo.IsIdCard) ? (string.IsNullOrEmpty(personInfo.IdCardNumber)) ? "one" : "two" : "three"
,
DocumentSerie = (personInfo.IsIdCard) ? personInfo.IdCardSerial : string.Empty
,
DocumentNumber = (personInfo.IsIdCard) ? (string.IsNullOrEmpty(personInfo.IdCardNumber)) ? string.Empty : personInfo.IdCardNumber : personInfo.PaspNumber
};
list.Add(registryPersonInfo);
}
registryPersonInfoBindingSource.DataSource = list;
}
else
{
ssStatusCivil.ForeColor = Color.Red;
ssStatusCivil.Text = #"Personal ID not found";
}
}
catch
{
ssStatusCivil.ForeColor = Color.Red;
ssStatusCivil.Text = #"error";
throw;
}
}
}
catch (Exception x)
{
lblFirstName.Text = String.Empty;
lblLastName.Text = String.Empty;
lblMiddleName.Text = String.Empty;
lblStatus.Text = String.Empty;
needsUpdate = false;
dgwMain.DataSource = null;
MessageBox.Show(
String.Format(
"error during loading. {0} error: {1} {2} info: {3}",
Environment.NewLine, x.Message, Environment.NewLine,
(x.InnerException == null) ? string.Empty : x.InnerException.Message), #"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Cursor = Cursors.Default;
btnSearch.Enabled = true;
}
}
how do you write this in controller?
the controller can't find labels, there is no picturebox
I have no idea how to get data via service reference
could you help ?
I have a class in which i calculate the credit limit left. And return the values through a DataTable. But in the IF condition it is throwing error 'Input string was not in a correct format.', Whats wrong in the code.
Please Help,
Thanks in Advance
string cmd2 = "select sum(FacilityAmountINR),sum(LCAmountPaid) from FacilityIssueDetails where Status='open' AND LCType = 'Inland LC'";
DataTable a = DbRdRw.SqlDbRead(cmd2, "FacilityIssueDetails");
decimal AvailInlandLC = 0;
string totcred = Convert.ToString(a.Rows[0]["Column1"]);
string totpaid = Convert.ToString(a.Rows[0]["Column2"]);
if (totcred != null && totpaid != null)
{
decimal TotalAmountCredit = Convert.ToDecimal(totcred);// error here
decimal TotalAmountpaid = Convert.ToDecimal(totpaid); // error here
AvailInlandLC = InlandLC - TotalAmountCredit + TotalAmountpaid;
}
//*************************************************************************
DataTable AvailableLimitTable = new DataTable();
AvailableLimitTable.Columns.Add("LCType",typeof (string));
AvailableLimitTable.Columns.Add("TotalLimit",typeof (decimal));
AvailableLimitTable.Columns.Add("AvailableLimit",typeof (decimal));
DataRow dr = AvailableLimitTable.NewRow();
dr["LCType"] = "Inland LC";
dr["TotalLimit"] = InlandLC;
dr["AvailableLimit"] = AvailInlandLC;
AvailableLimitTable.Rows.InsertAt(dr, 0);
Try to change the if loop condition if you are getting NULL value from database...
if (totcred != null && totpaid != null && totcred != "Null" && totpaid != "Null" )
{
decimal TotalAmountCredit = Convert.ToDecimal(totcred);// error here
decimal TotalAmountpaid = Convert.ToDecimal(totpaid); // error here
AvailInlandLC = InlandLC - TotalAmountCredit + TotalAmountpaid;
}
I have an xtraGrid control (v12.1) binded to a bindingSource, this last gets its data from a LINQ to entities query (EF4.3.1), the end user can filter and sort the gridView, I have a Stimulsoft report that shows the content of the gridView when the user clicks on a PrintListButton, how to get the xtragrid filtered and sorted datasource, in order to attach it to the report?
Thanks.
var data = GetDataView(xtraGridControl1);
report.RegData("List", data.ToTable());
public DataView GetDataView(GridControl gc)
{
DataView dv = null;
if (gc.FocusedView != null && gc.FocusedView.DataSource != null)
{
var view = (ColumnView)gc.FocusedView;
var currentList = listBindingSource.List.CopyToDataTable().DefaultView; //(DataView)
var filterExpression = GetFilterExpression(view);
var sortExpression = GetSortExpression(view);
var currentFilter = currentList.RowFilter;
//create a new data view
dv = new DataView(currentList.Table) {Sort = sortExpression};
if (filterExpression != String.Empty)
{
if (currentFilter != String.Empty)
{
currentFilter += " AND ";
}
currentFilter += filterExpression;
}
dv.RowFilter = currentFilter;
}
return dv;
}
public string GetFilterExpression(ColumnView view)
{
var expression = String.Empty;
if (view.ActiveFilter != null && view.ActiveFilterEnabled
&& view.ActiveFilter.Expression != String.Empty)
{
expression = view.ActiveFilter.Expression;
}
return expression;
}
public string GetSortExpression(ColumnView view)
{
var expression = String.Empty;
foreach (GridColumnSortInfo info in view.SortInfo)
{
expression += string.Format("[{0}]", info.Column.FieldName);
if (info.SortOrder == DevExpress.Data.ColumnSortOrder.Descending)
expression += " DESC";
else
expression += " ASC";
expression += ", ";
}
return expression.TrimEnd(',', ' ');
}