Tuesday 30 December 2014

dATA

bll


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using model;
using dal;

namespace bll
{
  public  class BLmanager
    {
      DalMAnager Ob = new DalMAnager();
      public Master Load(Master Obj,string Mode)
      {
          return Ob.lOAD(Obj, Mode);

      }
      public void sAVE(Master Obj, string Mode)
      {
          Ob.SAVE(Obj, Mode);

      }
    }
}
-------------------

DAL


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using model;
namespace dal
{
    public class DalMAnager
    {

        string con = ConfigurationManager.ConnectionStrings["ConStng"].ConnectionString;


        public void SAVE(Master Objcts, string Mode)
        {
            SqlConnection cong = new SqlConnection(con);
            Master OBJ = new Master();
            TableMngr obct = new TableMngr();
            try
            {
                cong.Open();
                foreach (TableMngr ob in Objcts.TBL)
                {
                    obct.Address = ob.Address;
                    obct.PlceData = new PlaceManager()
                    {
                        PlaceName = ob.PlceData.PlaceName
                    };
                    obct.Phone = ob.Phone;
                }


                SqlCommand cmd = new SqlCommand("Sp_Load", cong);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Mode", Mode);
                cmd.Parameters.AddWithValue("@Pid", null);
                cmd.Parameters.AddWithValue("@Address", obct.Address);
                cmd.Parameters.AddWithValue("@PlaceName", obct.PlceData.PlaceName);
                cmd.Parameters.AddWithValue("@Phone", obct.Phone);
                cmd.ExecuteNonQuery();
            }

            catch (Exception e)
            {
            }
            finally
            {
                cong.Close();
                cong.Dispose();
            }

        }



        public Master lOAD(Master Objcts, string Mode)
        {
            SqlConnection cong = new SqlConnection(con);
            Master OBJ = new Master();
            OBJ.TBL = new TableMngrColl();
            OBJ.PLCOLL = new PlaceMngrColl();
            try
            {
                cong.Open();
                SqlCommand cmd = new SqlCommand("Sp_Load", cong);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Mode", Mode);
                cmd.Parameters.AddWithValue("@Pid", Objcts.PlId);
                cmd.Parameters.AddWithValue("@Address", null);
                cmd.Parameters.AddWithValue("@PlaceName", null);
                cmd.Parameters.AddWithValue("@Phone", null);
                DataSet ds = new DataSet();
                SqlDataAdapter ad = new SqlDataAdapter();
                ad.SelectCommand = cmd;
                ad.Fill(ds);
                DataTable PlDt = new DataTable();
                DataTable Dtils = ds.Tables[0];
                if (Mode == "LO")
                {
                    PlDt = ds.Tables[1];

                    if (PlDt.Rows.Count > 0)
                    {
                        foreach (DataRow Object in PlDt.Rows)
                        {
                            OBJ.PLCOLL.Add(new PlaceManager()
                            {
                                PlceId = Convert.ToString(Object["pID"]),
                                PlaceName = Convert.ToString(Object["pNAME"]),
                            });
                        }
                    }
                }
                else if (Mode == "LG")
                {

                    if (Dtils.Rows.Count > 0)
                    {
                        foreach (DataRow Object in Dtils.Rows)
                        {
                            OBJ.TBL.Add(new TableMngr()
                            {
                                Address = Convert.ToString(Object["address"]),
                                Phone = Convert.ToString(Object["phone"]),
                                PlceData = new PlaceManager()
                                {
                                    PlaceName = Convert.ToString(Object["pID"])
                                }
                            });
                        }
                    }

                }

            }
            catch (Exception e)
            {
            }
            finally
            {
                cong.Close();
                cong.Dispose();
            }
            return OBJ;
        }
    }
}

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using model;
using bll;
public partial class _Default : System.Web.UI.Page
{
    string Mode = string.Empty;
    BLmanager ob = new BLmanager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadPlace();
        }
    }
    public void LoadPlace()
    {

        Master obj = new model.Master();
        obj.PlId = DropDownList1.SelectedValue;
        if (obj.PlId == "" || obj.PlId == null)
        {
            Mode = "LO";
            obj = ob.Load(obj, Mode);
            DropDownList1.DataSource = obj.PLCOLL;
            DropDownList1.DataTextField = "PlaceName";
            DropDownList1.DataValueField = "PlceId";
            DropDownList1.DataBind();
        }
        else
        {
            Mode = "LG";
            obj = ob.Load(obj, Mode);
            GridView1.DataSource = obj.TBL;
            GridView1.DataBind();
        }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadPlace();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        LoadPlace();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        e.Cancel = true;
        GridView1.EditIndex = -1;
        LoadPlace();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");
        TextBox txtAdd = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtAdd");
        TextBox txtPhone = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtPhone");
        Master obj = new model.Master();
        obj.TBL = new TableMngrColl();
        TableMngr Tm = new TableMngr();
        Tm.Address = txtAdd.Text;
        Tm.Phone = txtPhone.Text;
        Tm.PlceData = new PlaceManager()
        {
            PlaceName = txtName.Text
        };

        obj.TBL.Add(Tm);
        Mode = "UP";
       ob.sAVE(obj, Mode);
    }
}

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace model
{
   public class Master
    {
       public PlaceMngrColl PLCOLL { get; set; }
       public TableMngrColl TBL { get; set; }
       public string PlId { get; set; }
    } 
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace model
{
   public class PlaceManager
    {

        public string PlceId { get; set; }
        public string PlaceName { get; set; } 


    }
    public class PlaceMngrColl:System.Collections.ObjectModel.ObservableCollection<PlaceManager>
    {
    }
  
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace model
{
   public class TableMngr
    {

        public PlaceManager PlceData { get; set; }

        public string Address { get; set; }

        public string Phone { get; set; }

    }
    public class TableMngrColl : System.Collections.ObjectModel.ObservableCollection<TableMngr>
    {
    }
}

USE [fthrsoft]
GO
/****** Object:  StoredProcedure [dbo].[Sp_Load]    Script Date: 01/01/2005 00:22:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Sp_Load]

@Mode varchar(5),
@Pid int=null,
@Address varchar(50)=null,
@PlaceName varchar(50)=null,
@Phone varchar(50)=null
AS
BEGIN
   
    SET NOCOUNT ON;

IF(@Pid is null)
SELECT     PL.pID, PL.pNAME, DT.phone, DT.address
FROM         dbo.Tbl_Place AS PL INNER JOIN
dbo.[tbl-Details] AS DT ON PL.pID = DT.Pid
else
SELECT     PL.pID, PL.pNAME, DT.phone, DT.address
FROM         dbo.Tbl_Place AS PL INNER JOIN
dbo.[tbl-Details] AS DT ON PL.pID = DT.Pid
where PL.pID=@Pid

IF(@Mode='LO')
SELECT     pID, pNAME
FROM         dbo.Tbl_Place AS PL
END

IF @Mode='UP'
begin

update A set phone=@Phone,address=@Address
from [tbl-Details] as A
inner join Tbl_Place as B ON A.pID = B.Pid
WHERE A.pID=@PlaceName
end