Sunday, January 30, 2011

WPF Combobox Selected Index Change

private void cmbPCNo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                string PCName = cmbPCNo.SelectedValue as string;
                txtUserTicket.Text = objTimeManagementManager.GetTicketNoManager(PCName, DateTime.Today);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "PC Name", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

Saturday, January 29, 2011

WPF generate xml file for list view data to save in database.

   /**********Generatating XML**********/
            string strEmploymentInfoListObject = "";
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(ticket.ListOfTicket.GetType());
            MemoryStream memoryStream = new MemoryStream();
            XmlTextWriter xmlWriter;
            xmlWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            xmlWriter.Namespaces = true;
            x.Serialize(xmlWriter, ticket.ListOfTicket);
            xmlWriter.Close();
            memoryStream.Close();
            string xml;
            xml = Encoding.UTF8.GetString(memoryStream.GetBuffer());
            xml = xml.Substring(xml.IndexOf(Convert.ToChar(60)));
            xml = xml.Substring(0, (xml.LastIndexOf(Convert.ToChar(62)) + 1));
            strEmploymentInfoListObject = xml;
            


            /****** Checking The XML Data is Generate or not ********/
           
            MessageBox.Show(strEmploymentInfoListObject);
            ticketManager.SaveAllGenerateTicketInfo(xml);

Edit List view control in WPF

Consider the following Class.Mind it that you have to bind the class in list view property.


EPromotion objPromotion =new EPromotion();
objPromotion.EmployeeId = Convert.ToInt64(employeeIdTextBox.Text);
objPromotion.EmployeeName = employeeNameTextBox.Text;
List<EPromotion> liPromotion = new List<EPromotion>();
liPromotion.Add(objPromotion);
objPromotion.listPromotion = liPromotion;

/******** ADD ******/
promotionlistView.Items.Add(objPromotion);

/*** Selected EDIT *****/

EPromotion selectedPromotion = (EPromotion)this.promotionlistView.SelectedItem;

/***** Selected remove *******/
promotionlistView.Items.RemoveAt(promotionlistView.Items.IndexOf(promotionlistView.SelectedItem));

Wednesday, January 26, 2011

Copy a store procedure from one database to another.

Some times we need to copy a store procedure from one database to another. then we have to follow the following steps:

Right click on the SP under the DB and click Script Stored Procedure As > CREATE To > File, it will create an SQL script file, then run that script on the other database.




It's important that when you execute the store procedure just rename the database name.

Copy a table from one database to another database in SQL

Open a new query window in SQL server Management studio. in which database you want to copy a  table. Type

select* 
into new_name_of_table 
from old_database.table_name.

such as:
select* into Appointments from IEMS2.dbo.Appointments

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...