Page

Library Management Program in C#

class Program
    {
        static public int[] student = new int[100];
        static public int[] i = new int[5];
        static public int[] b = new int[5];
        static public int issuelimit = 2;
        static public string bookname;
        static public int id; 
        static public int bookcount;
        static public int bookid;
        static public int choice=0;
        static public char Repeat;

        static void Main(string[] args)
        {
            int choice=1;
            Console.WriteLine(" What do u want to do?\n");
            Console.WriteLine("1.Add a book to the Library");
            Console.WriteLine("2.Register a user ");
            Console.WriteLine("3.Issue a book");
            Console.WriteLine("4.Display list of Registered user");
            Console.WriteLine("5.Display list of books in library");
            Console.WriteLine("6.Exit");

            choice = Convert.ToInt16(Console.ReadLine());        

            LibMng lb = new LibMng();
            switch (choice)
            {
                case 1:
                    {   
                        do
                        {
                        Console.WriteLine("Enter the name of the book and the author's name: ");
                        string bookname = Convert.ToString(Console.ReadLine());
                        string author = Convert.ToString(Console.ReadLine());
                        bookcount++;
                        bookid++;
                            Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
                                Repeat = Convert.ToChar(Console.ReadLine());
                        } 
                            while (Repeat == 'y' || Repeat == 'Y');
                            break;                      
                    }
                case 2:
                    {
                        Console.WriteLine("Enter the name and address of user: ");
                        string studentname = Convert.ToString(Console.ReadLine());
                        string studentadd = Convert.ToString(Console.ReadLine());
                        Console.WriteLine("Enter the card ID");
                        id = Convert.ToInt16(Console.ReadLine());
                            do
                            {
                                if (student[id] != 0)
                                {
                                    lb.bookReturn();
                                }
                                else
                                {
                                    Console.WriteLine("Till no book is issued to this card");
                                    break;
                                }
                                Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
                                Repeat = Convert.ToChar(Console.ReadLine());
                            } 
                            while (Repeat == 'y' || Repeat == 'Y');
                            break;                      
                    }
                case 3:
                    {
                        Console.WriteLine("Enter the Student id");
                        id = Convert.ToInt16(Console.ReadLine());
                        do
                        {
                            if (student[id] < 2)
                            {
                                lb.Issue();
                            }
                            else
                            {
                                Console.WriteLine("Sorry no more books can be issued");
                                break;
                            }

                            Console.WriteLine("\nDo you wish to issue more to the same card??(y/n)");
                            Repeat = Convert.ToChar(Console.ReadLine());
                        }
                        while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }
                case 4:
                    {
                    do
                                {
                                    Console.WriteLine("the list of registered student is:");
                                    foreach (int a in Student)
                                    {
                                        Console.WriteLine("Name: ", a.studentname);
                                        Console.WriteLine("StudentId: {0}", a.studentid);
                                        Console.WriteLine("Number of books issued: {0}", a.NoOfBooksIssues);
                                    }
                                    Console.WriteLine("do you wish to continue??(y/n)");

                                } while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }
                case 5:
                    {
                                do
                                {
                                    Console.WriteLine("the list of books in library:");
                                    foreach (int b in BookLibrary)
                                    {
                                        Console.WriteLine("Book Title: {0}", b.bookname);
                                        Console.WriteLine("Book Id: {0}", b.bookid);
                                        Console.WriteLine("Author name: {0}", b.author);
                                    }
                                    Console.WriteLine("do you wish to continue??(y/n)");

                                } while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }                
                case 6:
                    {
                        break;
                    }

            }
                    Console.ReadLine();
            }
        }
        class LibMng : Program
        {
            public void Issue()
            {                
                Console.WriteLine("Enter The Book id ");
                int reqbook = Convert.ToInt32(Console.ReadLine());
                if (reqbook == bookid)
                {
                    if (i[0] != 0)
                    {
                        i[0]--;
                        Console.WriteLine("The Book is issued to Card{0}", id);
                        student[id]++;
                    }
                    else
                        Console.WriteLine("Book is not available");
                }
            }
            public void display()
            {
                Console.WriteLine("the books taken are: ");
            }

            public void chckAvail()
            {
                Console.WriteLine("Enter The Book id");
                int req = Convert.ToInt32(Console.ReadLine());
                if (req == bookid)
                {
                    if (i[0] != 0)
                    {
                        Console.WriteLine("The number of copy of the Book is::{0}", i[0]);
                    }
                    else
                        Console.WriteLine("Book is not available");
                }
            }
        }

            class BookLibrary: Program
            {
                public int bookcount;
                public int bookid;
                public string bookname;
                public string booktitle;

                public BookLibrary(int bookcount, int bookid, string bookname, string booktitle)
                {
                    this.bookcount = bookcount;
                    this.bookid = bookid;
                    this.bookname = bookname;
                    this.booktitle = booktitle;
                }               

            }
            class Student
            {
                public int studentcount;
                public int studentid;
                public string studentname;
                public int noOfbookissues = 0;

                public Student(int studentcount, int studentid, string studentname, int noOfbooksissued)
                {
                    this.studentcount = studentcount;
                    this.studentid = studentid;
                    this.studentname = studentname;
                    this.noOfbookissues = noOfbookissues;
                }
            }
            class IssueReturn: Program
            {            
                public void bookReturn()
                {
                Console.WriteLine("Enter The Book ID");
                int req1 = Convert.ToInt32(Console.ReadLine());

                if (req1==bookid)
                {
                    if (i[0] != 1)
                    {
                    i[0]++;
                    Console.WriteLine("The Book is returned from Card {0}", id);
                    student[id]--;
                    }
                else
                    Console.WriteLine("Till the Book is not issued to this Card");
                }
                }
            }
        }
    }

