Object to Json

 Convert to Json

protected void Button1_Click(object sender, EventArgs e)
        {
            Student s1 = new Student();
            s1.StudentID = TextBox1.Text;
            s1.Fname = TextBox2.Text;
            s1.Lname = TextBox3.Text;

            var json = new JavaScriptSerializer().Serialize(s1);
         
            // Write the string to a file.
            System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Lakshika\Desktop\dd.txt");
            file.WriteLine(json);

            List student=new List();
            student.Add(s1);

            _studentOp = new StudentOperations();
            _studentOp.SaveStudent(student);

            file.Close();
        }
Sunday, October 18, 2015
Posted by sinhalamp3

MVC 3 Full Teacher

Teacher Controller

public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            DBOperations db = new DBOperations();

            List qualification = db.getAllQualifications();
            ViewBag.QualificationList = new SelectList(qualification, "QualificationID", "QualificationType");
            List school = db.getAllSchools();
            ViewBag.SchoolList = new SelectList(school, "SchoolID", "SchoolName");
            return View();
        }

        [HttpPost]
        public ActionResult Create(Teacher teacher)
        {
            DBOperations db = new DBOperations();

            List qualification = db.getAllQualifications();
            ViewBag.QualificationList = new SelectList(qualification, "QualificationID", "QualificationType");
            List school = db.getAllSchools();
            ViewBag.SchoolList = new SelectList(school, "SchoolID", "SchoolName");
            db.insertTeacher(teacher);
            return View();

        }

        public ActionResult ViewTeacher()
        {
            DBOperations db = new DBOperations();
            List teachers = db.getAllTeachers();
            return View(teachers.AsEnumerable());
        }

        //public JsonResult View(int id)
        //{
        //    DBOperations db = new DBOperations();
        //    return Json(db.getTeacherById(id), JsonRequestBehavior.AllowGet);
        //}

        public ActionResult ViewTeacherById(int id)
        {
            DBOperations db = new DBOperations();
            Teacher teacher = db.getTeacherById(id);
            List school = db.getAllSchools();
            foreach (var items in school)
            {
                if (items.SchoolID == teacher.SchoolID)
                {
                    ViewData["SchoolName"] = items.SchoolName;
                }
            }
            List qualifications = db.getAllQualifications();
            foreach (var items in qualifications)
            {
                if (items.QualificationID == teacher.QualificationID)
                {
                    ViewData["Type"] = items.QualificationType;
                }
            }
            return View(teacher);
        }


        public ActionResult UpdateTeacher(int id)
        {

            DBOperations db = new DBOperations();
            List schools = db.getAllSchools();
            ViewBag.SchoolList = new SelectList(schools, "SchoolID", "SchoolName");
            List qualifications = db.getAllQualifications();
            ViewBag.QualificationList = new SelectList(qualifications, "QualificationID", "QualificationType");
            Teacher model = db.getTeacherById(id);

            return View(model);

        }

        [HttpPost]
        public ActionResult UpdateTeacher(Teacher teacher)
        {
            DBOperations db = new DBOperations();
            List schools = db.getAllSchools();
            ViewBag.SchoolList = new SelectList(schools, "SchoolID", "SchoolName");
            List qualifications = db.getAllQualifications();
            ViewBag.QualificationList = new SelectList(qualifications, "QualificationID", "QualificationType");
           // Teacher model = db.getTeacherById(id);

            db.UpdateTeacher(teacher);

            return View("ViewTeacher");

        }

        [HttpDelete]
        public ActionResult ViewTeacher(int id)
        {
            DBOperations db = new DBOperations();
            db.DeleteTeacher(id);
            return View("ViewTeacher");
        }
-------------------------------------------------------------------------------------

DB Operations Class

