Thursday, June 18, 2015

Selection criteria not working in Crystal Reports and Visual Studio 2010

Problem:
I had upgraded my visual studio.net 2008 project to visual studio.net 2010. After that i noticed that some reports are not working properly. Infact selectioncriteria was not working. I tried many things but in vain.

Solution:
Just comment out or delete the following lines of code where the crystalreportviewer is defined in InitializeComponent()
        Me.crystalreportviewer .SelectionFormula

        Me.crystalreportviewer .ViewTimeSelectionFormula

Wednesday, January 21, 2015

SQL Server 2008/2012 - Loop through/split a delimited string

On internet, you will find many ways to loop trough the comma separated list in SQL. Following is a little bit different thing. Comma Separated list is parsed using XML datatype is saved in a temporary table.


Declare @xml AS XML  
Declare @id_list  VarChar(Max)
SET @id_list  = '2,5,6,2,6,73,26,267'

CREATE TABLE #TmpIdlist  
(  
  IdSequence  INT  
)  
SET @xml = CAST(('' + replace(@id_list , ',' ,'')+'') AS XML)  
INSERT INTO #TmpIdlist (IdSequence)  
SELECT  N.value('.', 'INT') AS value  
FROM @xml.nodes('A') AS T(N)  

Friday, December 26, 2014

Nokia Lumia 530 review - Personal Experience

Hi All,
I was an Android user but one of my colleagues was in love with Lumia. So I decided to give it a try... So I purchased Lumia :).

Pros:
  • Design is sleek
  • Light weight 
  • Touch is very smooth (I was not expecting such a good touch from Nokia) 
  • Performance is very good
Cons:
  • Content(Pics/Video) is not being saved on SD card even then SD card is selected in Settings
  • Only Videos made by this mobile run smoothly or some other videos by chance run smoothly. So there is no guarantee that it will run any .avi, .mp4 or .3gp formats. I have movies in my SD card but I cant run them smoothly. i am very upset due to this feature. :(
  • WhatsApp and Viber can not browse SD card to send pics or other media
  • Skype is unable to send videos
  • When you have a video chat on skype its screens gets hot that you can boil an egg there :)
  • Multiple email accounts can be added but they are not fully synced. for example If i delete an email from my gmail or yahoo account. I want that should be deleted from Inbox.
  • Songs can not be payed until we have to make a list for all the songs.
  • Battery drains early
Final Verdict:
          Don't Buy this

Wednesday, November 19, 2014

Sorting in Crosstab report Crystal Report

Scenario: 
Sorting data in crosstab on the basis of invisible column in the dataset/table which is attached to report. Image 1 is the image without sorting. It is sorted by report engine automatically on the basis of first column which is description. But we do not want the sorting of report on the basis of description and description is sorted alphabetically. Image 2 is showing the design of the report. You can notice that description is the primary field there. So report is sorted on this field.



Image: 1


Image: 2

Solution:
Following are the steps:
Step 1: Open report designer and right click and select "Cross-Tab Expert..."


Step 2: You will see the Rows part and currently in my case i have two columns as rows description and date.


Step 3: As reports is being displayed description wise which is not required. There is a serial number field in table and report should be displayed according to it. So Select "Description" and click "Group Options...". There will be a dialog. So have to do some changes in it.


Step 4: Click the drop down and select SR_NO (serial number)



Step 5: SR_NO is selected in the image because you can see that there is mentioned that "the records will be sorted and grouped by:" So we are changing sorting here. :)



Step 6: Click the next tab "Options". Here we can customize the group name. By default this is unchecked as you can notice here.


Step 7: Check this checkbox and select the field for display and grouping which is description here



Step 8: Click "OK" and "Description" field will be replaced with "SR_NO"


Step 9: Now print the report and you can notice that report is sorted in SR_NO (serial number) instead of "Description" and display field is "Description"


















Tuesday, September 16, 2014

Selecting a row/record in Syncfusion's GridGroupingControl manually or at runtime

Here are following steps to select a row in gridgroupingcontrol manually:

1 - // Set  these properties
     //Inherited GridControlBase Selection

//turn on the GridGroupingControl's listbox mode (uses Table.SelectRecords collection)
            gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One; 
