In this blog, we will create a simple Windows application for maintaining check details using Visual Studio.

Process Flow

Create table & store procedure

In this application I have used MDF file. If you need, create a database from SQL Server, following the same script.
  1. CREATE TABLE [dbo].[ChequeDetails] (
  2. [ChequeDetailsId] NUMERIC (20) IDENTITY (1, 1) NOT NULL,
  3. [ChequeNumber] NVARCHAR (50) NULL,
  4. [GivenTo] NVARCHAR (50) NULL,
  5. [GivenDate] NVARCHAR (20) NULL,
  6. [ValidUpto] NVARCHAR (20) NULL,
  7. [Amount] NUMERIC (20, 2) NULL,
  8. [Notes] NVARCHAR (MAX) NULL,
  9. [CreatedBy] INT NULL,
  10. [CreatedDateTime] DATETIME NULL,
  11. [ModifiedBy] INT NULL,
  12. [ModifiedDateTime] DATETIME NULL,
  13. [IsDeleted] BIT NULL,
  14. PRIMARY KEY CLUSTERED ([ChequeDetailsId] ASC)
  15. );
  16. CREATE TABLE [dbo].[UserMaster] (
  17. [UserId] INT IDENTITY (1, 1) NOT NULL,
  18. [UserName] VARCHAR (20) NULL,
  19. [Password] NVARCHAR (MAX) NULL,
  20. [FirstName] VARCHAR (50) NULL,
  21. [LastName] VARCHAR (50) NULL,
  22. [Gender] TINYINT NULL,
  23. [EmailId] VARCHAR (250) NULL,
  24. [PhoneNumber] VARCHAR (10) NULL,
  25. [IsActiveUser] BIT NULL,
  26. [IsUserDeleted] BIT NULL,
  27. PRIMARY KEY CLUSTERED ([UserId] ASC)
  28. );
  29. CREATE PROCEDURE Proc_ChequeDetails
  30. @Mode varchar(10),
  31. @ChequeDetailsId NUMERIC(20)= NULL,
  32. @ChequeNumber nvarchar(50) = NULL,
  33. @GivenTo nvarchar(50) = NULL,
  34. @GivenDate nvarchar(20) = NULL,
  35. @ValidUpto nvarchar(20) = NULL,
  36. @Notes nvarchar(max) = NULL,
  37. @Amount NUMERIC(20,2) = NULL,
  38. @UserId int = NULL,
  39. @IsDeleted bit = NULL
  40. AS
  41. BEGIN
  42. IF(@Mode='INSERT')
  43. BEGIN
  44. INSERT INTO dbo.ChequeDetails(ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime,IsDeleted)
  45. VALUES(@ChequeNumber,@GivenTo,@GivenDate,@ValidUpto,@Amount,@Notes,@UserId,GETDATE(),@UserId,GETDATE(),0)
  46. SELECT 1 IsSuccess,'Cheque added Successfully!' as OutputMessage
  47. SELECT ChequeDetailsId,ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime FROM dbo.ChequeDetails
  48. END
  49. IF(@Mode='UPDATE')
  50. BEGIN
  51. UPDATE dbo.ChequeDetails SET ChequeNumber=@ChequeNumber,GivenTo=@GivenTo,GivenDate=@GivenDate,ValidUpto=@ValidUpto,Amount=@Amount,Notes=@Notes,
  52. ModifiedBy=@UserId,ModifiedDateTime=GETDATE()
  53. WHERE ChequeDetailsId=@ChequeDetailsId
  54. SELECT 1 IsSuccess,'Cheque added Successfully!' as OutputMessage
  55. SELECT ChequeDetailsId,ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime FROM dbo.ChequeDetails
  56. END
  57. IF(@Mode='DELETE')
  58. BEGIN
  59. UPDATE dbo.ChequeDetails SET IsDeleted=@IsDeleted,ModifiedBy=@UserId,ModifiedDateTime=GETDATE()
  60. WHERE ChequeDetailsId=@ChequeDetailsId
  61. SELECT 1 IsSuccess,'Cheque added Successfully!' as OutputMessage
  62. SELECT ChequeDetailsId,ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime FROM dbo.ChequeDetails
  63. END
  64. IF(@Mode='GETALL')
  65. BEGIN
  66. SELECT ChequeDetailsId,ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime FROM dbo.ChequeDetails
  67. END
  68. IF(@Mode='SEARCH')
  69. BEGIN
  70. SELECT ChequeDetailsId,ChequeNumber,GivenTo,GivenDate,ValidUpto,Amount,Notes,CreatedBy,CreatedDateTime,ModifiedBy,ModifiedDateTime,IsDeleted FROM dbo.ChequeDetails
  71. END
  72. END
  73. CREATE PROCEDURE [dbo].[Proc_Report]
  74. AS
  75. BEGIN
  76. select cd.ChequeNumber,cd.Amount,cd.GivenTo as ChequeGivenTo,
  77. cd.GivenDate as [ChequeGivenDate],cd.ValidUpto as [ChequeValidUpto],DATEDIFF(DAY,CAST(GETDATE() AS DATE),
  78. (CASE WHEN TRY_PARSE(ValidUpto AS smalldatetime) IS NULL THEN TRY_PARSE((SUBSTRING(ValidUpto,4,2)
  79. + '/' + SUBSTRING(ValidUpto,1,2) + '/' +SUBSTRING(ValidUpto,7,4)) AS smalldatetime) ELSE TRY_PARSE(ValidUpto AS smalldatetime) END)) AS [RemainingDays],
  80. cd.Notes,umc.FirstName+' '+umc.LastName as [ChequeCreatedBy],cd.CreatedDateTime as [ChequeCreatedDateTime],
  81. umm.FirstName+' '+umm.LastName as [ChequeModifiedBy],cd.ModifiedDateTime as [ChequeModifiedDateTime] from dbo.ChequeDetails cd
  82. left join dbo.UserMaster umc on cd.CreatedBy=umc.UserId
  83. left join dbo.UserMaster umm on cd.ModifiedBy=umm.UserId
  84. order by cd.ModifiedDateTime desc
  85. END
  86. CREATE PROCEDURE [dbo].[Proc_ValidateUser]
  87. @Mode varchar(50),
  88. @UserName varchar(20),
  89. @Password varchar(max)
  90. AS
  91. BEGIN
  92. IF @Mode='VALIDATEUSER'
  93. BEGIN
  94. IF EXISTS(SELECT 1 FROM dbo.UserMaster WHERE LOWER(UserName)=LOWER(@UserName) OR PhoneNumber=@UserName)
  95. BEGIN
  96. IF EXISTS(SELECT 1 FROM dbo.UserMaster WHERE (LOWER(UserName)=LOWER(@UserName) OR PhoneNumber=@UserName) AND ISNULL(IsActiveUser,0)=1)
  97. BEGIN
  98. IF EXISTS(SELECT 1 FROM dbo.UserMaster WHERE (LOWER(UserName)=LOWER(@UserName) OR PhoneNumber=@UserName) AND Password=@Password COLLATE SQL_Latin1_General_CP1_CS_AS)
  99. BEGIN
  100. SELECT 'true' AS IsAuthenticated,UserId,'!' AS UserFullName,'Login Successfully!' AS ErrorMessage
  101. FROM dbo.UserMaster WHERE (LOWER(UserName)=LOWER(@UserName) OR PhoneNumber=@Username) AND Password=@Password
  102. END
  103. ELSE
  104. BEGIN
  105. SELECT 'false' AS IsAuthenticated,0 AS UserId,'Wrong Password!' AS ErrorMessage
  106. END
  107. END
  108. ELSE
  109. BEGIN
  110. SELECT 'false' AS IsAuthenticated,0 AS UserId,'User Name is not Active!' AS ErrorMessage
  111. END
  112. END
  113. ELSE
  114. BEGIN
  115. SELECT 'false' AS IsAuthenticated,0 AS UserId,'User Name not Exist!' AS ErrorMessage
  116. END
  117. END
  118. END

