public SupplierInfoDTO populate()
    {
        try
        {
            //string strPC_PK;
            SupplierInfoDTO dto = new SupplierInfoDTO();
            // populate dto


            if (this.txtHideFieldPK.Value != "")
            {
                dto.PrimaryKey = (Guid)TypeDescriptor.GetConverter(dto.PrimaryKey).ConvertFromString(this.txtHideFieldPK.Value);
            }

            dto.SupplierName   = this.txtSupplierName.Text;
            dto.ContractPerson = this.txtContractPerson.Text;
            dto.ShortName      = this.txtShortName.Text;
            dto.Address        = this.txtAddress.Text;
            dto.Phone          = this.txtPhone.Text;
            dto.Fax            = this.txtFax.Text;
            dto.Email          = this.txtEmail.Text;
            dto.WebAddress     = this.txtWebAddress.Text;
            dto.EntryBy        = "Admin";
            dto.EntryDate      = DateTime.Now.Date;

            return(dto);
        }
        catch (Exception Exp)
        {
            throw Exp;
        }
    }
        public SupplierInfoDTO populate(SqlDataReader reader)
        {
            try
            {
                SupplierInfoDTO dto = new SupplierInfoDTO();

                dto.PrimaryKey     = (Guid)reader["Sp_PK"];
                dto.SupplierCode   = (string)reader["SupplierCode"];
                dto.SupplierName   = (string)reader["SupplierName"];
                dto.ContractPerson = (string)reader["ContractPerson"];
                dto.ShortName      = (string)reader["ShortName"];
                dto.Address        = (string)reader["Address"];
                dto.Phone          = (string)reader["Phone"];
                dto.Fax            = (string)reader["Fax"];
                dto.Email          = (string)reader["Email"];
                dto.WebAddress     = (string)reader["WebAddress"];
                dto.EntryBy        = (string)reader["EntryBy"];
                dto.EntryDate      = (DateTime)reader["EntryDate"];

                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        /// <summary>
        /// set Sales Main information in Domain Class
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public PurchaseReturnMainDTO populate(SqlDataReader reader)
        {
            try
            {
                PurchaseReturnMainDTO dto = new PurchaseReturnMainDTO();
                PurchaseMainDTO       oPurchaseMainDTO = new PurchaseMainDTO();
                SupplierInfoDTO       oSupplierInfoDTO = new SupplierInfoDTO();

                oPurchaseMainDTO.PrimaryKey  = (Guid)reader["PU_PK"];
                oPurchaseMainDTO.GRN_No      = (string)reader["GRN_No"];
                oPurchaseMainDTO.GRNDate     = (DateTime)reader["GRNDate"];
                oPurchaseMainDTO.ReferenceNo = (string)reader["ReferenceNo"];
                oPurchaseMainDTO.Sp_PK       = (Guid)reader["Sp_PK"];
                oPurchaseMainDTO.TotalAmount = (decimal)reader["TotalAmount"];
                oPurchaseMainDTO.Discount    = (decimal)reader["Discount"];
                oPurchaseMainDTO.EntryBy     = (string)reader["EntryBy"];
                oPurchaseMainDTO.EntryDate   = (DateTime)reader["EntryDate"];
                dto.PurchaseMainDTO          = oPurchaseMainDTO;

                oSupplierInfoDTO.PrimaryKey   = (Guid)reader["Sp_PK"];
                oSupplierInfoDTO.SupplierCode = (string)reader["SupplierCode"];
                oSupplierInfoDTO.SupplierName = (string)reader["SupplierName"];
                oSupplierInfoDTO.Address      = (string)reader["Address"];

                dto.SupplierInfoDTO = oSupplierInfoDTO;

                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // Error Handling developed by Samad
        // 05/12/06

        private void getPKCode(SupplierInfoDTO obj)
        {
            SqlConnection sqlConn   = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString());
            string        strPKCode = null;
            int           PKSL      = 0;

            string sqlSelect = "Select isnull(Max(SupplierCode),0)+1 From SupplierInfo";

            SqlCommand objCmd = sqlConn.CreateCommand();

            objCmd.CommandText = sqlSelect;

            try
            {
                sqlConn.Open();
                PKSL = (int)objCmd.ExecuteScalar();
            }
            catch (Exception Exp)
            {
                throw Exp;
            }
            finally
            {
                objCmd.Dispose();
                objCmd.Cancel();
                sqlConn.Dispose();
                sqlConn.Close();
            }

            strPKCode        = PKSL.ToString("000000");
            obj.SupplierCode = strPKCode;
            //return strPKCode;
        }
        public override void Delete(object obj)
        {
            SupplierInfoDTO oSupplierInfoDTO = (SupplierInfoDTO)obj;

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString());

            String sql = "Delete  SupplierInfo where Sp_PK=@Sp_PK";

            SqlCommand objCmdDelete = sqlConn.CreateCommand();

            objCmdDelete.CommandText = sql;

            try
            {
                objCmdDelete.Parameters.Add("@Sp_PK", SqlDbType.UniqueIdentifier, 16);

                objCmdDelete.Parameters["@Sp_PK"].Value = (Guid)oSupplierInfoDTO.PrimaryKey;

                sqlConn.Open();
                objCmdDelete.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objCmdDelete.Dispose();
                objCmdDelete.Cancel();
                sqlConn.Dispose();
                sqlConn.Close();
            }
        }
        public SupplierInfoDTO GetSupplierInfoBYCode(string strCode)
        {
            SupplierInfoDTO oSupplierInfoDTO = new SupplierInfoDTO();
            //oSupplierInfoDTO.PrimaryKey = pk;

            string sqlSelect = "Select Sp_PK,SupplierCode,SupplierName,ContractPerson,ShortName,Address,Phone,Fax,Email,WebAddress,EntryBy,EntryDate From SupplierInfo where SupplierCode=@SupplierCode";

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString());

            SqlCommand objCmd = sqlConn.CreateCommand();

            objCmd.CommandText = sqlSelect;
            objCmd.Connection  = sqlConn;


            try
            {
                objCmd.Parameters.Add(new SqlParameter("@SupplierCode", SqlDbType.VarChar, 6));

                objCmd.Parameters["@SupplierCode"].Value = strCode;

                sqlConn.Open();
                SqlDataReader thisReader = objCmd.ExecuteReader();

                while (thisReader.Read())
                {
                    oSupplierInfoDTO = populate(thisReader);
                }

                thisReader.Close();
                thisReader.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                objCmd.Dispose();
                objCmd.Cancel();
                sqlConn.Dispose();
                sqlConn.Close();
            }
            return(oSupplierInfoDTO);
        }
        public List <SupplierInfoDTO> getSupplierInfoData()
        {
            string sqlSelect = "Select Sp_PK,SupplierCode,SupplierName,ContractPerson,ShortName,Address,Phone,Fax,Email,WebAddress,EntryBy,EntryDate From SupplierInfo order by SupplierCode DESC";

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString());

            List <SupplierInfoDTO> oArrayList = new List <SupplierInfoDTO>();

            SqlCommand objCmd = sqlConn.CreateCommand();

            objCmd.CommandText = sqlSelect;
            objCmd.Connection  = sqlConn;

            try
            {
                sqlConn.Open();
                SqlDataReader thisReader = objCmd.ExecuteReader();

                while (thisReader.Read())
                {
                    SupplierInfoDTO oSupplierInfoDTO = populate(thisReader);
                    oArrayList.Add(oSupplierInfoDTO);
                }

                thisReader.Close();
                thisReader.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                objCmd.Dispose();
                objCmd.Cancel();
                sqlConn.Dispose();
                sqlConn.Close();
            }

            return(oArrayList);
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.lblErrorMessage.Text.Length != 0)
            {
                this.lblErrorMessage.Text = "";
            }

            SupplierInfoDTO dto = populate();

            Facade          facade           = Facade.GetInstance();
            ISupplierInfoBL oISupplierInfoBL = facade.createSupplierBL();
            oISupplierInfoBL.addNewSupplierRecord(dto);

            this.lblErrorMessage.Text = "Data Save Successfully.";

            this.txtHideFieldPK.Value   = "";
            this.txtSupplierCode.Text   = "";
            this.txtSupplierName.Text   = "";
            this.txtShortName.Text      = "";
            this.txtPhone.Text          = "";
            this.txtFax.Text            = "";
            this.txtEmail.Text          = "";
            this.txtContractPerson.Text = "";
            this.txtAddress.Text        = "";
            this.txtWebAddress.Text     = "";
            this.btnSave.Text           = "Save";

            this.GridView1.DataBind();
        }
        catch (Exception Exp)
        {
            lblErrorMessage.Text = cls.ErrorString(Exp);
        }
    }
    protected void GridView1_RowEdting(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Edit")
            {
                SupplierInfoDTO oSupplierInfoDTO = new SupplierInfoDTO();

                int index = Convert.ToInt32(e.CommandArgument);

                GridViewRow row = GridView1.Rows[index];
                this.txtSupplierName.Text = Server.HtmlDecode(row.Cells[2].Text);

                DataKey xx = this.GridView1.DataKeys[index];
                this.txtHideFieldPK.Value = xx.Value.ToString();

                Facade facade = Facade.GetInstance();
                oSupplierInfoDTO = facade.getSupplierInfo((Guid)TypeDescriptor.GetConverter(oSupplierInfoDTO.PrimaryKey).ConvertFromString(this.txtHideFieldPK.Value));

                txtSupplierCode.Text   = oSupplierInfoDTO.SupplierCode;
                txtSupplierName.Text   = oSupplierInfoDTO.SupplierName;
                txtContractPerson.Text = oSupplierInfoDTO.ContractPerson;
                txtShortName.Text      = oSupplierInfoDTO.ShortName;
                txtAddress.Text        = oSupplierInfoDTO.Address;
                txtPhone.Text          = oSupplierInfoDTO.Phone;
                txtFax.Text            = oSupplierInfoDTO.Fax;
                txtEmail.Text          = oSupplierInfoDTO.Email;
                txtWebAddress.Text     = oSupplierInfoDTO.WebAddress;
                this.btnSave.Text      = "Update";
            }
        }
        catch (Exception Exp)
        {
            lblErrorMessage.Text = cls.ErrorString(Exp);
        }
    }
        public override void Save(object obj)
        {
            SupplierInfoDTO oSupplierInfoDTO = (SupplierInfoDTO)obj;

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString());
            SqlCommand    objCmd  = sqlConn.CreateCommand();

            if (oSupplierInfoDTO.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000")
            {
                //string strset = getPKCode(oProductCategoryInfoDTO);
                String sql = "Insert Into SupplierInfo(SupplierCode,SupplierName,ContractPerson,ShortName,Address,Phone,Fax,Email,WebAddress,EntryBy,EntryDate) values(@SupplierCode,@SupplierName,@ContractPerson,@ShortName,@Address,@Phone,@Fax,@Email,@WebAddress,@EntryBy,@EntryDate)";


                try
                {
                    getPKCode(oSupplierInfoDTO);

                    objCmd.CommandText = sql;

                    objCmd.Parameters.Add(new SqlParameter("@SupplierCode", SqlDbType.VarChar, 6));
                    objCmd.Parameters.Add(new SqlParameter("@SupplierName", SqlDbType.VarChar, 100));
                    objCmd.Parameters.Add(new SqlParameter("@ContractPerson", SqlDbType.VarChar, 50));
                    objCmd.Parameters.Add(new SqlParameter("@ShortName", SqlDbType.VarChar, 25));
                    objCmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.VarChar, 150));
                    objCmd.Parameters.Add(new SqlParameter("@Phone", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@Fax", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@WebAddress", SqlDbType.VarChar, 20));
                    objCmd.Parameters.Add(new SqlParameter("@EntryBy", SqlDbType.VarChar, 5));
                    objCmd.Parameters.Add(new SqlParameter("@EntryDate", SqlDbType.DateTime));

                    objCmd.Parameters["@SupplierCode"].Value   = Convert.ToString(oSupplierInfoDTO.SupplierCode);
                    objCmd.Parameters["@SupplierName"].Value   = Convert.ToString(oSupplierInfoDTO.SupplierName);
                    objCmd.Parameters["@ContractPerson"].Value = Convert.ToString(oSupplierInfoDTO.ContractPerson);
                    objCmd.Parameters["@ShortName"].Value      = Convert.ToString(oSupplierInfoDTO.ShortName);
                    objCmd.Parameters["@Address"].Value        = Convert.ToString(oSupplierInfoDTO.Address);
                    objCmd.Parameters["@Phone"].Value          = Convert.ToString(oSupplierInfoDTO.Phone);
                    objCmd.Parameters["@Fax"].Value            = Convert.ToString(oSupplierInfoDTO.Fax);
                    objCmd.Parameters["@Email"].Value          = Convert.ToString(oSupplierInfoDTO.Email);
                    objCmd.Parameters["@WebAddress"].Value     = Convert.ToString(oSupplierInfoDTO.WebAddress);
                    objCmd.Parameters["@EntryBy"].Value        = Convert.ToString(oSupplierInfoDTO.EntryBy);
                    objCmd.Parameters["@EntryDate"].Value      = Convert.ToDateTime(oSupplierInfoDTO.EntryDate);

                    sqlConn.Open();
                    objCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    objCmd.Dispose();
                    objCmd.Cancel();
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            else
            {
                String sql = "Update  SupplierInfo set SupplierName=@SupplierName,ContractPerson=@ContractPerson,ShortName=@ShortName,Address=@Address,Phone=@Phone,Fax=@Fax,Email=@Email,WebAddress=@WebAddress,EntryBy=@EntryBy,EntryDate=@EntryDate where Sp_PK=@Sp_PK";

                //objCmd = new SqlCommand(sql, getCurrentConnection(), getCurrentTransaction()); ;

                try
                {
                    objCmd.CommandText = sql;

                    objCmd.Parameters.Add(new SqlParameter("@Sp_PK", SqlDbType.UniqueIdentifier, 16));
                    //objCmd.Parameters.Add(new SqlParameter("@SupplierCode", SqlDbType.VarChar, 6));
                    objCmd.Parameters.Add(new SqlParameter("@SupplierName", SqlDbType.VarChar, 100));
                    objCmd.Parameters.Add(new SqlParameter("@ContractPerson", SqlDbType.VarChar, 50));
                    objCmd.Parameters.Add(new SqlParameter("@ShortName", SqlDbType.VarChar, 25));
                    objCmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.VarChar, 150));
                    objCmd.Parameters.Add(new SqlParameter("@Phone", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@Fax", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar, 30));
                    objCmd.Parameters.Add(new SqlParameter("@WebAddress", SqlDbType.VarChar, 20));
                    objCmd.Parameters.Add(new SqlParameter("@EntryBy", SqlDbType.VarChar, 5));
                    objCmd.Parameters.Add(new SqlParameter("@EntryDate", SqlDbType.DateTime));

                    objCmd.Parameters["@Sp_PK"].Value = (Guid)oSupplierInfoDTO.PrimaryKey;
                    //objCmd.Parameters["@SupplierCode"].Value = Convert.ToString(oSupplierInfoDTO.SupplierCode);
                    objCmd.Parameters["@SupplierName"].Value   = Convert.ToString(oSupplierInfoDTO.SupplierName);
                    objCmd.Parameters["@ContractPerson"].Value = Convert.ToString(oSupplierInfoDTO.ContractPerson);
                    objCmd.Parameters["@ShortName"].Value      = Convert.ToString(oSupplierInfoDTO.ShortName);
                    objCmd.Parameters["@Address"].Value        = Convert.ToString(oSupplierInfoDTO.Address);
                    objCmd.Parameters["@Phone"].Value          = Convert.ToString(oSupplierInfoDTO.Phone);
                    objCmd.Parameters["@Fax"].Value            = Convert.ToString(oSupplierInfoDTO.Fax);
                    objCmd.Parameters["@Email"].Value          = Convert.ToString(oSupplierInfoDTO.Email);
                    objCmd.Parameters["@WebAddress"].Value     = Convert.ToString(oSupplierInfoDTO.WebAddress);
                    objCmd.Parameters["@EntryBy"].Value        = Convert.ToString(oSupplierInfoDTO.EntryBy);
                    objCmd.Parameters["@EntryDate"].Value      = Convert.ToDateTime(oSupplierInfoDTO.EntryDate);

                    sqlConn.Open();
                    objCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    objCmd.Dispose();
                    objCmd.Cancel();
                    sqlConn.Dispose();
                    sqlConn.Close();
                }
            }
        }