Tuesday, July 17, 2012

LINQ to SQL connectionstring pickup from multiple DBML

In Your application if you have more than one DBML file then each DBML file will contain app.config for each DBML file. consider the WPF application






it will be not possible for you to change the client app.config connection string on deployment.
when your application will be ready for deployment take a copy of your solution from your source control. bcoz now you are going to perform many change on your app.config.

1. if you have more than one project then you have change the all project output type as a class library except the start up project.
   right click on the project > properties > change the output as class library




2. Click on setting > right click on the connection string click remove string. if you have more than one then remove all as same.


3. if you have app.xaml . right click and exclude it from project.

4. open your DBML file > right click > properties > expand the connection > select application string as false.





5. Open the DBML cs file on the





change it with 

 public dbDataContext() : base(ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString, mappingSource)
and it will be look like and you will also get a error




6. To remove the error you have to add System.Configuration dll in your project.

 
 7. You have to remove or hide the connection string of this project





Now build the project if you have more than one projectdo it for all project.


9. In you start up project the app.config will be





 If you have any query please comment.
thank you

Monday, July 16, 2012

ASP.NET Crystal report Group Tree hide

It's really looking odd that when a crystal report load it also load the group tree. You can easily stop the group tree showing.

aspx :


 <CR:CrystalReportViewer ID="secondarySalesCrystalReportViewer" runat="server" EnableDatabaseLogonPrompt="False"  
             EnableParameterPrompt="False" AutoDataBind="true" EnableDrillDown="False"   
             GroupTreeStyle-ShowLines="False" HasCrystalLogo="False" Height="50px"   
             Width="350px" />  

and on the page loading  event you have to use:

 secondarySalesCrystalReportViewer.ToolPanelView =CrystalDecisions.Web.ToolPanelViewType.None;


for example



  protected void Page_Load(object sender, EventArgs e)  
     {  
       secondarySalesCrystalReportViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;  
       if (!IsPostBack)  
       {  
         secondarySalesCrystalReportViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;  
         LoadAllWingInformation();  
         LoadDivision();  
         LoadRegion();  
         LoadTeritory();  
       }  
     }  


thank you

Monday, July 9, 2012

ASP.NET Gridview paging in List datasource

In a grid view if the data-source is used a list and the grid view is bind with the class attribute then we can also use paging on the grid view.

consider the gridview image:

the aspx:


 <asp:GridView ID="productGridView" runat="server" Width="700px" CellPadding="3" CellSpacing="1"  
           AutoGenerateColumns="False" Height="125px" ForeColor="#333333" AllowPaging="True"  
           GridLines="None"   
           OnSelectedIndexChanged="productGridView_SelectedIndexChanged" onpageindexchanging="productGridView_PageIndexChanging"   
           >  
           <AlternatingRowStyle BackColor="#A99B17" />  
           <Columns>  
             <asp:BoundField DataField="ProductId" HeaderText="Id" />  
             <asp:BoundField DataField="ProductCode" HeaderText="Item Code" ItemStyle-HorizontalAlign="Center" />  
             <asp:BoundField DataField="ProductName" HeaderText=" Product Name" />  
             <asp:BoundField DataField="ProductDescription" HeaderText="Description" />  
             <asp:BoundField DataField="ProductPrice" HeaderText="Price" ItemStyle-HorizontalAlign="Right" />  
             <asp:BoundField DataField="ProductQty" HeaderText="Qty (in SKU)" ItemStyle-HorizontalAlign="Right" />  
             <asp:BoundField DataField="ProductUnit" HeaderText="SKU Name" />  
             <asp:BoundField DataField="ProductVersion" HeaderText="Version" ItemStyle-HorizontalAlign="Center" />  
              <asp:BoundField DataField="ProductLine" HeaderText="Product Line" ItemStyle-HorizontalAlign="Center" />  
             <asp:CommandField ShowSelectButton="True" />  
           </Columns>  
           <EditRowStyle BackColor="#7C6F57" />  
           <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
           <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
           <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />  
           <RowStyle BackColor="#E3EAEB" />  
           <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />  
           <SortedAscendingCellStyle BackColor="#F8FAFA" />  
           <SortedAscendingHeaderStyle BackColor="#246B61" />  
           <SortedDescendingCellStyle BackColor="#D4DFE1" />  
           <SortedDescendingHeaderStyle BackColor="#15524A" />  
         </asp:GridView>  


Page index changing event :





     protected void productGridView_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)  
     {  
       LoadProductDataGrid();  
       productGridView.PageIndex = e.NewPageIndex;  
       productGridView.DataBind();  
     }  
  private void LoadProductDataGrid()  
     {  
       productGridView.DataSource = _productManagerObj.GetAllProductInfo();  
       productGridView.DataBind();  
     }  
 // From Manager Class  
  internal List<Product> GetAllProductInfo()  
     {  
       return _productGatewayObj.GetAllProductInfo();  
     }  
 // In Gateway class  
 internal List<Product> GetAllProductInfo()  
     {  
      MeghnaGroupDataClassesDataContext  _meghnaGroupData = new MeghnaGroupDataClassesDataContext();  
       List<Product> products = new List<Product>();  
       foreach (var product in (from j in _meghnaGroupData.AD_PRODUCTs   
                    select j ).Distinct())  
       {  
         Product productObj = new Product();  
         productObj.ProductId = (int) product.ProductId;  
         productObj.ProductCode = product.Code;  
         productObj.ProductName = product.Name;  
         productObj.ProductDescription = product.Description;  
         productObj.ProductPrice = (decimal) product.Price;  
         productObj.ProductVersion = product.versionno;  
         productObj.ProductQty = (int) product.TotalQuantity;  
         productObj.ProductUnit = product.Unit;  
         productObj.ProductLine = product.TypeName;  
         products.Add(productObj);  
       }  
       return products;  
     }  