public void insertTeacher(Teacher teacher)
        {
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "insert into Teacher values ('"+teacher.TeacherName+"','"+teacher.TeacherNIC+"','"+teacher.TeacherAddress+"',"+teacher.QualificationID+","+teacher.SchoolID+")";
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        public List getAllQualifications()
        {
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from Qualification";
            SqlDataReader dr = cmd.ExecuteReader();
            List qualifications = new List();
            while (dr.Read())
            {
                Qualification qualification = new Qualification();
                qualification.QualificationID = dr.GetInt32(0);
                qualification.QualificationType = dr.GetString(1);

                qualifications.Add(qualification);
            }

            return qualifications;
        }

        public List getAllSchools()
        {
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from School";
            SqlDataReader dr = cmd.ExecuteReader();
            List schools = new List();
            while (dr.Read())
            {
                School school = new School();
                school.SchoolID = dr.GetInt32(0);
                school.SchoolName = dr.GetString(1);

                schools.Add(school);
            }

            return schools;
        }

        public List getAllTeachers()
        {
            List teachers = new List();
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT * FROM Teacher";
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Teacher teacher = new Teacher();
                teacher.TeacherID = dr.GetInt32(0);
                teacher.TeacherName = dr.GetString(1);
                teacher.TeacherNIC = dr.GetString(2);
                teacher.TeacherAddress = dr.GetString(3);
                teacher.QualificationID = dr.GetInt32(4);
                teacher.SchoolID = dr.GetInt32(5);
                
                teachers.Add(teacher);
            }
            return teachers;

        }

        public Teacher getTeacherById(int teacher_id)
        {
            Teacher teacher = new Teacher();
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from Teacher where TeacherID="+teacher_id+"";
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                teacher.TeacherID = dr.GetInt32(0);
                teacher.TeacherName = dr.GetString(1);
                teacher.TeacherNIC = dr.GetString(2);
                teacher.TeacherAddress = dr.GetString(3);
                teacher.QualificationID = dr.GetInt32(4);
                teacher.SchoolID = dr.GetInt32(5);
            }

            return teacher;
        }

        public void UpdateTeacher(Teacher teacher)
        {
            int teacher_id = teacher.TeacherID;
            string teacher_name = teacher.TeacherName;
            string teacher_address = teacher.TeacherAddress;
            string teacher_nic = teacher.TeacherNIC;
            int quali_id = teacher.QualificationID;
            int school_id = teacher.SchoolID;

            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "Update Teacher set TeacherName='" + teacher_name + "',TeacherNIC='" + teacher_nic + "',TeacherAddress='" + teacher_address + "',QualificationID=" + quali_id + ",SchoolID=" + school_id + " where TeacherID=" + teacher_id + "";
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        public void DeleteTeacher(int id)
        {
            SqlConnection conn = new SqlConnection(Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "delete from Teacher where TeacherID="+id+"";
            cmd.ExecuteNonQuery();
            conn.Close();
        }

---------------------------------------------------------------------------------------------

DBConnection Class

public class Connection
    {
        public static string ConnectionString
        {
            get { return "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SINGADB;Data Source=Lakshika-PC\\SQLEXPRESS"; }
        }
     
 
    }
Saturday, October 17, 2015
Posted by sinhalamp3

MVC 2 Create, Search

Create Student

Controller

DekmaEntities _dekmaEntities;

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Student student)
        {
            using (_dekmaEntities = new DekmaEntities())
            {
                _dekmaEntities.Students.AddObject(student);
                _dekmaEntities.SaveChanges();

                return View("Index");
            }

        }

public ActionResult ViewAll()
        {
            using (_dekmaEntities = new DekmaEntities())
            {
                var stu = _dekmaEntities.Students.Take(10).ToArray();
                List studentList = new List();

                for (int i = 0; i < stu.Length; i++)
                {
                    Student student = new Student();
                    student.Student_ID = stu[i].Student_ID;
                    student.Name = stu[i].Name;

                    studentList.Add(student);
                }

                return View(studentList);
            }
        }
---------------------------------------------------------------------------------------------

Views

---
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>


Create




   

Create



    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

       

            Fields
           
           

                <%: Html.LabelFor(model => model.Student_ID) %>
           
           

                <%: Html.TextBoxFor(model => model.Student_ID) %>
                <%: Html.ValidationMessageFor(model => model.Student_ID) %>
           
           
           

                <%: Html.LabelFor(model => model.Name) %>
           
           

                <%: Html.TextBoxFor(model => model.Name) %>
                <%: Html.ValidationMessageFor(model => model.Name) %>
           
           
           

                <%: Html.LabelFor(model => model.House) %>
           
           

                <%: Html.TextBoxFor(model => model.House) %>
                <%: Html.ValidationMessageFor(model => model.House) %>
           
           
           

                <%: Html.LabelFor(model => model.street) %>
           
           

                <%: Html.TextBoxFor(model => model.street) %>
                <%: Html.ValidationMessageFor(model => model.street) %>
           
           
           

                <%: Html.LabelFor(model => model.City) %>
           
           

                <%: Html.TextBoxFor(model => model.City) %>
                <%: Html.ValidationMessageFor(model => model.City) %>
           
           
           

                <%: Html.LabelFor(model => model.Gender) %>
           
           

                <%: Html.TextBoxFor(model => model.Gender) %>
                <%: Html.ValidationMessageFor(model => model.Gender) %>
           
           
           

                <%: Html.LabelFor(model => model.Birth_day) %>
           
           

                <%: Html.TextBoxFor(model => model.Birth_day) %>
                <%: Html.ValidationMessageFor(model => model.Birth_day) %>
           
           
           

                <%: Html.LabelFor(model => model.NIC) %>
           
           

                <%: Html.TextBoxFor(model => model.NIC) %>
                <%: Html.ValidationMessageFor(model => model.NIC) %>
           
           
           

                <%: Html.LabelFor(model => model.Tel_land) %>
           
           

                <%: Html.TextBoxFor(model => model.Tel_land) %>
                <%: Html.ValidationMessageFor(model => model.Tel_land) %>
           
           
           

                <%: Html.LabelFor(model => model.Tel_mobile) %>
           
           

                <%: Html.TextBoxFor(model => model.Tel_mobile) %>
                <%: Html.ValidationMessageFor(model => model.Tel_mobile) %>
           
           
           

                <%: Html.LabelFor(model => model.Stream) %>
           
           

                <%: Html.TextBoxFor(model => model.Stream) %>
                <%: Html.ValidationMessageFor(model => model.Stream) %>
           
           
           

                <%: Html.LabelFor(model => model.Ex_Center) %>
           
           

                <%: Html.TextBoxFor(model => model.Ex_Center) %>
                <%: Html.ValidationMessageFor(model => model.Ex_Center) %>
           
           
           

                <%: Html.LabelFor(model => model.T_R) %>
           
           

                <%: Html.TextBoxFor(model => model.T_R) %>
                <%: Html.ValidationMessageFor(model => model.T_R) %>
           
           
           

                <%: Html.LabelFor(model => model.AL_Year) %>
           
           

                <%: Html.TextBoxFor(model => model.AL_Year) %>
                <%: Html.ValidationMessageFor(model => model.AL_Year) %>
           
           
           

                <%: Html.LabelFor(model => model.School_Name) %>
           
           

                <%: Html.TextBoxFor(model => model.School_Name) %>
                <%: Html.ValidationMessageFor(model => model.School_Name) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_Name) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_Name) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_Name) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_TP) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_TP) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_TP) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_Occupation) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_Occupation) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_Occupation) %>
           
           
           
               
           
       

    <% } %>

   

        <%: Html.ActionLink("Back to List", "Index") %>
   



