private void getPKCode(ProductCategoryInfoDTO obj) { SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); string strPKCode = null; int PKSL = 0; string sqlSelect = "Select isnull(Max(PC_Code),0)+1 From ProductCategoryInfo"; 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("00"); obj.PC_Code = strPKCode; }
public override void Delete(object obj) { ProductCategoryInfoDTO oProductCategoryInfoDTO = (ProductCategoryInfoDTO)obj; SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); String sql = "Delete ProductCategoryInfo where PC_PK=@PC_PK "; SqlCommand objCmdDelete = sqlConn.CreateCommand(); objCmdDelete.CommandText = sql; try { objCmdDelete.Parameters.Add("@PC_PK", SqlDbType.UniqueIdentifier, 16); objCmdDelete.Parameters["@PC_PK"].Value = (Guid)oProductCategoryInfoDTO.PrimaryKey; sqlConn.Open(); objCmdDelete.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { objCmdDelete.Dispose(); objCmdDelete.Cancel(); sqlConn.Dispose(); sqlConn.Close(); } }
public ProductCategoryInfoDTO Populate(SqlDataReader reader) { try { ProductCategoryInfoDTO dto = new ProductCategoryInfoDTO(); dto.PrimaryKey = (Guid)reader["PC_PK"]; dto.PC_Code = (string)reader["PC_Code"]; dto.PC_Description = (string)reader["PC_Description"]; dto.EntryBy = (string)reader["EntryBy"]; dto.EntryDate = (DateTime)reader["EntryDate"]; return(dto); } catch (Exception Exp) { throw Exp; } }
public ProductCategoryInfoDTO FindByPK(Guid pk) { ProductCategoryInfoDTO pcDTO = new ProductCategoryInfoDTO(); string sqlSelect = "SELECT PC_PK, PC_Code, PC_Description,EntryBy,EntryDate FROM ProductCategoryInfo WHERE PC_PK=@PC_PK"; SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objCmd = sqlConn.CreateCommand(); try { objCmd.CommandText = sqlSelect; objCmd.Connection = sqlConn; objCmd.Parameters.Add("@PC_PK", SqlDbType.UniqueIdentifier, 16); objCmd.Parameters["@PC_PK"].Value = pk; sqlConn.Open(); SqlDataReader thisReader = objCmd.ExecuteReader(); while (thisReader.Read()) { pcDTO = Populate(thisReader); } thisReader.Close(); thisReader.Dispose(); } catch (Exception Exp) { throw Exp; } finally { objCmd.Dispose(); objCmd.Cancel(); sqlConn.Dispose(); sqlConn.Close(); } return(pcDTO); }
public ProductCategoryInfoDTO populate() { try { ProductCategoryInfoDTO dto = new ProductCategoryInfoDTO(); // populate dto if (this.txtHideFieldPK.Value != "") { dto.PrimaryKey = (Guid)TypeDescriptor.GetConverter(dto.PrimaryKey).ConvertFromString(this.txtHideFieldPK.Value); } dto.PC_Description = this.txtCategoryDescription.Text; dto.EntryBy = "Admin"; dto.EntryDate = DateTime.Now.Date; return(dto); } catch (Exception Exp) { throw Exp; } }
protected void GridView1_RowEdting(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "Edit") { Facade facade = Facade.GetInstance(); int index = Convert.ToInt32(e.CommandArgument); ProductSubCategoryInfoDTO oProductSubCategoryInfoDTO = new ProductSubCategoryInfoDTO(); GridViewRow row = GridView1.Rows[index]; DataKey xx = this.GridView1.DataKeys[index]; this.txtHideFieldPK.Value = xx.Value.ToString(); oProductSubCategoryInfoDTO = facade.GetProductsubCategoryInfo((Guid)TypeDescriptor.GetConverter(oProductSubCategoryInfoDTO.PrimaryKey).ConvertFromString(this.txtHideFieldPK.Value)); this.txtPSCCode.Text = Server.HtmlDecode(row.Cells[2].Text); this.txtPSubCategoryDescription.Text = Server.HtmlDecode(row.Cells[3].Text); this.btnSave.Text = "Update"; ProductCategoryInfoDTO pcDto = new ProductCategoryInfoDTO(); pcDto = facade.GetProductCategoryInfo((Guid)oProductSubCategoryInfoDTO.PC_PK); this.ddlProductCategory.SelectedValue = pcDto.PrimaryKey.ToString(); //*********Modified by NERO. DDL Select Example. Req: SAMAD******************** //DropDownList1.SelectedItem.Selected = false; //DropDownList1.Items.FindByValue("000111-222556-3333-2222-222").Selected=true; //*********END EXAMPLE********************************************************* } } catch (Exception Exp) { lblErrorMessage.Text = cls.ErrorString(Exp); } }
public List <ProductCategoryInfoDTO> GetProductCategoryInfo() { List <ProductCategoryInfoDTO> productCategoriList = new List <ProductCategoryInfoDTO>(); SqlConnection objmycon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objcmd = new SqlCommand(); SqlDataReader DR; objcmd.Connection = objmycon; objcmd.CommandText = "SELECT PC_PK, PC_Code, PC_Description,EntryBy,EntryDate FROM ProductCategoryInfo ORDER BY PC_Code"; try { objmycon.Open(); DR = objcmd.ExecuteReader(); while (DR.Read()) { ProductCategoryInfoDTO ProcInfo = new ProductCategoryInfoDTO();//(Guid)DR[0],(string)DR[1],(string)DR[1]); ProcInfo.PrimaryKey = (Guid)DR[0]; ProcInfo.PC_Code = (string)DR[1]; ProcInfo.PC_Description = (string)DR[2]; productCategoriList.Add(ProcInfo); } DR.Close(); } catch (Exception Exp) { throw Exp; } finally { objmycon.Close(); } return(productCategoriList); }
protected void btnSave_Click(object sender, EventArgs e) { if (this.lblErrorMessage.Text.Length != 0) { this.lblErrorMessage.Text = ""; } ProductCategoryInfoDTO dto = populate(); Facade facade = Facade.GetInstance(); IProductCategoryBL oCategoryBL = facade.createProductCategoryBL(); try { oCategoryBL.addNewProduct(dto); // this.lblErrorMessage.Text = "Data Save Successfully."; //======================================================================= // btnSave.Attributes.Add("onclick", "test()"); //======================================================================= this.txtHideFieldPK.Value = ""; this.txtProductCategoryCode.Text = ""; this.txtCategoryDescription.Text = ""; this.btnSave.Text = "Save"; this.GridView1.DataBind(); this.lblErrorMessage.Text = "Data Save Successfully."; } catch (Exception Exp) { lblErrorMessage.Text = cls.ErrorString(Exp); } }
public override void Save(object obj) { ProductCategoryInfoDTO oProductCategoryInfoDTO = (ProductCategoryInfoDTO)obj; SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objCmd = sqlConn.CreateCommand(); if (oProductCategoryInfoDTO.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000") { String sql = "Insert Into ProductCategoryInfo(PC_Code,PC_Description,EntryBy,EntryDate) values(@PC_Code,@PC_Description,@EntryBy,@EntryDate)"; try { getPKCode(oProductCategoryInfoDTO); objCmd.CommandText = sql; objCmd.Parameters.Add(new SqlParameter("@PC_Code", SqlDbType.VarChar, 2)); objCmd.Parameters.Add(new SqlParameter("@PC_Description", SqlDbType.VarChar, 50)); objCmd.Parameters.Add(new SqlParameter("@EntryBy", SqlDbType.VarChar, 5)); objCmd.Parameters.Add(new SqlParameter("@EntryDate", SqlDbType.DateTime)); objCmd.Parameters["@PC_Code"].Value = Convert.ToString(oProductCategoryInfoDTO.PC_Code); objCmd.Parameters["@PC_Description"].Value = Convert.ToString(oProductCategoryInfoDTO.PC_Description); objCmd.Parameters["@EntryBy"].Value = Convert.ToString(oProductCategoryInfoDTO.EntryBy); objCmd.Parameters["@EntryDate"].Value = Convert.ToDateTime(oProductCategoryInfoDTO.EntryDate); sqlConn.Open(); objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { objCmd.Dispose(); objCmd.Cancel(); sqlConn.Close(); sqlConn.Dispose(); } } else { String sql = "Update ProductCategoryInfo set PC_Description=@PC_Description,EntryBy=@EntryBy,EntryDate=@EntryDate where PC_PK=@PC_PK "; try { objCmd.CommandText = sql; objCmd.Parameters.Add("@PC_Description", SqlDbType.VarChar, 50); objCmd.Parameters.Add("@EntryBy", SqlDbType.VarChar, 50); objCmd.Parameters.Add("@EntryDate", SqlDbType.DateTime); objCmd.Parameters.Add("@PC_PK", SqlDbType.UniqueIdentifier, 16); objCmd.Parameters["@PC_Description"].Value = Convert.ToString(oProductCategoryInfoDTO.PC_Description); objCmd.Parameters["@EntryBy"].Value = Convert.ToString(oProductCategoryInfoDTO.EntryBy); objCmd.Parameters["@EntryDate"].Value = Convert.ToDateTime(oProductCategoryInfoDTO.EntryDate); objCmd.Parameters["@PC_PK"].Value = (Guid)oProductCategoryInfoDTO.PrimaryKey; sqlConn.Open(); objCmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { objCmd.Dispose(); objCmd.Cancel(); sqlConn.Dispose(); sqlConn.Close(); } } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "Edit") { ProductInfoDTO pDto = new ProductInfoDTO(); int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView1.Rows[index]; DataKey dk = GridView1.DataKeys[index]; this.hfPrimaryKey.Value = dk.Value.ToString(); Facade facade = Facade.GetInstance(); DropDownListSubCategory(facade); pDto = facade.GetProductInfoDTO((Guid)TypeDescriptor.GetConverter(pDto.PrimaryKey).ConvertFromString(this.hfPrimaryKey.Value)); this.txtProductCode.Text = pDto.P_Code; this.txtProductName.Text = pDto.P_Name; this.txtStyle.Text = pDto.P_Style; this.txtSalesPrice.Text = pDto.P_SalesPrice.ToString(); this.txtCostPrice.Text = pDto.P_CostPrice.ToString(); this.txtTax.Text = pDto.P_Tax.ToString(); this.txtVat.Text = pDto.P_VAT.ToString(); this.txtDiscount.Text = pDto.P_Discount.ToString(); this.txtMinLevel.Text = pDto.P_MinLevel.ToString(); this.txtMaxLevel.Text = pDto.P_MaxLevel.ToString(); this.txtReorderLevel.Text = pDto.P_ReorderLevel.ToString(); this.chkStatus.Checked = pDto.P_Status; this.txtSalesPriceDate.Text = pDto.P_SalesPriceDate.ToString("MM/dd/yyyy"); this.txtCostPriceDate.Text = pDto.P_CostPriceDate.ToString("MM/dd/yyyy"); this.chkWarranty.Checked = pDto.P_Warranty; this.txtWarrantyMonth.Text = pDto.P_WarrantyMonth.ToString(); this.btnSave.Text = "Update"; ProductCategoryInfoDTO pcDto = new ProductCategoryInfoDTO(); pcDto = facade.GetProductCategoryInfo((Guid)pDto.PC_PrimaryKey); this.ddlProductCategory.SelectedValue = pcDto.PrimaryKey.ToString(); ProductSubCategoryInfoDTO pscDto = new ProductSubCategoryInfoDTO(); pscDto = facade.GetProductsubCategoryInfo((Guid)pDto.PSC_PrimaryKey); if (pscDto.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000") { this.ddlProductSubCategory.SelectedValue = ""; } else { this.ddlProductSubCategory.SelectedValue = pscDto.PrimaryKey.ToString(); } ProductBrandInfoDTO pbDto = new ProductBrandInfoDTO(); pbDto = facade.GetProductBrandInfo((Guid)pDto.PB_PrimaryKey); if (pbDto.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000") { this.ddlProductBrand.SelectedValue = ""; } else { this.ddlProductBrand.SelectedValue = pbDto.PrimaryKey.ToString(); } ProductUnitInfoDTO puDto = new ProductUnitInfoDTO(); puDto = facade.GetProductUnitInfo((Guid)pDto.PU_PrimaryKey); if (puDto.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000") { this.ddlProductUnit.SelectedValue = ""; } else { this.ddlProductUnit.SelectedValue = puDto.PrimaryKey.ToString(); } } } catch (Exception Exp) { lblErrorMessage.Text = cls.ErrorString(Exp); } }