Tuesday, July 3, 2012

ASP.NET Crystal report not showing after publish


 1.Right click on your crystal report. go to properties



 2. Change build action properties Embedded Resource to-> Embedded Resource.
Now publish your application you will get your crystal report after publish.

you  can also try this:
Crystal report is not showing after publish, but it show on local PC. may be it the common issue in VS2010 for SAP crystal report. i am not sure about your crystal report error, but here is some possible solution link for your crystal report solution.

http://niitdeveloper.blogspot.com/2012/03/deploy-crystal-report-aspnet.html
http://social.msdn.microsoft.com/Forums/en-CA/vscrystalreports/thread/ef56f72b-7ede-47d8-ba9e-9e63b9ac0203
http://forums.asp.net/t/1764951.aspx/1

if all the link does not solve your problem you can follow this:

1. Put your crystal report in your UI folder.


2. Publish your application


Here you will see one interesting thing that their is no crystal report in your UI folder where you publish the application.

right click on your solution open in window explorer mode, copy the crystal report from UI folder and paste it to publisher folder UI. now upload the the solution.


Hope it will help you.




Monday, July 2, 2012

Failed to export using the options you specified. Please check your options and try again.

#Solution:1
 in post back just set report loading event as follows btnViewReport_Click(null, null);



  protected void Page_Load(object sender, EventArgs e)  
     {  
       if (!IsPostBack == true)  
       {  
         LoadFactoryName();  
       }  
       else  
       {  
         // Your report viewing button event name  
         btnViewReport_Click(null, null);  
       }  
     }  



#Solution:2
You are trying to export the crystal report in PDF or other format.  But it is not working in  VS2010 asp.net SAP crystal report. my this article is not solve the exception but you may can take a alternative way for the solution. you can export the the crystal report in pdf when the report load.

Consider the method it will just load the crystal report

  private void LoadDateRangeWiseAllItemDetails()  
     {  
       _secondarySales = new SecondarySales();  
       _secondarySaleses = new List<SecondarySales>();  
       _secondarySales.FromDate = Convert.ToDateTime(String.Format("{0}", Request.Form["startDate"]));  
       _secondarySales.ToDate = Convert.ToDateTime(String.Format("{0}", Request.Form["endDate"]));  
       _secondarySaleses = _secondarySalesObj.LoadDateRangeWiseAllItemDetails(_secondarySales);  
       ReportDocument details = new ReportDocument();  
       details.Load(Server.MapPath("../Report/secondarySalesItemDetailsCrystalReport.rpt"));  
       details.SetDataSource(_secondarySaleses);  
       secondarySalesCrystalReportViewer.ReportSource = details;  
     }  

it will look like this:



if i want to load the report in PDF....then..?? then we can take a  another button name Download Pdf . click on this button it will load a pdf file to download. In this button event method we will use the previous method code + add the code for pdf.then the crystal report to PDF method will be look like :


  private void LoadDateRangeWiseAllItemDetails()  
     {  
       _secondarySales = new SecondarySales();  
       _secondarySaleses = new List<SecondarySales>();  
       _secondarySales.FromDate = Convert.ToDateTime(String.Format("{0}", Request.Form["startDate"]));  
       _secondarySales.ToDate = Convert.ToDateTime(String.Format("{0}", Request.Form["endDate"]));  
       _secondarySaleses = _secondarySalesObj.LoadDateRangeWiseAllItemDetails(_secondarySales);  
       ReportDocument details = new ReportDocument();  
       details.Load(Server.MapPath("../Report/secondarySalesItemDetailsCrystalReport.rpt"));  
       details.SetDataSource(_secondarySaleses);  
       secondarySalesCrystalReportViewer.ReportSource = details;  
       // for pdf  
       BinaryReader stream = new BinaryReader(details.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));  
       Response.ClearContent();  
       Response.ClearHeaders();  
       Response.ContentType = "application/pdf";  
       Response.AddHeader("content-disposition", "attachment; filename=" + "pdfName");  
       Response.AddHeader("content-length", stream.BaseStream.Length.ToString());  
       Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)));  
       Response.Flush();  
       Response.Close();   
     }  

Build and run the application you will get you report as pdf for download.



Enjoy...

SAP Crystal report Deployment Environment

In our application if we use SAP crystal report, then after deployment we fall such a problem that we need to install VS2010 and SAP crystal  report 13.0. But there need only a run time crystal report software. here is the link to download you appropriate run time software for deployment PC.

https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=56787567

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...