//turn off GridControlBase selection support (do not use TableControl.Selections collection
      gridGroupingControl1.TableOptions.AllowSelection = ((Syncfusion.Windows.Forms.Grid.GridSelectionFlags)((Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row | Syncfusion.Windows.Forms.Grid.GridSelectionFlags.AlphaBlend)));
        //indicate how you want current cell to look/behave
            gridGroupingControl1.TableOptions.ListBoxSelectionCurrentCellOptions = GridListBoxSelectionCurrentCellOptions.HideCurrentCell;

2 - // Call this function on button click or on some other event
  private void SetGridRow()
        {
            gridGroupingControl1.Table.Records[0].SetCurrent();
            gridGroupingControl1.TableControl.CurrentCell.Activate(0, 0);
        }

3 - Implement this event and it will raise automatically due to step 2
        private void gridGroupingControl1_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e)
        {
            GridGroupingControl grid = sender as GridGroupingControl;

            if (grid.Table.CurrentRecord != null)
            {
                grid.Table.SelectedRecords.Clear();
                Record rec = grid.Table.CurrentRecord;
                if (!grid.Table.SelectedRecords.Contains(rec))
                    grid.Table.SelectedRecords.Add(rec);
            }            
        }

Friday, July 25, 2014

GridConditionalFormatDescriptor and QueryCellStyleInfo- how to format a row and a single cell in gridgroupingcontrol of Syncfusion?

GridConditionalFormatDescriptor only allow you to row formatting. 
Sample:
  GridConditionalFormatDescriptor gridConditionaReplaced = new GridConditionalFormatDescriptor();
            gridConditionaReplaced.Appearance.AnyRecordFieldCell.Font.Bold = true;
            gridConditionaReplaced.Appearance.AnyRecordFieldCell.TextColor = System.Drawing.Color.Brown;
            gridConditionaReplaced.Expression = "[ORDER_STATUS] =  'Replaced'";

            gridList.TableDescriptor.ConditionalFormats.Add(gridConditionaReplaced);

If you want to format any one cell, then you need to use QueryCellStyleInfo or PrepareViewStyleInfo event to achieve that. Below is the example that shows to change backcolor of a negative value cell and bracket for nagative value cell. Please refer to the below code in which QueryCellStyleInfo event is used to achieve your need.
Sample:
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
e.Style.Format = "{#,##}"; // You can set your own format
}
}
}
}

Wednesday, July 9, 2014

MS Access Database file deployment in .Net

I found it helpful from stackoverflow that is why I shared with you.

http://stackoverflow.com/questions/18961296/does-access-itself-need-to-be-installed-so-my-net-app-can-use-an-access-databas

Question:
I am developing a .NET program. If I use Access as a database for the purpose of running the program, should Access be installed on the host computer?
If is it not necessary that Access be installed, what should be used for proper running of the program (for example dll file)?
Also, it is important for me to have a low volume program.

Answer:
No, you don't need to have the full Microsoft Access application installed on the machine(s) on which you intend to run your .NET app. What you do need is to have the Microsoft Access Database Engine (a.k.a "ACE") installed on each machine. Note that the installed version of ACE (32-bit or 64-bit) must match the "bitness" of your .NET application (i.e., a 32-bit .NET application will need the 32-bit version of ACE, and a 64-bit .NET application will require the 64-bit version of ACE).
The installers for the Access Database Engine ("ACE") are available here.
http://www.microsoft.com/en-US/download/details.aspx?id=13255

Friday, May 16, 2014

How to remove SkypEmoticons malware - Part 2

"Your skype does not support extended icons. Please download the extension here: 
http://skypemoticonscomplete.com/?skype=1"