Sunday, October 11, 2015
Posted by sinhalamp3

Encript/Decrpt

Encript/Decrpt

static void Main(string[] args)
        {
            string a = "a";

            Console.WriteLine(Encript(a).ToString());
            Decript(15731535468486);
            Console.ReadLine();
        }

        static Int64 Encript(string p)
        {
            Int64 c = 31;

            for (int i = 0; i < p.Length; i++)
            {
                c = c * 47 + (byte)p[i] % 97;              
            }

            return c;
        }

        static void Decript(Int64 n)
        {
            Int64 letter = 0;

            while (letter < 31)
            {
                letter = n % 47;
                char l = (char)(letter + 97);
                Console.WriteLine(l);

                n = (n - letter) / 47;
            }
        }
Tuesday, October 14, 2014
Posted by sinhalamp3

EJB - without Msg Bean


EJB

1)      Add entity class to ELB module.
2)      Create Façade(Add Session Bean for Entity Classes.)
Entity Class(Student)
public class Student implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long studentid;  // Rename id into YOUR Primary Key or ID idà studentid
    private String name;   
    private int age;

    public Long getStudentid() {
        return studentid;
    }

    public void setStudentid(Long studentid) {
        this.studentid = studentid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
Then Create Façade(Add Session Bean for Entity Classes.)   
Don’t want to do any modification in Façade classes.

OKKK

AddStudent - Add Servlet to Web Module
out.println("");
            out.println("");
            out.println("");
            out.println("Servlet AddStudent");           
            out.println("
");
            out.println("");
            out.println("

Servlet Add Student

");
           
           
            out.println("
");
            out.println("Student Name:
");
            out.println("Student Age :
");
           
            out.println("
");
            out.println("
");
           
           
           
            
            out.println("
");
            out.println("
");
Modify DoPost Method in Servlet

@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
     
         String name = request.getParameter("name");
        String age = request.getParameter("age");
                Student student = new Student();
        student.setName(name);
        student.setAge(Integer.parseInt(age));     
        studentFacade.create(student);       
       
        processRequest(request, response);
    }

View Student  Servlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
           
            List students = studentFacade.findAll();
           
           
            out.println("");
            out.println("");
            out.println("");
            out.println("Servlet ViewStudent");           
            out.println("
");
            out.println("");
            out.println("

Servlet ViewStudent

");
                                  
            out.println("");
           
            out.println("");
            out.println(" ");
            out.println("
Student ID
");
            out.println("
name
");
            out.println("
age
");
            out.println("
");
            out.println("
");
           
            for (Iterator it = students.iterator(); it.hasNext();) {
                Student elem = (Student) it.next();
               
                out.println(" ");
                out.println("
");
                out.println(elem.getStudentid() + "
");
                out.println("
");
               
                out.println("
");
                out.println(elem.getName()+ "
");
                out.println("
");
               
                out.println("
");
                out.println(elem.getAge() + "
");
                out.println("
");
               
                out.println("
");
                
             }      
        
            out.println("
");
            out.println("
");
            out.println("
");
            out.println("
");
           
           
           
            out.println("
");
            out.println("
");
        }

    }
Posted by sinhalamp3

Mongo DB - (DBManager and CRUD)

DBManager

* @author Lakshika
 */
public class DBManager {
    private static DB database;
 
    public static DB getDatabase() {
if(database == null) {
MongoClient mongo;
try {
mongo = new MongoClient("localhost", 27017);
database = mongo.getDB("usermanager");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return database;
}
 

}

=======================================================================

User Class


public class User {
   
    private int id;
    private String firstName;
    private String lastName;
    private String email;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;

    }

=================================================================


AddUser Interface

 private static DBObject createDBObject(User user) {
       BasicDBObjectBuilder docBuilder = BasicDBObjectBuilder.start();                              
       docBuilder.append("_id", user.getId());
       docBuilder.append("firstName", user.getFirstName());
       docBuilder.append("lastName", user.getLastName());
       docBuilder.append("Email", user.getEmail());
       return docBuilder.get();

    }

AddUser Buttn Click

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {    // Add User                                  
        // TODO add your handling code here:
     
     
        User newUser = new User();
        newUser.setId(Integer.parseInt(jTextField1.getText()));
        newUser.setFirstName(jTextField2.getText());
        newUser.setLastName(jTextField3.getText());
        newUser.setEmail(jTextField4.getText());

        DBObject doc = createDBObject(newUser);
        DB userDB = DBManager.getDatabase();
        DBCollection col = userDB.getCollection("user");
        WriteResult result = col.insert(doc);
     
        JOptionPane.showMessageDialog(rootPane, "User Insert SucessFully...!");
        jTextField1.setText("");      
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");

    }    

=======================================================================

View User Details in jTable

public void printmongData()
    {
 
        DefaultTableModel model = new DefaultTableModel();

        model.addColumn("ID");
        model.addColumn("First Name");
        model.addColumn("Last Name");
        model.addColumn("Email");

 
 
        DB userDB = DBManager.getDatabase();
        DBCollection col = userDB.getCollection("user");
     
         DBCursor cursor = col.find();
     
         while (cursor.hasNext()) {
             DBObject user=(DBObject) cursor.next();        
            model.addRow(new Object[] {user.get("_id"),user.get("firstName"),user.get("lastName"),user.get("Email")});
       
         }
         jTable1.setModel(model);

    }

///////////////////// Call the Method ---------------

private void formWindowOpened(java.awt.event.WindowEvent evt) {                                
        // TODO add your handling code here:
     
        printmongData();
    }

=====================================================================
Load UserID to ComboBox

 public void fillID() {
        DB userDB = DBManager.getDatabase();
        DBCollection col = userDB.getCollection("user");

        DBCursor cursor = col.find();

        while (cursor.hasNext()) {
            DBObject user = (DBObject) cursor.next();
            jComboBox1.addItem(user.get("_id"));
        }

    }


//////////////// Call it in WindowOpened Event

private void formWindowOpened(java.awt.event.WindowEvent evt) {                                
        // TODO add your handling code here:
     
        fillID();
     
    }
=================================================================
Get Selected ComboBox Value

private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {                                          
        // TODO add your handling code here:
     
        DB userDB = DBManager.getDatabase();
        DBCollection col = userDB.getCollection("user");

        DBCursor cursor = col.find();

        while (cursor.hasNext()) {
            DBObject user = (DBObject) cursor.next();
            int seletedID = Integer.parseInt(jComboBox1.getSelectedItem().toString());
         
                    //       JOptionPane.showMessageDialog(rootPane, user.get("_id").toString());
                     //      JOptionPane.showMessageDialog(rootPane, jComboBox1.getSelectedItem().toString());

            if(user.get("_id").toString().equals(jComboBox1.getSelectedItem().toString()))
           {
             
                jTextField1.setText(user.get("_id").toString());
                jTextField2.setText(user.get("firstName").toString());
                jTextField3.setText(user.get("lastName").toString());
                jTextField4.setText(user.get("Email").toString());

            }


        }
===============================================================

Update User (btnClick)

try {
            DB userDB = DBManager.getDatabase();
            DBCollection col = userDB.getCollection("user");

            BasicDBObject query = new BasicDBObject("_id", new BasicDBObject("$eq", Integer.parseInt(jTextField1.getText())));

            BasicDBObject newDocument = new BasicDBObject();
            newDocument.put("firstName", jTextField2.getText());
            newDocument.put("lastName", jTextField3.getText());
            newDocument.put("Email", jTextField4.getText());

            BasicDBObject updateObj = new BasicDBObject();
            updateObj.put("$set", newDocument);

            col.update(query, updateObj, false, true);

            JOptionPane.showMessageDialog(rootPane, "User Update SucessFully...!");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Please Select User");

        }

===============================================================
Delete User (btnClick)

try {
            DB userDB = DBManager.getDatabase();
            DBCollection col = userDB.getCollection("user");

            BasicDBObject query = new BasicDBObject("_id", new BasicDBObject("$eq", Integer.parseInt(jTextField1.getText())));
            col.remove(query);

            JOptionPane.showMessageDialog(rootPane, "User Delete SucessFully...!");
            this.setVisible(false);
            this.dispose();
            ManageUsers mange= new ManageUsers();
            mange.setVisible(true);
         
         

        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Please Select User");
        }











Monday, October 13, 2014
Posted by sinhalamp3

Web Service Currency Convertor


Consume a Web Service in ASP.NET

//-------------------------------------------Windows Form -------------------------------
private void Form1_Load(object sender, EventArgs e)
        {
foreach (var item in Enum.GetValues(typeof(ServiceReference1.Currency)))
            {
                comboBox1.Items.Add(item);
                comboBox2.Items.Add(item);
            }
}


private void button1_Click(object sender, EventArgs e)
        {
            String one = comboBox1.SelectedItem.ToString();
            String two = comboBox2.SelectedItem.ToString();

            int three = Int32.Parse(textBox1.Text);

            ServiceReference1.Currency cd = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), one);
            ServiceReference1.Currency cd1 = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), two);
            ServiceReference1.CurrencyConvertorSoapClient ws = new ServiceReference1.CurrencyConvertorSoapClient("CurrencyConvertorSoap");
            double ds = ws.ConversionRate(cd, cd1);
            double result = ds * three;
            textBox2.Text = result.ToString();

        }
---------------------------------------------------------------------------
----------------------------------------ASP .NET --------------------------

protected void Page_Load(object sender, EventArgs e)
 {
            string[] names = Enum.GetNames(typeof(ServiceReference1.Currency));
            int[] values = (int[])Enum.GetValues(typeof(ServiceReference1.Currency));
            for (int i = 0; i < names.Length; i++)
            {
                DropDownList1.Items.Add(
                   new ListItem(
                     names[i],
                     values[i].ToString()
                    )    
        );
            }

            for (int i = 0; i < names.Length; i++)
            {
                DropDownList2.Items.Add(
                   new ListItem(
                     names[i],
                     values[i].ToString()
                    )
        );
            }




                //foreach (var item in Enum.GetValues(typeof(ServiceReference1.Currency)))
                //{
                //    to.Items.Add(item);


                //}
         
        }

-----------------------------------------------------------------------------------------------
        protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {

                ServiceReference1.CurrencyConvertorSoapClient client = new ServiceReference1.CurrencyConvertorSoapClient();

                ServiceReference1.Currency fromValue = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), DropDownList1.SelectedItem.ToString());

                ServiceReference1.Currency toValue = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), DropDownList2.SelectedItem.ToString());

                double currencyValue = Convert.ToDouble(TextBox1.Text.ToString());

                double finalValue = currencyValue * (Convert.ToDouble(client.ConversionRate(fromValue, toValue).ToString()));

                Label1.Text = finalValue.ToString();

             
             

            }
            catch (Exception ex)
            {
            }
        }
}
Posted by sinhalamp3

Popular Post

Blogger templates

lakshika345@gmail.com. Powered by Blogger.

- Copyright © mp3s for you -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -