Thursday 31 January 2013

Treeview Data Retrive in Database and show in trieeview in window application


  void filltrv()
        {
            try
            {
                trvCategory.Nodes.Clear();
                var n = (from y in ss.GetInstance.GetAllMenus()
                         where y.Parent_Menu_ID == 0
                         select y).ToList();
                for (i = 0; i < n.Count; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Tag = n[i].Menu_ID.ToString();
                    tn.Text = n[i].Menu_Name.ToString();
                    trvCategory.Nodes.Add(tn);
                }
                for (i = 0; i < trvCategory.Nodes.Count; i++)
                {
                    var nn = (from y in ss.GetInstance.GetAllMenus()
                              where y.Parent_Menu_ID == Convert.ToInt32(trvCategory.Nodes[i].Tag.ToString())
                              select y).ToList();
                    if (nn.Count > 0)
                    {
                        for (int j = 0; j < nn.Count; j++)
                        {
                            TreeNode tn1 = new TreeNode();
                            tn1.Tag = nn[j].Menu_ID.ToString();
                            tn1.Text = nn[j].Menu_Name.ToString();
                            trvCategory.Nodes[i].Nodes.Add(tn1);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
      private void trvCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                int x=trvCategory.SelectedNode.Level;
                if (x == 0)
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Tag);
                }
                else
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Parent.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Parent.Tag);
                }
               
               
                trvCategory.Visible = false;
                CmbSequence.Enabled = true;
                BindSequence();
            }
            catch (Exception ex)
            {
            }
        }
DataBase Design

