private void LoadControls(SqlInt32 DistributorID)
    {
        DistributorENT entDistributor = new DistributorENT();
        DistributorBAL balDistributor = new DistributorBAL();

        entDistributor = balDistributor.SelectByPK(DistributorID);

        if (!entDistributor.BranchID.IsNull)
        {
            ddlBranchID.SelectedValue = entDistributor.BranchID.Value.ToString();
        }

        if (!entDistributor.DistributorName.IsNull)
        {
            txtDistributorName.Text = entDistributor.DistributorName.Value.ToString();
        }

        if (!entDistributor.MobileNo.IsNull)
        {
            txtMobileNo.Text = entDistributor.MobileNo.Value.ToString();
        }

        if (!entDistributor.VehicleType.IsNull)
        {
            txtVehicleType.Text = entDistributor.VehicleType.Value.ToString();
        }

        if (!entDistributor.VehicleNo.IsNull)
        {
            txtVehicleNo.Text = entDistributor.VehicleNo.Value.ToString();
        }
    }
Esempio n. 2
0
        public Boolean Update(DistributorENT entDistributor)
        {
            DistributorDAL distributorDAL = new DistributorDAL();

            if (distributorDAL.Update(entDistributor))
            {
                return(true);
            }
            else
            {
                this.Message = distributorDAL.Message;
                return(false);
            }
        }
        public Boolean Update(DistributorENT entDistributor)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objCmd = objConn.CreateCommand())
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_Distributor_UpdateByPK";
                        objCmd.Parameters.AddWithValue("@DistributorID", entDistributor.DistributorID);
                        objCmd.Parameters.AddWithValue("@BranchID", entDistributor.BranchID);
                        objCmd.Parameters.AddWithValue("@DistributorName", entDistributor.DistributorName);
                        objCmd.Parameters.AddWithValue("@MobileNo", entDistributor.MobileNo);
                        objCmd.Parameters.AddWithValue("@VehicleType", entDistributor.VehicleType);
                        objCmd.Parameters.AddWithValue("@VehicleNo", entDistributor.VehicleNo);
                        objCmd.Parameters.AddWithValue("@UserID", entDistributor.UserID);
                        #endregion Prepare Command

                        objCmd.ExecuteNonQuery();

                        return(true);
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message.ToString();
                        return(false);
                    }
                catch (Exception ex)
                {
                    Message = ex.InnerException.Message.ToString();
                    return(false);
                }
                finally
                {
                    if (objConn.State == ConnectionState.Open)
                    {
                        objConn.Close();
                    }
                }
            }
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            #region Server Side Validation

            String strError = String.Empty;

            if (ddlBranchID.SelectedIndex == 0)
            {
                strError += "- Select Branch<br />";
            }

            if (txtDistributorName.Text.Trim() == String.Empty)
            {
                strError += "- Enter Distributor Name<br />";
            }

            if (txtMobileNo.Text.Trim() == String.Empty)
            {
                strError += "- Enter Mobile No<br />";
            }

            if (txtVehicleType.Text.Trim() == String.Empty)
            {
                strError += "- Enter Vehicle Type<br />";
            }

            if (txtVehicleNo.Text.Trim() == String.Empty)
            {
                strError += "- Enter Vehicle No<br />";
            }

            #endregion Server Side Validation

            DistributorENT entDistributor = new DistributorENT();
            DistributorBAL balDistributor = new DistributorBAL();

            #region Gather Data

            if (ddlBranchID.SelectedIndex > 0)
            {
                entDistributor.BranchID = Convert.ToInt32(ddlBranchID.SelectedValue);
            }

            if (txtDistributorName.Text.Trim() != String.Empty)
            {
                entDistributor.DistributorName = txtDistributorName.Text.Trim();
            }

            if (txtMobileNo.Text.Trim() != String.Empty)
            {
                entDistributor.MobileNo = txtMobileNo.Text.Trim();
            }

            if (txtVehicleType.Text.Trim() != String.Empty)
            {
                entDistributor.VehicleType = txtVehicleType.Text.Trim();
            }

            if (txtVehicleNo.Text.Trim() != String.Empty)
            {
                entDistributor.VehicleNo = txtVehicleNo.Text.Trim();
            }

            entDistributor.UserID = Convert.ToInt32(Session["UserID"]);

            if (Request.QueryString["DistributorID"] == null)
            {
                balDistributor.Insert(entDistributor);
                lblMessage.Text = "Data Inserted Successfully";
                ClearControls();
            }
            else
            {
                entDistributor.DistributorID = Convert.ToInt32(Request.QueryString["DistributorID"]);
                balDistributor.Update(entDistributor);
                Response.Redirect("~/AdminPanel/Distributor/DistributorList.aspx");
            }

            #endregion Gather Data
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = ex.Message.ToString();
        }
    }
        public DistributorENT SelectByPK(SqlInt32 DistributorID)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objcmd = objConn.CreateCommand())
                    try
                    {
                        #region Prepar Command

                        objcmd.CommandType = CommandType.StoredProcedure;
                        objcmd.CommandText = "PR_Distributor_SelectByPK";
                        objcmd.Parameters.AddWithValue("@DistributorID", DistributorID);

                        #endregion Prepar Command

                        #region ReadData and Set Controls

                        DistributorENT entDistributor = new DistributorENT();
                        using (SqlDataReader objSDR = objcmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["DistributorID"].Equals(DBNull.Value))
                                {
                                    entDistributor.DistributorID = Convert.ToInt32(objSDR["DistributorID"]);
                                }
                                if (!objSDR["BranchID"].Equals(DBNull.Value))
                                {
                                    entDistributor.BranchID = Convert.ToInt32(objSDR["BranchID"]);
                                }
                                if (!objSDR["DistributorName"].Equals(DBNull.Value))
                                {
                                    entDistributor.DistributorName = Convert.ToString(objSDR["DistributorName"]);
                                }
                                if (!objSDR["MobileNo"].Equals(DBNull.Value))
                                {
                                    entDistributor.MobileNo = Convert.ToString(objSDR["MobileNo"]);
                                }
                                if (!objSDR["VehicleType"].Equals(DBNull.Value))
                                {
                                    entDistributor.VehicleType = Convert.ToString(objSDR["VehicleType"]);
                                }
                                if (!objSDR["VehicleNo"].Equals(DBNull.Value))
                                {
                                    entDistributor.VehicleNo = Convert.ToString(objSDR["VehicleNo"]);
                                }
                                if (!objSDR["UserID"].Equals(DBNull.Value))
                                {
                                    entDistributor.UserID = Convert.ToInt32(objSDR["UserID"]);
                                }
                            }
                        }
                        return(entDistributor);

                        #endregion ReadData and Set Controls
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message.ToString();
                        return(null);
                    }
                catch (Exception ex)
                {
                    Message = ex.InnerException.Message.ToString();
                    return(null);
                }
                finally
                {
                    if (objConn.State == ConnectionState.Open)
                    {
                        objConn.Close();
                    }
                }
            }
        }