Create Application

Open Visual Studio New > Project > Window Desktop > Select Windows Form Application.

After the project name hit OK and it will go to the solution explorer window.

Right click the project and select New> New Item.

I have added all files like the below structure

If you are going to use MDF, after creating this file run the above query in Visual Studio.

I have authenticated a simple username & password.

Only after login is validation, it the Parent form (MDI Form)

  1. if (TxtUserName.Text == "" || string.IsNullOrEmpty(TxtUserName.Text)) {
  2. LblMessage.Text = "Please Enter User Name";
  3. TxtUserName.Focus();
  4. return;
  5. }
  6. if (TxtPassword.Text == "" || string.IsNullOrEmpty(TxtPassword.Text))
  7. {
  8. LblMessage.Text = "Please Enter Password";
  9. TxtPassword.Focus();
  10. return;
  11. }
  12. try
  13. {
  14. var dsResult = new DataSet();
  15. var vmResult = new VmUserDetails();
  16. SqlParameter[] sqlParam = new SqlParameter[3];
  17. sqlParam[0] = new SqlParameter("@Mode", "VALIDATEUSER");
  18. sqlParam[1] = new SqlParameter("@UserName", TxtUserName.Text);
  19. sqlParam[2] = new SqlParameter("@Password", TxtPassword.Text);
  20. dsResult = objHelper.GetDatasetFromProcedure("dbo.Proc_ValidateUser", sqlParam);
  21. if (dsResult != null && dsResult.Tables.Count > 0)
  22. {
  23. if (dsResult.Tables[0].Rows.Count > 0)
  24. {
  25. vmResult = dsResult.Tables[0].ToList<VmUserDetails>().ToList().FirstOrDefault();
  26. }
  27. }
  28. if (vmResult.IsAuthenticated)
  29. {
  30. FrmChequeMaintanance frmMain = new FrmChequeMaintanance();
  31. GlobalAccess.GlobalUserId = vmResult.UserId;
  32. GlobalAccess.GlobalUserFullName = vmResult.UserFullName;
  33. frmMain.Text = "Welcome " + vmResult.UserFullName;
  34. this.Hide();
  35. }
  36. else
  37. {
  38. LblMessage.Text = vmResult.ErrorMessage;
  39. return;
  40. }
Check Details

Data is saved into the database and pending to data grid control.

  1. var objAddCheque = new VmAddCheque();
  2. if (TxtChequeNumber.Text == "" || string.IsNullOrEmpty(TxtChequeNumber.Text))
  3. {
  4. LblMessageFaliure.Text = "Please Enter Cheque Number";
  5. TxtChequeNumber.Focus();
  6. return;
  7. }
  8. if (TxtGivenTo.Text == "" || string.IsNullOrEmpty(TxtGivenTo.Text))
  9. {
  10. LblMessageFaliure.Text = "Please Enter the Name of the Person whom you gave this Cheque";
  11. TxtGivenTo.Focus();
  12. return;
  13. }
  14. if (TxtGivenDate.Text == "" || string.IsNullOrEmpty(TxtGivenDate.Text))
  15. {
  16. LblMessageFaliure.Text = "Please Select Cheque Issued date";
  17. TxtGivenDate.Focus();
  18. return;
  19. }
  20. if (TxtValidUpto.Text == "" || string.IsNullOrEmpty(TxtValidUpto.Text))
  21. {
  22. LblMessageFaliure.Text = "Please Select Cheque Expiry date";
  23. TxtValidUpto.Focus();
  24. return;
  25. }
  26. if (TxtAmount.Text == "" || string.IsNullOrEmpty(TxtAmount.Text))
  27. {
  28. LblMessageFaliure.Text = "Please Fill the Cheque Amount";
  29. TxtAmount.Focus();
  30. return;
  31. }
  32. objAddCheque.Mode = "INSERT";
  33. objAddCheque.ChequeNumber = TxtChequeNumber.Text;
  34. objAddCheque.GivenTo = TxtGivenTo.Text;
  35. objAddCheque.GivenDate = TxtGivenDate.Text;
  36. objAddCheque.ValidUpto = TxtValidUpto.Text;
  37. objAddCheque.Amount = Convert.ToDecimal(TxtAmount.Text);
  38. objAddCheque.Notes = RtfNotes.Text;
  39. SaveDatas(objAddCheque);

Report Generation

For the report concept I have used default Visual Studio report of rdlc. If you need, you can add any external reporting tool like crystal report, Telerik report…etc.

  1. this.procReportBindingSource.DataMember = "Proc_Report";
  2. this.procReportBindingSource.DataSource = this.chequeMaintananceDBdsReportBindingSource;
  3. //
  4. // chequeMaintananceDBdsReportBindingSource
  5. //
  6. this.chequeMaintananceDBdsReportBindingSource.DataSource = this.chequeMaintananceDBdsReport;
  7. this.chequeMaintananceDBdsReportBindingSource.Position = 0;
  8. //
  9. // chequeMaintananceDBdsReport
  10. //
  11. this.chequeMaintananceDBdsReport.DataSetName = "ChequeMaintananceDBdsReport";
  12. this.chequeMaintananceDBdsReport.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
  13. //
  14. // PnlReport
  15. //
  16. this.PnlReport.BackColor = System.Drawing.Color.SeaShell;
  17. this.PnlReport.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  18. this.PnlReport.Controls.Add(this.RptChequeDetails);
  19. this.PnlReport.Location = new System.Drawing.Point(13, 12);
  20. this.PnlReport.Name = "PnlReport";
  21. this.PnlReport.Size = new System.Drawing.Size(1457, 711);
  22. this.PnlReport.TabIndex = 1;