How to SUM two fields within an SQL query

                                                          Value1     Value2
                                                         -----------------------
                                                             3               6
                                                             1               5
                                                             4               3
                                                             8               1

SQL Query :

select Value1 + Value2 as qty  from Table1;

Result :

                                                               qty
                                                            ---------
                                                                9
                                                                6
                                                                7
                                                                9

How to Convert Amount (Currency) in words directly on Crystal Report.


To Create function follow the steps given below:
(i) go to Field Explorer
(ii) right click on Formula Fields click on New give specific name
(iii) Formula Editor window will open just paste the Code given below
(iv) Save & Close...
(v) Just drag the Field to your specific required Location that done...

Changes to be made from your side is
i) AmntTypes.UnitCost : This is a Database Field. Change as per your requirement.

Please note if you have Currency as Datatype in SQL DB than Do use ToNumber() function to convert it to number otherwise it will throw error of Number Required.

numbervar RmVal:=0;
currencyVar Amt:=0;
numbervar pAmt:=0;
stringvar InWords :="Rupees ";

Amt := ({AmntTypes.UnitCost});

if Amt > 10000000 then RmVal := truncate(ToNumber(Amt)/10000000);
if Amt = 10000000 then RmVal := 1;
if RmVal = 1 then
InWords := InWords + " " + towords(RmVal,0) + " crore"
else
if RmVal > 1 then InWords := InWords + " " + towords(RmVal,0) + " crores";

Amt := Amt - Rmval * 10000000;
if Amt > 100000 then RmVal := truncate(ToNumber(Amt)/100000);
if Amt = 100000 then RmVal := 1;
if RmVal >=1 then
InWords := InWords + " " + towords(RmVal,0) + " lakhs";

Amt := Amt - Rmval * 100000;
if Amt > 0 then InWords := InWords + " " + towords(truncate(Amt),0);
pAmt := (ToNumber(Amt) - truncate(ToNumber(Amt))) * 100;
if pAmt > 0 then
InWords := InWords + " and " + towords(pAmt,0) + " paisa only"
else
InWords := InWords + " only";
UPPERCASE(InWords)


How to Build a New Database in Access

Step 1. Create a blank database. First, launch Access and choose File> New.




Step 2. Add a database name. then press create.



Step 3. Right Click on Table.and select Design View and set the table name.




Step 4. Add Column name and set the DataType 




Step 5. Click Save



Messagebox with Yes No button c#

private void btnclose_Click(object sender, EventArgs e)
        {
            string message = "Do you want to close this window?";
            string title = "Tools Management System";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;

            DialogResult result = MessageBox.Show(message, title, buttons);
            if (result == DialogResult.Yes)
            {
                this.Dispose();
            }
            else
            {
                // Do something
            }
        }



How To Send Email From C# Windows Application Using Gmail SMTP

 private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();

                message.From = new MailAddress("abc@gmail.com");
                message.To.Add(new MailAddress("xyz@gmail.com"));
                message.Subject = "Test";
                message.Body = "Content";

                smtp.Port = 587;
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential("abc@gmail.com", "**********");
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("err: " + ex.Message);
            }
}

How to get Hidden Column Value in GridView

Try to have them Visible="true", but hide them with CSS.

METHOD 1:

<style type="text/css">
 .hidden-col
 {
     display:none;
 }
</style>


<asp:BoundField HeaderText="User ID" DataField="Id" ItemStyle-CssClass="hidden-col" HeaderStyle-CssClass="hidden-col" >

</asp:BoundField>


METHOD 2:

<asp:BoundField HeaderText="User ID" DataField="Id"  Visible="False" >

</asp:BoundField>