One of my friends in Canada got same issue but following Part 1 he was unable to solve the issue then he pinged me to resolve it at any cost. We did not want to reinstall OS. So here are the following steps to remove it because in this case, it has changed some of its settings and places. As SkypEmoticon is a malware so do not install any kind of new extensions for viewing skype animated icons. Please install the animated icons from well reputed companies do not install them on your friend's request. 
Anyways I installed it and it started disturbing my chat as well. It automatically added new line after every sentence and start sending the above blue sentence as well almost with every sentence of emoticon. Surprisingly, no antivirus recognizes it. :(
It may vary from Windows 7 to Windows 8. Current screens shots are taken from Windows 7. 
But I hope even then it will help u.

So here are the following steps to remove it:
1- Uninstall SkypEmoticons from Control Panel -> Add/Remove Programs
but it is still there

2 - So go to your Task Manager

                                      

3 - Right click and Open file location like that

4 - As the folder opens, click End task the SkypEmoticons that is SE.exe * 32 process from task manager and then delete the folder named SkypEmoticons from Roaming folder as in the image. Usually the path is "C:\Users\username\AppData\Roaming\SkypEmoticons"


5 - Now go to Run and write Regedit, it will open the Registry Editor
6 - Press CTRL + F and type SkypEmi, it will show you the following item keep on Pressing F3 to find more registry items like that and delete them. You can see in the following images.
7 - After getting this message that Finished searching through the registry. You can see the last image. Press CTRL + F and type SE.exe, it will show you the same screen with SE.exe at some path so delete them also and keep on Pressing F3 to find more registry items like that and delete them. You can see in the following images.






5 - 

8 - Now you are free from this malware. :)

Monday, May 12, 2014

Subreport is not showing data

Sometimes sub-report does not show its data. Although user is providing data accurately. There are two solutions for doing this:

1 - Redesign subreport, it will fix your issue definitely

2 - Make Formula fields and call the values in these formula fields and then use these formula fields.


Thursday, September 26, 2013

Conditionally suppress a line or a box object in Crystal Reports

As of Crystal Reports 2008 there is still no option to conditionally suppress a line or a box drawing object in Crystal Reports, so the closest work-around is to use a blank Text Field.

With the text field you can use the border properties to create most lines. By using the top, bottom, left or right border line properties you can draw a single, double, dashed, or dotted line almost anywhere you want that can be conditionally suppressed and/or colored. In the following picture, i was required to draw a line on first column. In the first look, it seems that this is a box object used but it is not so. There are text objects behind Accrued Profit, Cash Out and Deferred Collection. As first column is group 1 and second column is group 2 and third one is the sum of group 2 and Total is the sum of group 1. So in this kind of display first coulmn's values were repeated with group 2 values. So first i applied some formula on the group values then to draw line I have followed the following steps:

 Here are the steps:

1- Drag some Text Object and right click on it. Select Format Text... from the context menu.



2 - Select Border tab and click any Line style option as per requirement and click its formula button on right side. 



3 - Write the following code and change accordingly




By using multiple text fields of varying sizes, you could also conditionally size the lines too. You may be able to use the size and position dialog to conditionally change the length too, but that method seems to be grayed out (unavailable) sometimes.
Horizontal lines are simpler to create with this method, but vertical lines can also be created by stacking text fields in adjacent sections.
You may have to move the text field to the back if it blocks another field, but in most cases it won't be necessary as long as your text field is empty - maybe you want some text to conditionally appear too - just insert a formula or text. The text box gives you a lot of options.

Friday, August 30, 2013

How to access child controls and their events via element host in Winform



 MessageBox.Show(((WPFCustomControl.WPFComboBox)((System.Windows.Forms.Integration.ElementHost)ctl).Child).SelectedIndex.ToString());

How to remove SkypEmoticons malware - Part 1


"Your skype does not support extended icons. Please download the extension here: 
http://skypemoticonsb.asia/index.php?skype=1"

SkypEmoticon is a malware so do not install any kind of new extensions for viewing skype animated icons. Please install the animated icons from well reputed companies do not install them on your friend's request. 
Anyways I installed it and it started disturbing my chat as well. It automatically added new line after every sentence and start sending the above blue sentence as well almost with every sentence of emoticon. Surprisingly, no antivirus recognizes it. :(

So here are the following steps to remove it:
1- Uninstall SkypEmoticons from Control Panel -> Add/Remove Programs

but it is still there
2 - So go to your Task Manager



3 - Right click and Open file location like that

4 - As the folder opens, click End task the SkypEmoticons (32 bit) process from task manager and then delete the folder named SkypEmoticons from Roaming folder as in the image. Usually the path is "C:\Users\username\AppData\Roaming\SkypEmoticons"


5 - Now you are free from this malware. :)

Sunday, May 26, 2013

Sending Email in C#


 SmtpClient client = new SmtpClient();
                client.Port = 25;
                client.Host = "smtp.gmail.com";
                client.EnableSsl = true;
                client.Timeout = 10000000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential("asad.naeem@gmail.com", "Password");