Other City Add When user choose other in Combobox in WindoApplication


 void BindCity(int State_ID)
        {
            var objcity = from hhh in ERPManagement.GetInstance.GetAllCity()
                          where hhh.State_ID == State_ID
                          select hhh;

            List<ss> Cities = new List<ss>();
            ssdummy = new ss();
            dummy.City_Name = "Select";
            dummy.City_ID = 0;
            Cities.Add(dummy);
            foreach (ss City in objcity)
            {
                Cities.Add(City);
            }
            TAGGING_CountryStateCity dummy_ = new TAGGING_CountryStateCity();
            dummy_.City_Name = "Other";
            dummy_.City_ID = -1;
            Cities.Add(dummy_);
            cmbCity.DataSource = Cities;
            cmbCity.DisplayMember = "City_Name";
            cmbCity.ValueMember = "City_ID";
        }



 if (CourierId == 0)
            {
                ww ObjInsert = new ww ();
                ObjInsert.Courier_Code = TxtCourierCode.Text.Trim();
                if (TxtCourierName.Text != "")
                {
                    ObjInsert.Courier_Name = TxtCourierName.Text;
                }
                else
                {
                    MessageBox.Show("Courier name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);  
                    TxtCourierName.Focus();
                    return;
                }
                if (TxtContactPersonName.Text != "")
                {
                    ObjInsert.Contact_Person_Name = TxtContactPersonName.Text;
                }
                else
                {
                    MessageBox.Show("ContactPerson name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtContactPersonName.Focus();
                    return;
                }
                if (TxtAddress.Text != "")
                {
                    ObjInsert.Address = TxtAddress.Text;
                }
                else
                {
                    MessageBox.Show("Address cannot be blank ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtAddress.Focus();
                    return;
                }
                ObjInsert.Mobile_No = TxtMobNo.Text;
                ObjInsert.Alternate_Mobile_No = TxtAlterNateMobNo.Text;

                ObjInsert.Phone_No = TxtPhoneNo.Text;
                ObjInsert.Fax_No = TxtFaxNo.Text;
                if (cmbCountry.SelectedIndex != 0)
                {
                    ObjInsert.Country_ID = Convert.ToInt32(cmbCountry.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a country. ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               
                    cmbCountry.Focus();
                    return;
                }
                if (cmbState.SelectedIndex != 0)
                {
                    ObjInsert.State_ID = Convert.ToInt32(cmbState.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a state.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                
                    cmbState.Focus();
                    return;
                }
                if (cmbCity.SelectedIndex != 0)
                {
                    ObjInsert.City_ID = Convert.ToInt32(cmbCity.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a city.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);              
                    cmbCity.Focus();
                    return;
                }
                ObjInsert.Email_ID = TxtEmailId.Text;
                ObjInsert.Additional_Info1 = TxtAdditionalInfo1.Text;
                ObjInsert.Additional_Info2 = TxtAdditionalInfo2.Text;
                ObjInsert.Additional_Info3 = TxtAdditionalInfo3.Text;
                ObjInsert.City = TxtCityadd.Text.Trim();
                TxtCourierCode.Text=ERPManagement.GetInstance.InsertManageCourier(ObjInsert);
                MessageBox.Show("Data saved successfully.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Information);
               // tabControlItemType.SelectedIndex = 0;
                Reset();
            }
            else
            {
                Pos_ManageCourier ObjUpdate = new Pos_ManageCourier();
                ObjUpdate.Courier_Code = TxtCourierCode.Text;
                ObjUpdate.Courier_ID = CourierId;

                if (TxtCourierName.Text != "")
                {
                    ObjUpdate.Courier_Name = TxtCourierName.Text;
                }
                else
                {
                    MessageBox.Show("Courier name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);  
             
                    TxtCourierName.Focus();
                    return;
                }
                if (TxtContactPersonName.Text != "")
                {
                    ObjUpdate.Contact_Person_Name = TxtContactPersonName.Text;
                }
                else
                {
                    MessageBox.Show("Contact person name can't be blank. ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    TxtContactPersonName.Focus();
                    return;
                }
                if (TxtAddress.Text != "")
                {
                    ObjUpdate.Address = TxtAddress.Text;
                }
                else
                {
                    MessageBox.Show("Address can't be blank.", "ddd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtAddress.Focus();
                    return;
                }
                ObjUpdate.Mobile_No = TxtMobNo.Text;
                ObjUpdate.Alternate_Mobile_No = TxtAlterNateMobNo.Text;

                ObjUpdate.Phone_No = TxtPhoneNo.Text;
                ObjUpdate.Fax_No = TxtFaxNo.Text;
                if (cmbCountry.SelectedIndex != 0)
                {
                    ObjUpdate.Country_ID = Convert.ToInt32(cmbCountry.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a country.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    cmbCountry.Focus();
                    return;
                }
                if (cmbState.SelectedIndex != 0)
                {
                    ObjUpdate.State_ID = Convert.ToInt32(cmbState.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a state.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    cmbState.Focus();
                    return;
                }
                if (cmbCity.SelectedIndex != 0)
                {
                    ObjUpdate.City_ID = Convert.ToInt32(cmbCity.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a city.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    cmbCity.Focus();
                    return;
                }
                ObjUpdate.Email_ID = TxtEmailId.Text;
                ObjUpdate.Additional_Info1 = TxtAdditionalInfo1.Text;
                ObjUpdate.Additional_Info2 = TxtAdditionalInfo2.Text;
                ObjUpdate.Additional_Info3 = TxtAdditionalInfo3.Text;
                ObjUpdate.City = TxtCityadd.Text.Trim();
                ERPManagement.GetInstance.UpdateManageCourier(ObjUpdate);
                MessageBox.Show("Data updated successfully.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                tabControlItemType.SelectedIndex = 0;
                TxtCityadd.Text = "";
                TxtCityadd.Visible = false;
            }
        }
StoreProcedure


ALTER PROCEDURE InsertManageCourier
(
@Courier_Name varchar(50),
@Contact_Person_Name varchar(50),
@Address varchar(max),
@City_ID INT,
@State_ID INT,
@Country_ID INT,
@Mobile_No varchar(20),
@Alternate_Mobile_No varchar(20),
@Phone_No varchar(20),
@Email_ID varchar(50),
@Fax_No varchar(50),
@Additional_Info1 varchar(max),
@Additional_Info2 varchar(max),
@Additional_Info3 varchar(max),
@CityName Varchar(50)=NULL,
@P_RET_VALUE    VARCHAR(50) OUTPUT
)
AS BEGIN
DECLARE @p_pcd VARCHAR(20)
SET @p_pcd=(SELECT RIGHT('000'+ CONVERT(VARCHAR(50),MAX(SUBSTRING(Courier_Code,1,4))+1),4)AS Courier_Code
            FROM Pos.MST_Courier)
SELECT @p_pcd=ISNULL(@p_pcd,'0001')
SET @P_RET_VALUE=@p_pcd


DECLARE @VAL INT
IF(@City_ID = -1)
BEGIN
INSERT into  City(State_ID,City_Name,Created_On,Is_Active,Is_Deleted)  VALUES(@State_ID,@CityName,GetDate(),1,0)
SET @VAL=SCOPE_IDENTITY()
INSERT INTO  MST_Courier
(Courier_Code,Courier_Name, Contact_Person_Name, Address,City_ID,State_ID,Country_ID,Mobile_No,Alternate_Mobile_No,Phone_No,Email_ID,Fax_No,Additional_Info1,Additional_Info2,Additional_Info3)
values(@P_RET_VALUE,@Courier_Name, @Contact_Person_Name,@Address,@VAL,@State_ID,@Country_ID,@Mobile_No,@Alternate_Mobile_No,@Phone_No,@Email_ID,@Fax_No,@Additional_Info1,@Additional_Info2,@Additional_Info3)

END
ELSE
BEGIN
INSERT INTO  MST_Courier
(Courier_Code,Courier_Name, Contact_Person_Name, Address,City_ID,State_ID,Country_ID,Mobile_No,Alternate_Mobile_No,Phone_No,Email_ID,Fax_No,Additional_Info1,Additional_Info2,Additional_Info3)
values(@P_RET_VALUE,@Courier_Name, @Contact_Person_Name,@Address,@City_ID,@State_ID,@Country_ID,@Mobile_No,@Alternate_Mobile_No,@Phone_No,@Email_ID,@Fax_No,@Additional_Info1,@Additional_Info2,@Additional_Info3)
END  

END
============================
Store Procedure Jeun Acchi @City_ID = -1 Taha front end re cs Page re Statically Set karajaichi ki je 
  dummy_.City_ID = -1;

Cristal Report In Dyanamically Method


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Swash.Objects;
using System.Data;
using System.Data.SqlClient;



  private void frmReportViewer_Load(object sender, EventArgs e)
        {

            TAGGING_CommonVariable objVar = new TAGGING_CommonVariable();
            objVar.servername = @"Satya\Linku";
            objVar.DatabaseName = "XXXXXX";
            objVar.username = "aaaa";
            objVar.password = "ddddd";

            if (reportFlag == 0)//IssueToQualityControl
            {
                crReportIssueToQC objCr = new crReportIssueToQC();
                CrystalDecisions.Shared.TableLogOnInfo tliCurrent = default(CrystalDecisions.Shared.TableLogOnInfo);
                try
                {
                    foreach (CrystalDecisions.CrystalReports.Engine.Table tbCurrent in objCr.Database.Tables)
                    {
                        tliCurrent = tbCurrent.LogOnInfo;
                        var _with1 = tliCurrent.ConnectionInfo;
                        _with1.ServerName = objVar.servername;
                        _with1.DatabaseName = objVar.DatabaseName;
                        _with1.UserID = objVar.username;
                        _with1.Password = objVar.password;
                        _with1.IntegratedSecurity = false;
                        tbCurrent.ApplyLogOnInfo(tliCurrent);
                    }

                    this.crystalReportViewerAll.ReportSource = objCr;
                    objCr.SetParameterValue(0, paramvalue);
                    //objCr.SetParameterValue(1, paramvalueId);
                    crystalReportViewerAll.Show();
                }
                catch
                {

                }
            }