// Error Handling Developed by Samad // 05/12/06 private string Get_ProductUnitCode(ProductUnitInfoDTO Obj) { string pucode = null; int pucodeno = 0; SqlConnection objmycon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objcmd = new SqlCommand(); objcmd.CommandText = "Select Isnull(Max(cast(PU_Code as int)),0 )+1 from ProductUnitInfo"; objcmd.Connection = objmycon; try { objmycon.Open(); pucodeno = (int)objcmd.ExecuteScalar(); } catch (Exception Exp) { throw Exp; } finally { objmycon.Close(); } pucode = pucodeno.ToString("00"); return(pucode); }
protected void btnAdd_Click(object sender, EventArgs e) { try { if (this.lblErrorMessage.Text.Length != 0) { this.lblErrorMessage.Text = ""; } if (this.txtPU_Name.Text.Length == 0) { this.lblErrorMessage.Text = "Unit Name field can not be blank. Please Insert"; txtPU_Name.Focus(); return; } ProductUnitInfoDTO pudto = Populate(); IProductUnitBL puFacade = Facade.GetInstance().GetPUBLImp(); puFacade.addNewProductUnit(pudto); this.lblErrorMessage.Text = "Data Save Successfully."; this.txtPU_PK.Value = ""; this.txtPU_Code.Text = ""; //this.txtPU_Code.Text = pudto.PU_Code; this.txtPU_Name.Text = ""; this.btnAdd.Text = "Save"; GridView1.DataBind(); } catch (Exception Exp) { lblErrorMessage.Text = cls.ErrorString(Exp); } }
public ArrayList GetData() { SqlConnection objMyCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objCom = new SqlCommand(); ArrayList subUnitList = new ArrayList(); objCom.Connection = objMyCon; objCom.CommandText = "SELECT PU_PK, PU_Code, PU_Name FROM ProductUnitInfo ORDER BY PU_Code"; try { objMyCon.Open(); SqlDataReader reader = objCom.ExecuteReader(); while (reader.Read()) { ProductUnitInfoDTO dto = Populate(reader); subUnitList.Add(dto); } reader.Close(); reader.Dispose(); } catch (Exception Exp) { throw Exp; } return(subUnitList); }
public override void Delete(object obj) { ProductUnitInfoDTO oProductUnitInfoDto = (ProductUnitInfoDTO)obj; SqlConnection objmycon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objcmd = new SqlCommand(); objcmd.CommandText = "Delete From ProductUnitInfo WHERE PU_PK=@PU_PK"; objcmd.Parameters.Add(new SqlParameter("@PU_PK", SqlDbType.UniqueIdentifier, 16)); objcmd.Parameters["@PU_PK"].Value = (Guid)oProductUnitInfoDto.PrimaryKey; objcmd.Connection = objmycon; try { objmycon.Open(); objcmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { objmycon.Close(); } }
public override void Save(object Obj) { ProductUnitInfoDTO puInfo = (ProductUnitInfoDTO)Obj; SqlConnection objmycon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objcmd = new SqlCommand(); if (puInfo.PrimaryKey.ToString() == "00000000-0000-0000-0000-000000000000") { puInfo.PU_Code = Get_ProductUnitCode(puInfo); objcmd.CommandText = "Insert Into ProductUnitInfo(PU_Code,PU_Name,EntryBy,EntryDate) Values(@PU_Code,@PU_Name,@EntryBy,@EntryDate)"; objcmd.Parameters.Add(new SqlParameter("@PU_Code", SqlDbType.VarChar, 2)); objcmd.Parameters.Add(new SqlParameter("@PU_Name", SqlDbType.VarChar, 50)); objcmd.Parameters.Add(new SqlParameter("@EntryBy", SqlDbType.VarChar, 5)); objcmd.Parameters.Add(new SqlParameter("@EntryDate", SqlDbType.DateTime, 8)); objcmd.Parameters["@PU_Code"].Value = (string)puInfo.PU_Code; objcmd.Parameters["@PU_Name"].Value = (string)puInfo.PU_Name; objcmd.Parameters["@EntryBy"].Value = (string)puInfo.EntryBy; objcmd.Parameters["@EntryDate"].Value = (DateTime)puInfo.EntryDate; } else { objcmd.CommandText = "Update ProductUnitInfo set PU_Name=@PU_Name where PU_PK=@PU_PK"; objcmd.Parameters.Add(new SqlParameter("@PU_PK", SqlDbType.UniqueIdentifier, 16)); objcmd.Parameters.Add(new SqlParameter("@PU_Name", SqlDbType.VarChar, 50)); objcmd.Parameters["@PU_PK"].Value = (Guid)puInfo.PrimaryKey; objcmd.Parameters["@PU_Name"].Value = (string)puInfo.PU_Name; } objcmd.Connection = objmycon; try { objmycon.Open(); objcmd.ExecuteNonQuery(); } catch (Exception Exp) { throw Exp; } finally { objmycon.Close(); } }
public ProductUnitInfoDTO Populate(SqlDataReader reader) { try { ProductUnitInfoDTO dto = new ProductUnitInfoDTO(); dto.PrimaryKey = (Guid)reader["PU_PK"]; dto.PU_Code = (string)reader["PU_Code"]; dto.PU_Name = (string)reader["PU_Name"]; dto.EntryBy = (string)reader["EntryBy"]; dto.EntryDate = (DateTime)reader["EntryDate"]; return(dto); } catch (Exception Exp) { throw Exp; } }
private ProductUnitInfoDTO Populate() { try { ProductUnitInfoDTO dto = new ProductUnitInfoDTO(); if (this.txtPU_PK.Value.ToString() != "") { dto.PrimaryKey = (Guid)TypeDescriptor.GetConverter(dto.PrimaryKey).ConvertFromString(this.txtPU_PK.Value); } dto.PU_Code = this.txtPU_Code.Text; dto.PU_Name = this.txtPU_Name.Text; dto.EntryBy = Constants.DEFULT_USER; dto.EntryDate = DateTime.Today; return(dto); } catch (Exception Exp) { throw Exp; } }
public ProductUnitInfoDTO FindByPK(Guid pk) { ProductUnitInfoDTO puDTO = new ProductUnitInfoDTO(); string sqlSelect = "SELECT PU_PK, PU_Code, PU_Name, EntryBy, EntryDate FROM ProductUnitInfo WHERE PU_PK=@PU_PK"; SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objCmd = sqlConn.CreateCommand(); try { objCmd.CommandText = sqlSelect; objCmd.Connection = sqlConn; objCmd.Parameters.Add("@PU_PK", SqlDbType.UniqueIdentifier, 16); objCmd.Parameters["@PU_PK"].Value = pk; sqlConn.Open(); SqlDataReader thisReader = objCmd.ExecuteReader(); while (thisReader.Read()) { puDTO = Populate(thisReader); } thisReader.Close(); thisReader.Dispose(); } catch (Exception Exp) { throw Exp; } finally { objCmd.Dispose(); objCmd.Cancel(); sqlConn.Dispose(); sqlConn.Close(); } return(puDTO); }
public List <ProductUnitInfoDTO> GetProductUnitInfo() { List <ProductUnitInfoDTO> productUnitList = new List <ProductUnitInfoDTO>(); SqlConnection objmycon = new SqlConnection(ConfigurationManager.ConnectionStrings["DPOSConnectionString"].ToString()); SqlCommand objcmd = new SqlCommand(); objcmd.Connection = objmycon; objcmd.CommandText = "SELECT PU_PK,PU_Code,PU_Name,EntryBy,EntryDate FROM ProductUnitInfo ORDER BY PU_Code"; try { objmycon.Open(); SqlDataReader thisReader = objcmd.ExecuteReader(); while (thisReader.Read()) { ProductUnitInfoDTO oProductUnitInfoDto = Populate(thisReader); productUnitList.Add(oProductUnitInfoDto); } thisReader.Close(); thisReader.Dispose(); } catch (Exception ex) { throw ex; } finally { objcmd.Dispose(); objcmd.Cancel(); } return(productUnitList); }
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); } }