//  MailMessage mm = new MailMessage("asad.naeem@gmail.com", "asad.naeem@gmail.com", "test", "test");


                MailMessage mm = new MailMessage("FromEmail", "ToEmail", "Subject", "Body");


                mm.BodyEncoding = UTF8Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                client.Send(mm);
         
                MessageBox.Show("Email Sent");

Friday, January 11, 2013

Open On-Screen Keyboard In C#


There are some of the ways to on-screen keyboard:
1 - Process.Start("C:\Windows\System32\OSK.EXE")
2 - System.Diagnostics.Process.Start("osk");
3 -Process[] pArr = Process.GetProcesses();
   foreach (Process p in pArr)
   {
            if (p.ProcessName == "osk" || p.ProcessName == "msswchx")
              p.Kill();
   }
ProcessStartInfo pInfo = new ProcessStartInfo(((Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\osk.exe")));              
                Process pr = Process.Start(pInfo);
               System.Threading.Thread.Sleep(100);
                pr.WaitForInputIdle();
4-   string windir = Environment.GetEnvironmentVariable("WINDIR");
            string osk = null;
            if (osk == null)
            {
                osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
                if (!File.Exists(osk))
                {
                    osk = null;
                }
            }
            if (osk == null)
                osk = "osk.exe";

            Process.Start(osk);

but when you have 32-bit built application and you want to open osk on 64-bit Windows 7. It will give error "Could not start On-Screen keyboard".  Simply you have to build your application's every module with Any CPU Setting, then this issue will be resolved immediately.

Windows won't allow you to call a 64-bit OSK.exe from your program. Anyone can start osk.exe from Run, but call it from within a 32-bit application won't work in 64-bit Windows.
Ideally Microsoft should include a 32-bit version of OSK.exe in the system folder and allow us to use it, if being called from a 32-bit application.
Another work around is to get your hands on 32-bit Windows XP and pull osk.exe from it, bundle this with you app. When you call the on-screen keyboard, check if OS is 64-bit, if it is call the Windows XP osk.exe, works OK. Although not ideal.

Write data to an Excel worksheet with C# fast

Source: http://www.clear-lines.com/blog/post/Write-data-to-an-Excel-worksheet-with-C-fast.aspx

The current project I am working on requires writing large amount of data to Excel worksheets. In this type of situation, I create an array with all the data I want to write, and set the value of the entire target range at once. I know from experience that this method is much faster than writing cells one by one, but I was curious about how much faster, so I wrote a little test, writing larger and larger chunks of data and measuring the speed of both methods:
private static void WriteArray(int rows, int columns, Worksheet worksheet)
{
var data = new object[rows, columns];
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
data[row - 1, column - 1] = "Test";
}
}
var startCell = (Range)worksheet.Cells[1, 1];
var endCell = (Range)worksheet.Cells[rows, columns];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.Value2 = data;
}
private static void WriteCellByCell(int rows, int columns, Worksheet worksheet)
{
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
var cell = (Range)worksheet.Cells[row, column];
cell.Value2 = "Test";
}
}
}
Clearly, the array approach is the way to go, performing close to 1000 times faster per cell. It also seems to improve as size increases, but that would require a bit more careful testing.
WriteDataToExcel
However, one additional thing I needed to do was to format the data, using NumberFormat as well as font, borders and color fills, and I thought I would use the same approach – and I observed a significant performance degradation.
private static void WriteNumberFormatArray(int rows, int columns, Worksheet worksheet)
{
var data = new object[rows, columns];
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
data[row - 1, column - 1] = "0.000%";
}
}
var startCell = (Range)worksheet.Cells[1, 1];
var endCell = (Range)worksheet.Cells[rows, columns];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.NumberFormat = data;
}
private static void WriteNumberFormatCellByCell(int rows, int columns, Worksheet worksheet)
{
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
var cell = (Range)worksheet.Cells[row, column];
cell.NumberFormat = "0.000%";
}
}
}
Here is the benchmark I ran, comparing writing NumberFormat by array vs. cell by cell:
WriteNumberFormat
The cell-by-cell version performs about the same writing values or number formats; however, the array version works about 100 times worse for NumberFormat compared to Value2. It still runs way faster than the cell-by-cell approach, but it’s not night-and-day any more.
Fortunately, when you are writing large amount of data like this, chances are, you are really writing records to a worksheet. And while every cell could potentially have a different value, the format is likely consistent, either by row or by column. That is, every cell in a column probably has the same number format. In that case, we have an alternative, which is to apply the format to an entire range at once, like this:
private static void WriteNumberFormatByColumn(int rows, int columns, Worksheet worksheet)
{
for (var column = 1; column <= columns; column++)
{
var startCell = (Range)worksheet.Cells[1, column];
var endCell = (Range)worksheet.Cells[rows, column];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.NumberFormat = "0.000%";
}
}
I ran my test again, and observed the following:
FormatByColumn
The format by column runs initially as fast as the array-based approach, but its time remains roughly constant as we increase the number of rows, making it an increasingly attractive option as the number of rows increases.
How do you handle writing large amounts of data to Excel? Any Jedi tricks you care to share?
And for completeness, here is the code I used to run my tests; I used an Action delegate in my test loop, which allowed me to easily swap the functions I wanted to compare – feel free to comment and criticize!
namespace ExcelSpeedTest
{
using System;
using System.Diagnostics;
using Microsoft.Office.Interop.Excel;
class Program
{
static void Main(string[] args)
{
var excel = new Application();
excel.DisplayAlerts = false;
var workbooks = excel.Workbooks;
var stopwatch = new Stopwatch();
var blockSize = 10;
Console.WriteLine("Write by array.");
MeasureOverIncreasingSize(workbooks, blockSize, stopwatch, WriteNumberFormatArray);
Console.WriteLine("Write by column.");
MeasureOverIncreasingSize(workbooks, blockSize, stopwatch, WriteNumberFormatByColumn);
Console.WriteLine("Write cell by cell.");
MeasureOverIncreasingSize(workbooks, blockSize, stopwatch, WriteNumberFormatCellByCell);
Console.ReadLine();
excel.Quit();
}
private static void MeasureOverIncreasingSize(Workbooks workbooks, intblockSize, Stopwatch stopwatch, Action<intint, Worksheet> method)
{
for (int size = 1; size <= 10; size++)
{
var workbook = workbooks.Add(Type.Missing);
var worksheets = workbook.Sheets;
var worksheet = (Worksheet)worksheets[1];
var rows = blockSize * size;
var columns = blockSize;
stopwatch.Reset();
stopwatch.Start();
method(rows, columns, worksheet);
stopwatch.Stop();
WriteEvaluation(stopwatch, rows, columns);
workbook.Close(false, Type.Missing, Type.Missing);
}
}
private static void WriteArray(int rows, int columns, Worksheet worksheet)
{
var data = new object[rows, columns];
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
data[row - 1, column - 1] = "Test";
}
}
var startCell = (Range)worksheet.Cells[1, 1];
var endCell = (Range)worksheet.Cells[rows, columns];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.Value2 = data;
}
private static void WriteCellByCell(int rows, int columns, Worksheet worksheet)
{
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
var cell = (Range)worksheet.Cells[row, column];
cell.Value2 = "Test";
}
}
}
private static void WriteNumberFormatArray(int rows, int columns, Worksheet worksheet)
{
var data = new object[rows, columns];
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
data[row - 1, column - 1] = "0.000%";
}
}
var startCell = (Range)worksheet.Cells[1, 1];
var endCell = (Range)worksheet.Cells[rows, columns];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.NumberFormat = data;
}
private static void WriteNumberFormatByColumn(int rows, int columns, Worksheet worksheet)
{
for (var column = 1; column <= columns; column++)
{
var startCell = (Range)worksheet.Cells[1, column];
var endCell = (Range)worksheet.Cells[rows, column];
var writeRange = worksheet.Range[startCell, endCell];
writeRange.NumberFormat = "0.000%";
}
}
private static void WriteNumberFormatCellByCell(int rows, int columns, Worksheet worksheet)
{
for (var row = 1; row <= rows; row++)
{
for (var column = 1; column <= columns; column++)
{
var cell = (Range)worksheet.Cells[row, column];
cell.NumberFormat = "0.000%";
}
}
}
private static void WriteEvaluation(Stopwatch stopwatch, int rows, intcolumns)
{
var cells = rows * columns;
var time = stopwatch.ElapsedMilliseconds;
var timePerCell = Math.Round((double)time / (double)cells, 5);
Console.WriteLine(string.Format("Writing {0} values took {1} ms or {2} ms/cell.", cells, time, timePerCell));
}
}
}