Showing posts with label Windows application. Show all posts
Showing posts with label Windows application. Show all posts

Friday, August 24, 2018

Sample Use Case document for any development


User case is important role play in our any new development. The developer well know the post and per-condition of what he want to develop to get some clear idea. Without any use case or wire-frame if we develop any application then defiantly have more modification/Changes after the release. So best before start any new module developer should have Use Case document.

The below one sample template for use case diagram.

USE CASE ID:
UC-01
DESCRIPTION:
This use case describes the xxxxxx xxxxx sample tool
REQUIREMENT ID(S):
RE-1.1, RE-1.2 ….. RE-1.9
ACTOR(S):
 User
PRE-CONDITIONS:
Configured tool and page to submit
POST-CONDITIONS:
Post conditions.
BASIC FLOW:

 Submit registration.
Verify the user name
Save the user to database
Display the result
EXCEPTION FLOW 1:

User name or email unavailable.
Not valid data entered.

Friday, May 6, 2016

Simple Example of Singleton Design Pattern in C# Example

Simple Example of Singleton Design Pattern in C# Example


UI Code:
 ApplicationState state = ApplicationState.GetState();
            state.LoginId="Kanchan";
            state.RoleId= "Admin";
         
            ApplicationState state2 = ApplicationState.GetState();
            label3.Text = state2.LoginId;
            label5.Text = state2.RoleId;
            label6.Text = (state == state2).ToString();

Singleton Class Code:
 class ApplicationState
    {
        private static ApplicationState instance=null;
        // State Information  
        public string LoginId
        { get; set;}
        public string RoleId
        { get; set; }
   
        private ApplicationState()
        {        
        }
        //Lock Object
        private static object lockThis = new object();
        public static ApplicationState GetState()  
        {
            lock (lockThis)      
            {          

                if (ApplicationState.instance == null)
                  instance = new ApplicationState();      
            }      
                return instance;            
        }  
     
    }

Wednesday, October 7, 2015

How to read simple excel file in c#.net Or Import excel file in C#.net



Previously I have explained the code for saving data to Excel file. But here I am going to give the C#.Net code to read data from excel file row by row and column by column automatically. You no need to specify the column to read.
The below code will read all the row and column data field and assign to string value. You can modify the saving methodology to DataTable or List which other way you want.

Source Code:
 
private void LoadICMClient()
        {
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                MessageBox.Show("Excel is not properly installed!!");
                return;
            }

            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Range range;
            string str;
            int rCnt = 0;
            int cCnt = 0;

            xlWorkBook = xlApp.Workbooks.Open(Directory.GetCurrentDirectory() + @"\Reports\Test.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            range = xlWorkSheet.UsedRange;

            for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
            {
                for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
                {
                    str = (string)(range.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2;
                    MessageBox.Show(str);
                }
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();
            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
        }


The below code will release the Excel dll object and clear the reference info.

private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }