private List <ProductCategoryDetail> Load(DataSet data) { List <ProductCategoryDetail> productCategoryDetails; ProductCategoryDetail productCategoryDetail; try { productCategoryDetails = new List <ProductCategoryDetail>(); foreach (DataRow row in data.Tables[0].Rows) { productCategoryDetail = new ProductCategoryDetail(); productCategoryDetail.ProductID = row.Field <long>("ProductID"); productCategoryDetail.CategoryDetailID = row.Field <int>("CategoryDetailID"); productCategoryDetails.Add(productCategoryDetail); } } catch (Exception ex) { throw ex; } return(productCategoryDetails); }
public JsonResult SaveProductCatData(ProductCategoryDetail productCategoryDetail) { var AllStatus = productCategoryData.AddProdCatgry(productCategoryDetail); return(new JsonResult { Data = AllStatus, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public bool Insert_Product_Category(long product_id, int category_id) { bool result = false; try { MoneyDataContext db = new MoneyDataContext(); ProductCategoryDetail prod = new ProductCategoryDetail { Product_Id = product_id, Category_Id = category_id }; db.ProductCategoryDetails.InsertOnSubmit(prod); db.SubmitChanges(); result = true; } catch (Exception ex) { } return(result); }
/// <summary> /// Adds the new type of the product category. /// </summary> /// <param name="productCategoryType">The model.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public long AddNewProductCategoryType(ProductCategoryType productCategoryType, string productIds = "") { try { var productCategoryTypeModel = context.ProductCategoryType.Where(x => x.CategoryType == productCategoryType.CategoryType && x.IsDelete == false).FirstOrDefault(); if (productCategoryTypeModel == null) { context.ProductCategoryType.Add(productCategoryType); context.SaveChanges(); if (!string.IsNullOrWhiteSpace(productIds)) { string[] splitProductIds = productIds.Split(','); if (splitProductIds != null && splitProductIds.Length > 0) { foreach (var item in splitProductIds) { if (!string.IsNullOrWhiteSpace(item)) { ProductCategoryDetail productCategoryDetail = new ProductCategoryDetail(); productCategoryDetail.ProductCategoryTypeFK = productCategoryType.ProductCategoryTypeId; productCategoryDetail.ProductFK = DBHelper.ParseInt64(item); context.ProductCategoryDetail.Add(productCategoryDetail); context.SaveChanges(); } } } } return(productCategoryType.ProductCategoryTypeId); } else { return(ReturnCode.AlreadyExist.GetHashCode()); } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); throw ex; } }
public List <dynamic> AddProdCatgry(ProductCategoryDetail productCategoryDetail) { List <dynamic> objDynamic = new List <dynamic>(); ProductCatgry productCatgry = new ProductCatgry(); ProdcatCust prodcatCust = new ProdcatCust(); int value = 0; switch (productCategoryDetail.Type) { case "1": { var Data = JsonConvert.DeserializeObject <List <ProductCatgry> >(productCategoryDetail.Productcategorydet); for (int i = 0; i < Data.Count; i++) { productCatgry = Data[i]; if (productCatgry.Ischange == 1) { if (!string.IsNullOrEmpty(UserID)) { productCatgry.UserId = Convert.ToInt64(UserID); } if (!string.IsNullOrEmpty(productCategoryDetail.CustID)) { productCatgry.CustID = Convert.ToInt64(productCategoryDetail.CustID); } if (productCatgry.IsDelete == true) { productCatgry.Type = 3; productCatgry.IsActive = false; } AddProductCategory(productCatgry); } } break; } case "2": { var Data = JsonConvert.DeserializeObject <List <ProdcatCust> >(productCategoryDetail.CustID); Int64 val = Int64.Parse(productCategoryDetail.CatID); for (int i = 0; i < Data.Count; i++) { ProdcatCust prodcatCustnew = new ProdcatCust(); prodcatCustnew = Data[i]; if (val != 0) { productCatgry.Type = 5; productCatgry.ProdCatId = val; } else { productCatgry.Type = 1; productCatgry.IsActive = true; } if (!string.IsNullOrEmpty(UserID)) { productCatgry.UserId = Convert.ToInt64(UserID); } productCatgry.IsActive = prodcatCustnew.IsCat; productCatgry.CustID = (prodcatCustnew.CustId); productCatgry.ProdCatDesc = productCategoryDetail.Productcategorydet; AddProductCategory(productCatgry); val = productCatgry.ProdCatId; if (productCatgry.count == -99) { value = productCatgry.count; } } break; } } DataSet ds = GetProductCatDetail(0, 2); List <ProductCatgry> prodCatmaster = (from item in ds.Tables[0].AsEnumerable() select new ProductCatgry { ProdCatId = item.Field <Int64>("ProdCatId"), ProdCatDesc = item.Field <String>("ProdCatDesc"), IsActive = item.Field <bool>("IsActive"), Type = 2, }).ToList(); objDynamic.Add(prodCatmaster); List <ProductCatgry> prodCat = (from item in ds.Tables[1].AsEnumerable() select new ProductCatgry { ProdCatId = item.Field <Int64>("ProdCatId"), ProdCatDesc = item.Field <String>("ProdCatDesc"), IsActive = item.Field <bool>("IsActive"), CustID = item.Field <Int64>("CustId"), }).ToList(); objDynamic.Add(prodCat); objDynamic.Add(value); return(objDynamic); }
public static ProductCategoryDetail ProductCategoryEdit(string id, int index) { // Set active row HttpContext.Current.Session["ROW_ID"] = id; HttpContext.Current.Session["ROW"] = index; var level = 0; var dataProductCate = (List <ProductCategoryDetail>)HttpContext.Current.Session["SESSION_PRODUCT_CATEGORY_LIST"]; if (dataProductCate != null) { level = (from t in dataProductCate where t.id == Convert.ToInt32(id) select t.level_no).FirstOrDefault(); } var callDataProductCate = new ProductCategoryDetail(); var dsDataProductCat = new DataSet(); try { using (SqlConnection conn = new SqlConnection(SPlanetUtil.GetConnectionString())) { List <SqlParameter> arrParm = new List <SqlParameter> { new SqlParameter("@search_name", SqlDbType.VarChar, 200) { Value = "" }, new SqlParameter("@id", SqlDbType.Int) { Value = id }, new SqlParameter("@parent_id", SqlDbType.Int) { Value = 0 }, new SqlParameter("@level_no", SqlDbType.Int) { Value = level } }; conn.Open(); dsDataProductCat = SqlHelper.ExecuteDataset(conn, "sp_product_category_list", arrParm.ToArray()); conn.Close(); } if (dsDataProductCat.Tables.Count > 0) { var row = dsDataProductCat.Tables[0].Rows[0]; callDataProductCate.id = Convert.IsDBNull(row["id"]) ? 0 : Convert.ToInt32(row["id"]);//returnData.id = ตัวแปรที่สร้างชี้ไปที่propetieที่สร้างตรงกับฟิวในตาราง, เอาข้อมูลจากtabelโดยเช็คค่าว่างของฟิว?ถ้าไม่ก็คอนเวิดฟิวเป็นint callDataProductCate.cat_type = Convert.IsDBNull(row["cat_type"]) ? null : Convert.ToString(row["cat_type"]); callDataProductCate.parent_id = Convert.IsDBNull(row["parent_id"]) ? 0 : Convert.ToInt32(row["parent_id"]); callDataProductCate.cat_name_tha = Convert.IsDBNull(row["cat_name_tha"]) ? null : Convert.ToString(row["cat_name_tha"]); callDataProductCate.cat_name_eng = Convert.IsDBNull(row["cat_name_eng"]) ? null : Convert.ToString(row["cat_name_eng"]); callDataProductCate.parent_root_id = Convert.IsDBNull(row["parent_root_id"]) ? 0 : Convert.ToInt32(row["parent_root_id"]); callDataProductCate.level_no = Convert.IsDBNull(row["level_no"]) ? 0 : Convert.ToInt32(row["level_no"]); } } catch (Exception ex) { throw ex; } return(callDataProductCate); }
public static ProductCategoryDetail addItemChild(string id) { var Data = new { level_no = 0, parent_id = 0 }; var dataProductCate = (List <ProductCategoryDetail>)HttpContext.Current.Session["SESSION_PRODUCT_CATEGORY_LIST"]; if (dataProductCate != null) { Data = (from t in dataProductCate where t.id == Convert.ToInt32(id) select new { level_no = t.level_no, parent_id = t.parent_id }).FirstOrDefault(); } //หาlevaelfrom SESSION_PRODUCT_CATEGORY_LIST var returnData = new ProductCategoryDetail(); //ตั้งตัวแปรชนิดเดียวกับคลาสที่สร้าง ตามฟิวในตาราง var dsProductCategory = new DataSet(); //ตั้งตัวแปรเพื่อใช่เก็บข้อมูลจากtabel try { using (SqlConnection conn = new SqlConnection(SPlanetUtil.GetConnectionString())) { List <SqlParameter> arrParm = new List <SqlParameter> { new SqlParameter("@search_name", SqlDbType.VarChar) { Value = " " }, new SqlParameter("@id", SqlDbType.Int) { Value = id }, new SqlParameter("@parent_id", SqlDbType.Int) { Value = Data.parent_id }, new SqlParameter("@level_no", SqlDbType.Int) { Value = Data.level_no } }; conn.Open(); dsProductCategory = SqlHelper.ExecuteDataset(conn, "sp_product_category_list", arrParm.ToArray()); conn.Close(); } if (dsProductCategory.Tables.Count > 0) //เช็คว่าdata null? { var row = dsProductCategory.Tables[0].Rows[0]; //สร้างตัวแปรมาโดยเรียกระบุจากtabelแรก,colแรก ชี้ตำแหน่งลงไป returnData.id = Convert.IsDBNull(row["id"]) ? 0 : Convert.ToInt32(row["id"]); //returnData.id = ตัวแปรที่สร้างชี้ไปที่propetieที่สร้างตรงกับฟิวในตาราง, เอาข้อมูลจากtabelโดยเช็คค่าว่างของฟิว?ถ้าไม่ก็คอนเวิดฟิวเป็นint returnData.cat_type = Convert.IsDBNull(row["cat_type"]) ? null : Convert.ToString(row["cat_type"]); returnData.parent_id = Convert.IsDBNull(row["parent_id"]) ? 0 : Convert.ToInt32(row["parent_id"]); returnData.parent_root_id = Convert.IsDBNull(row["parent_root_id"]) ? 0 : Convert.ToInt32(row["parent_root_id"]); returnData.cat_name_tha = Convert.IsDBNull(row["cat_name_tha"]) ? null : Convert.ToString(row["cat_name_tha"]); returnData.cat_name_eng = Convert.IsDBNull(row["cat_name_eng"]) ? null : Convert.ToString(row["cat_name_eng"]); returnData.level_no = Convert.IsDBNull(row["level_no"]) ? 0 : Convert.ToInt32(row["level_no"]); } } catch (Exception ex) { throw ex; } return(returnData); }
/// <summary> /// Updates the type of the product category. /// </summary> /// <param name="productCategoryType">The model.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public long UpdateProductCategoryType(ProductCategoryType productCategoryType, long updatedBy, string productIds = "") { try { var productCategoryTypeModelCheck = context.ProductCategoryType.Where(x => x.CategoryType == productCategoryType.CategoryType && x.IsDelete == false && x.ProductCategoryTypeId != productCategoryType.ProductCategoryTypeId).FirstOrDefault(); if (productCategoryTypeModelCheck == null) { var productCategoryTypeModel = context.ProductCategoryType.Where(x => x.ProductCategoryTypeId == productCategoryType.ProductCategoryTypeId && x.IsDelete == false).FirstOrDefault(); if (productCategoryTypeModel != null) { productCategoryTypeModel.ModifiedOn = DateTime.Now; productCategoryTypeModel.UpdatedBy = updatedBy; productCategoryTypeModel.CategoryType = productCategoryType.CategoryType; productCategoryTypeModel.Image = productCategoryType.Image; productCategoryTypeModel.Description = productCategoryType.Description; productCategoryTypeModel.IsShowInFrontend = productCategoryType.IsShowInFrontend; productCategoryTypeModel.ProductCategoryFK = productCategoryType.ProductCategoryFK; context.SaveChanges(); if (!string.IsNullOrWhiteSpace(productIds)) { var productCategory = context.ProductCategoryDetail.Where(x => x.ProductCategoryTypeFK == productCategoryTypeModel.ProductCategoryTypeId).ToList(); if (productCategory != null) { foreach (var item in productCategory) { context.ProductCategoryDetail.Remove(item); context.SaveChanges(); } } string[] splitProductIds = productIds.Split(','); if (splitProductIds != null && splitProductIds.Length > 0) { foreach (var item in splitProductIds) { if (!string.IsNullOrWhiteSpace(item)) { ProductCategoryDetail productCategoryDetail = new ProductCategoryDetail(); productCategoryDetail.ProductCategoryTypeFK = productCategoryType.ProductCategoryTypeId; productCategoryDetail.ProductFK = DBHelper.ParseInt64(item); context.ProductCategoryDetail.Add(productCategoryDetail); context.SaveChanges(); } } } } return(productCategoryTypeModel.ProductCategoryTypeId); } else { return(ReturnCode.NotExist.GetHashCode()); } } else { return(ReturnCode.AlreadyExist.GetHashCode()); } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); throw ex; } }