Thursday 31 January 2013

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;

No comments:

Post a Comment