예제 #1
0
        public static bool Apply(
            this SqlTransaction transaction, string TRANSACTION_NAME, MessageString errorMsg)
        {
            bool result = false;

            try
            {
                transaction.Commit();
                result = true;
            }
            catch (Exception ex)
            {
                errorMsg.Append(ex.ToString());
                try
                {
                    if (SString.IsNotNone(TRANSACTION_NAME))
                    {
                        transaction.Rollback(TRANSACTION_NAME);
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }
                catch (Exception)
                {
                    errorMsg.Append(ex.ToString());
                }
            }
            return(result);
        }
예제 #2
0
        public void StringBadChildren()
        {
            SExpression str = new SString("test");

            str.AddChild(new SString("testSub"));
            Parser.parse(str);
        }
예제 #3
0
        public static bool Apply(
            this SqlTransaction transaction, string TRANSACTION_NAME, out string errorMsg)
        {
            errorMsg = string.Empty;
            bool result = false;

            try
            {
                transaction.Commit();
                result = true;
            }
            catch (Exception ex)
            {
                errorMsg = ex.ToString();
                try
                {
                    if (SString.IsNotNone(TRANSACTION_NAME))
                    {
                        transaction.Rollback(TRANSACTION_NAME);
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }
                catch (Exception)
                {
                    errorMsg = $"{errorMsg}{ex.ToString()}";
                }
            }
            return(result);
        }
예제 #4
0
        public ActionResult detail(int id)
        {
            try
            {
                Product product = productService.GetByPrimaryKey(id);
                if (product != null)
                {
                    product.Variants = variantService.GetByProductID(product.ProductID);
                    product.Images   = imageService.GetByProductID(product.ProductID);
                    product.Options  = optionService.GetByProductID(product.ProductID);
                    if (product.Options != null && product.Options.Count > 0)
                    {
                        foreach (var item in product.Options)
                        {
                            if (!string.IsNullOrEmpty(item.OptionValue))
                            {
                                if (item.OptionName != "Title" && item.OptionValue != "DefaultTitle")
                                {
                                    item.OptionValues = (SString.RemoveElementAtBeginEnd(item.OptionValue, ",")).Split(',').ToList <string>();
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(product.Tags))
                    {
                        List <string> listTag = (SString.RemoveElementAtBeginEnd(product.Tags, ",")).Split(',').ToList <string>();
                        foreach (var item in listTag)
                        {
                            product.ListTag.Add(new Tag
                            {
                                TagName = item
                            });
                        }
                    }

                    string where             = string.Format("SupplierID={0} and ProductStyleID={1} and ProductID <>{2}", product.SupplierID, product.ProductStyleID, product.ProductID);
                    product.ProductsRelation = productService.GetByWhere(where);
                    if (product.ProductsRelation != null && product.ProductsRelation.Count > 0)
                    {
                        foreach (var item in product.ProductsRelation)
                        {
                            item.Variants = variantService.GetByProductID(item.ProductID);
                            item.Images   = imageService.GetByProductID(item.ProductID);
                        }
                    }
                    return(View(product));
                }

                return(RedirectToAction("grid"));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                throw;
            }
        }
예제 #5
0
        public void SStringTranslateTest()
        {
            var processor = ScriptProcessorFactory.GetNew();

            SString testString = processor.CreateString("this is a test string!");

            var obj = ScriptOutAdapter.Translate(testString);

            Assert.IsTrue(obj.GetType() == typeof(string));
            Assert.IsTrue((string)obj == testString.Value);
        }
예제 #6
0
    protected override void Read()
    {
        Type t = this.GetType();

        FieldInfo[] infos = t.GetFields();
        SBase       tmp   = null;

        for (int i = 0; i < infos.Length; i++)
        {
            FieldInfo fi = infos[i];

            if (fi.FieldType == typeof(SInt))
            {
                tmp = new SInt();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SInt).Def = ca.intv;
                }
            }
            else if (fi.FieldType == typeof(SFloat))
            {
                tmp = new SFloat();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SFloat).Def = ca.floatv;
                }
            }
            else if (fi.FieldType == typeof(SString))
            {
                tmp = new SString();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SString).Def = ca.stringv;
                }
            }
            else if (IsBaseType(fi.FieldType, typeof(SBase)))
            {
                tmp = Activator.CreateInstance(fi.FieldType) as SBase;
            }
            else
            {
                Debug.LogError(string.Format("{0} no suppot!", fi.Name));
                continue;
            }
            tmp.Init(sb, string.Format(ConnctFormat, key, fi.Name));
            fi.SetValue(this, tmp);
        }
    }
예제 #7
0
        private async Task <SData> ConvertToSDataAsync(JToken value, SDataType dataType)
        {
            SData result = null;

            try
            {
                switch (dataType)
                {
                case SDataType.Bool:
                    result = new SBool(value.Value <bool>());
                    break;

                case SDataType.DateTime:
                    result = new SDateTime(value.Value <DateTime>());
                    break;

                case SDataType.Duration:
                    result = new SDuration(value.Value <string>());
                    break;

                case SDataType.Number:
                    result = new SNumber(value.Value <double>());
                    break;

                case SDataType.NumberList:
                    result = new SNumberList(value.Select(i => i.Value <double>()).ToList());
                    break;

                case SDataType.String:
                    result = new SString(value.Value <string>());
                    break;

                case SDataType.StringDict:
                    result = new SStringDict(value.ToDictionary(i => ((JProperty)i).Name, i => ((JProperty)i).Value.Value <string>()));
                    break;

                case SDataType.StringList:
                    result = new SStringList(value.Select(i => i.Value <string>()).ToList());
                    break;
                }
            }
            catch (Exception e)
            {
                throw new EvalException($"Cannot convert {value.ToString()} to data type {dataType.ToString()}.", e);
            }

            return(await Task.FromResult(result));
        }
예제 #8
0
        public static string GetUsername(int id)
        {
            IDbConnection connectDB = new SqlConnection(Common.ConnectString);

            try
            {
                string query    = "select Username from AppUsers where Id = " + id;
                string username = connectDB.Query <string>(query).FirstOrDefault();
                return(SString.ConverToString(username));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return("");
            }
        }
예제 #9
0
        /// <summary>
        /// create new cookie and return cookie id of cart new or return cookie id of cart exist
        /// </summary>
        /// <returns></returns>
        public string retrieveCookie()
        {
            try
            {
                HttpCookie myCookie = Request.Cookies[Common.CookieCart];
                if (myCookie != null)
                {
                    return(myCookie.Value);
                }

                string     cookieID     = SString.RandomString(32);
                HttpCookie cookieObject = new HttpCookie(Common.CookieCart, cookieID);
                cookieObject.Expires = DateTime.Now.AddDays(14);
                Response.Cookies.Add(cookieObject);
                return(cookieID);
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                throw;
            }
        }
예제 #10
0
        public string GetValueLink2ObjectID(int tableNameID, int actionID, int objectID, string objectValue)
        {
            try
            {
                string value = "";
                if (actionID == (int)Common.ActionID.Delete)
                {
                    return(objectValue);
                }

                if (tableNameID == (int)Common.TableName.Account)
                {
                    var temp = appUserService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.Username;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Collection)
                {
                    var temp = collectionService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.CollectionName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Customer)
                {
                    var temp = customerService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.CustomerFirstName + " " + temp.CustomerLastName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Product)
                {
                    var temp = productService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.ProductName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.TblOrder)
                {
                    var temp = tblOrderService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = "#" + SString.ConverToString(Common.BaseNumberOrder + temp.Number);
                        return(value);
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(objectValue);
            }
            return(objectValue);
        }
예제 #11
0
 public static SString MaxSString(SString x, SString y) => x.Value > y.Value ? x : y;
예제 #12
0
		protected SNode ParseOne()
		{
			EStreamCode check;
			byte isshared = 0;
			SNode thisobj = null;
			SDBRow lastDbRow = null;

			try
			{
				byte type = Reader.ReadByte();
				check = (EStreamCode)(type & 0x3f);
				isshared = (byte)(type & 0x40);
			}
			catch (EndOfFileException)
			{
				return null;
			}

			#region EStreamCode Switch
			switch (check)
			{
				case EStreamCode.EStreamStart:
					break;
				case EStreamCode.ENone:
					thisobj = new SNone();
					break;
				case EStreamCode.EString:
					thisobj = new SString(Reader.ReadString(Reader.ReadByte()));
					break;
				case EStreamCode.ELong:
					thisobj = new SLong(Reader.ReadLong());
					break;
				case EStreamCode.EInteger:
					thisobj = new SInt(Reader.ReadInt());
					break;
				case EStreamCode.EShort:
					thisobj = new SInt(Reader.ReadShort());
					break;
				case EStreamCode.EByte:
					thisobj = new SInt(Reader.ReadByte());
					break;
				case EStreamCode.ENeg1Integer:
					thisobj = new SInt(-1);
					break;
				case EStreamCode.E0Integer:
					thisobj = new SInt(0);
					break;
				case EStreamCode.E1Integer:
					thisobj = new SInt(1);
					break;
				case EStreamCode.EReal:
					thisobj = new SReal(Reader.ReadDouble());
					break;
				case EStreamCode.E0Real:
					thisobj = new SReal(0);
					break;
				case EStreamCode.E0String:
					thisobj = new SString(null);
					break;
				case EStreamCode.EString3:
					thisobj = new SString(Reader.ReadString(1));
					break;
				case EStreamCode.EString4:
					goto case EStreamCode.EString;
				case EStreamCode.EMarker:
					thisobj = new SMarker((byte)GetLength());
					break;
				case EStreamCode.EUnicodeString:
					goto case EStreamCode.EString;
				case EStreamCode.EIdent:
					thisobj = new SIdent(Reader.ReadString(GetLength()));
					break;
				case EStreamCode.ETuple:
					{
						int length = GetLength();
						thisobj = new STuple((uint)length);
						Parse(thisobj, length);
						break;
					}
				case EStreamCode.ETuple2:
					goto case EStreamCode.ETuple;
				case EStreamCode.EDict:
					{
						int len = (GetLength() * 2);
						SDict dict = new SDict((uint)len);
						thisobj = dict;
						Parse(dict, len);
						break;
					}
				case EStreamCode.EObject:
					thisobj = new SObject();
					Parse(thisobj, 2);
					break;
				case EStreamCode.ESharedObj:
					thisobj = ShareGet(GetLength());
					break;
				case EStreamCode.EChecksum:
					thisobj = new SString("checksum");
					Reader.ReadInt();
					break;
				case EStreamCode.EBoolTrue:
					thisobj = new SInt(1);
					break;
				case EStreamCode.EBoolFalse:
					thisobj = new SInt(0);
					break;
				case EStreamCode.EObject22:
					{
						SObject obj = new SObject();
						thisobj = obj;
						Parse(thisobj, 1);

						string oclass = obj.Name;
						if (oclass == "dbutil.RowList")
						{
							SNode row;
							while ((row = ParseOne()) != null)
								obj.AddMember(row);
						}
						break;
					}
				case EStreamCode.EObject23:
					goto case EStreamCode.EObject22;
				case EStreamCode.E0Tuple:
					thisobj = new STuple(0);
					break;
				case EStreamCode.E1Tuple:
					thisobj = new STuple(1);
					Parse(thisobj, 1);
					break;
				case EStreamCode.E0Tuple2:
					goto case EStreamCode.E0Tuple;
				case EStreamCode.E1Tuple2:
					goto case EStreamCode.E1Tuple;
				case EStreamCode.EEmptyString:
					thisobj = new SString(string.Empty);
					break;
				case EStreamCode.EUnicodeString2:
					/* Single unicode character */
					thisobj = new SString(Reader.ReadString(2));
					break;
				case EStreamCode.ECompressedRow:
					thisobj = GetDBRow();
					break;
				case EStreamCode.ESubstream:
					{
						int len = GetLength();
						CacheFileReader readerSub = new CacheFileReader(Reader, len);
						SSubStream ss = new SSubStream(len);
						thisobj = ss;
						CacheFileParser sp = new CacheFileParser(readerSub);
						sp.Parse();
						for (int i = 0; i < sp.Streams.Count; i++)
							ss.AddMember(sp.Streams[i].Clone());

						Reader.Seek(readerSub.Position, SeekOrigin.Begin);
						break;
					}
				case EStreamCode.E2Tuple:
					thisobj = new STuple(2);
					Parse(thisobj, 2);
					break;
				case EStreamCode.EString2:
					goto case EStreamCode.EString;
				case EStreamCode.ESizedInt:
					switch (Reader.ReadByte())
					{
						case 8:
							thisobj = new SLong(Reader.ReadLong());
							break;
						case 4:
							thisobj = new SInt(Reader.ReadInt());
							break;
						case 3:
							// The following seems more correct than the forumla used.
							// int value = (Reader.Char() << 16) + (Reader.ReadByte());
							thisobj = new SInt((Reader.ReadByte()) + (Reader.ReadByte() << 16));
							break;
						case 2:
							thisobj = new SInt(Reader.ReadShort());
							break;
					}
					break;
				case (EStreamCode)0x2d:
					if (Reader.ReadByte() != (byte)0x2d)
						throw new ParseException("Didn't encounter a double 0x2d where one was expected at " + (Reader.Position - 2));
					else if (lastDbRow != null)
						lastDbRow.IsLast = true;
					return null;
				case 0:
					break;
				default:
					throw new ParseException("Can't identify type " + String.Format("{0:x2}", (int)check) +
											" at position " + String.Format("{0:x2}", Reader.Position) + " limit " + Reader.Length);
			}
			#endregion

			if (thisobj == null)
				throw new ParseException("no thisobj in parseone");

			if (isshared != 0)
			{
				if (thisobj == null)
					throw new ParseException("shared flag but no obj");
				ShareAdd(thisobj);
			}

			return thisobj;
		}
예제 #13
0
 public string UpdateOptionOfProduct(int productID)
 {
     try
     {
         string         result = "";
         List <Variant> variants = new VariantService().GetByProductID(productID);
         string         optionValue1 = "", optionValue2 = "", optionValue3 = "";
         if (variants != null && variants.Count > 0)
         {
             foreach (var item in variants)
             {
                 if (!string.IsNullOrEmpty(item.Option1))
                 {
                     if (!optionValue1.Contains(item.Option1))
                     {
                         optionValue1 += item.Option1 + ",";
                     }
                 }
                 if (!string.IsNullOrEmpty(item.Option2))
                 {
                     if (!optionValue2.Contains(item.Option2))
                     {
                         optionValue2 += item.Option2 + ",";
                     }
                 }
                 if (!string.IsNullOrEmpty(item.Option3))
                 {
                     if (!optionValue3.Contains(item.Option3))
                     {
                         optionValue3 += item.Option3 + ",";
                     }
                 }
             }
             optionValue1 = SString.RemoveElementAtBeginEnd(optionValue1, ",");
             optionValue2 = SString.RemoveElementAtBeginEnd(optionValue2, ",");
             optionValue3 = SString.RemoveElementAtBeginEnd(optionValue3, ",");
         }
         List <TblOption> options = GetByProductID(productID);
         if (options != null && options.Count > 0)
         {
             for (int i = 0; i < options.Count; i++)
             {
                 if (i == 0)
                 {
                     options[i].OptionValue = optionValue1;
                 }
                 else if (i == 1)
                 {
                     options[i].OptionValue = optionValue2;
                 }
                 else if (i == 2)
                 {
                     options[i].OptionValue = optionValue3;
                 }
                 Update(options[i]);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return("");
     }
 }
예제 #14
0
 /// <summary>
 /// Creates an instance of the string primitive, also setting the escaped status.
 /// </summary>
 internal SString CreateString(string value, bool escaped, bool interpolate)
 {
     return(SString.Factory(this, value, escaped, interpolate));
 }
예제 #15
0
        public ActionResult getLineItem(string variantChoiced, string query)
        {
            try
            {
                LineItemsOfOrder productVariantOfProduct = new LineItemsOfOrder();
                List <Product>   products = new List <Product>();
                if (string.IsNullOrEmpty(query))
                {
                    products = productService.GetAll();
                }
                else
                {
                    string where = string.Format("ProductName like N'%{0}%' or Tags like N'%{1}%' ", query, query);
                    where       += string.Format(" or ProductID in (select Product.ProductID from Product left join TblOption on Product.ProductID = TblOption.ProductID " +
                                                 " where OptionValue like N'%{0}%')", query);
                    products = productService.GetByWhere(where);
                }

                List <int> variantIDs = new List <int>();
                if (!string.IsNullOrEmpty(variantChoiced))
                {
                    variantChoiced = SString.RemoveElementAtBeginEnd(variantChoiced, ",");
                    string[] temp = variantChoiced.Split(',');
                    foreach (var item in temp)
                    {
                        variantIDs.Add(SNumber.ToNumber(item));
                    }
                }

                if (products != null && products.Count > 0)
                {
                    foreach (var item in products)
                    {
                        List <Variant> variants = variantService.GetByProductID(item.ProductID);
                        if (variants != null && variants.Count > 0)
                        {
                            if (variants.Count == 1 && variants[0].Option1 == "Default Title")
                            {
                                LineItem temp = new LineItem();
                                temp.VariantID  = variants[0].VariantID;
                                temp.SKU        = variants[0].VariantSKU;
                                temp.ProductID  = item.ProductID;
                                temp.ObjectName = item.ProductName;
                                temp.IsDefault  = true;
                                temp.Price      = SNumber.ToNumber(variants[0].VariantPrice);
                                temp.Quantity   = 1;

                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                temp.ImageUrl = thumb;
                                if (!variantIDs.Contains(temp.VariantID))
                                {
                                    temp.CanChoice = true;
                                }
                                else
                                {
                                    temp.CanChoice = false;
                                }
                                productVariantOfProduct.ProductVariants.Add(temp);
                            }
                            else
                            {
                                LineItem product = new LineItem();
                                product.VariantID  = 0;
                                product.ProductID  = item.ProductID;
                                product.ObjectName = item.ProductName;
                                product.IsDefault  = true;
                                product.Price      = -1;
                                product.CanChoice  = false;
                                product.Quantity   = 1;
                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                product.ImageUrl = thumb;
                                productVariantOfProduct.ProductVariants.Add(product);

                                for (int i = 0; i < variants.Count; i++)
                                {
                                    LineItem temp = new LineItem();
                                    temp.ProductID  = item.ProductID;
                                    temp.VariantID  = variants[i].VariantID;
                                    temp.ObjectName = variants[i].VariantTittle;
                                    temp.SKU        = variants[i].VariantSKU;
                                    temp.IsDefault  = false;
                                    temp.Price      = SNumber.ToNumber(variants[i].VariantPrice);
                                    temp.Quantity   = 1;
                                    if (!variantIDs.Contains(temp.VariantID))
                                    {
                                        temp.CanChoice = true;
                                    }
                                    else
                                    {
                                        temp.CanChoice = false;
                                    }

                                    TblImage image = imageService.GetByPrimaryKey(variants[i].ImageID);
                                    if (image != null)
                                    {
                                        temp.ImageUrl = image.ImageUrl;
                                    }
                                    productVariantOfProduct.ProductVariants.Add(temp);
                                }
                            }
                        }
                    }
                }
                return(View(productVariantOfProduct));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(null);
            }
        }
예제 #16
0
        public string detail(Collection collection, HttpPostedFileBase file)
        {
            try
            {
                collection.TemplateLayouts = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Selected = true, Text = "collection", Value = "collection"
                    },
                    new SelectListItem {
                        Selected = true, Text = "collection.list", Value = "collection.list"
                    },
                }, "Value", "Text", "1");

                //create collectionID for all rules
                foreach (var item in collection.TblRules)
                {
                    item.CollectionID = collection.CollectionID;
                }

                string strErrorMessage = "";
                bool   flg             = false;
                if (ModelState.IsValid)
                {
                    // insert collection
                    if (collection.CollectionType == "custom")
                    {
                        collection.ConditionForCollection = false;
                    }
                    else if (collection.CollectionType == "smart")
                    {
                        for (int i = 0; i < collection.TblRules.Count; i++)
                        {
                            if (string.IsNullOrEmpty(collection.TblRules[i].ConditionValue))
                            {
                                strErrorMessage += "Giá trị lọc không được để trống<br/>";
                                flg              = true;
                            }
                        }
                    }
                    if (!flg)
                    {
                        collection.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                        bool result = collectionService.Update(collection);

                        if (result)
                        {
                            LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Update, collection.CollectionID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, collection.CollectionName);

                            // delete image collection
                            string folder = Server.MapPath("~/assets/uploads/collections/") + collection.CollectionID;
                            ImageService.DeleteSubFolder(folder);

                            // update collection image url
                            string imageUrl = UploadImage(collection.CollectionID, file);
                            if (!string.IsNullOrEmpty(imageUrl))
                            {
                                collection.CollectionImage = imageUrl;
                                collectionService.Update(collection);
                            }
                            if (collection.CollectionType == "smart")
                            {
                                List <TblRule> listRuleExisted = tblRuleService.SelectByCollectionID(collection.CollectionID);
                                if (listRuleExisted == null || listRuleExisted.Count <= 0)
                                {
                                    for (int i = 0; i < collection.TblRules.Count; i++)
                                    {
                                        if (tblRuleService.CheckRuleValid(collection.TblRules[i]))
                                        {
                                            tblRuleService.Insert(collection.TblRules[i]);
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < collection.TblRules.Count; i++)
                                    {
                                        bool flgInsert = true;
                                        for (int j = 0; j < listRuleExisted.Count; j++)
                                        {
                                            if (tblRuleService.Equals(listRuleExisted[j], collection.TblRules[i]))
                                            {
                                                flgInsert = false;
                                            }
                                        }
                                        if (flgInsert)
                                        {
                                            tblRuleService.Insert(collection.TblRules[i]);
                                        }
                                    }
                                    for (int i = 0; i < listRuleExisted.Count; i++)
                                    {
                                        bool flgDelete = true;
                                        for (int j = 0; j < collection.TblRules.Count; j++)
                                        {
                                            if (tblRuleService.Equals(listRuleExisted[i], collection.TblRules[j]))
                                            {
                                                flgDelete = false;
                                            }
                                        }
                                        if (flgDelete)
                                        {
                                            tblRuleService.DeleteByPrimary(listRuleExisted[i].RuleID);
                                        }
                                    }
                                }
                                // get list prodct by all condition in collection
                                string linkCondition = "";
                                if (collection.ConditionForCollection)
                                {
                                    linkCondition = "and";
                                }
                                else
                                {
                                    linkCondition = "or";
                                }
                                string                   strConditionProductByRule      = "1=1 and " + tblRuleService.GetConditionProductByListRule(collection.TblRules, linkCondition);
                                List <Product>           listProductByRulesOfCollection = productService.GetByWhere(strConditionProductByRule);
                                List <CollectionProduct> listCollectionProductExisted   = collectionProductService.GetByCollectionID(collection.CollectionID);
                                if (listProductByRulesOfCollection != null && listProductByRulesOfCollection.Count > 0)
                                {
                                    List <int> listProductAdd    = new List <int>();
                                    List <int> listProductDelete = new List <int>();
                                    if (listCollectionProductExisted == null || listCollectionProductExisted.Count <= 0)
                                    {
                                        for (int i = 0; i < listProductByRulesOfCollection.Count; i++)
                                        {
                                            collectionProductService.Insert(new CollectionProduct
                                            {
                                                CollectionID = collection.CollectionID,
                                                ProductID    = listProductByRulesOfCollection[i].ProductID,
                                            });
                                        }
                                    }
                                    else
                                    {
                                        for (int i = 0; i < listProductByRulesOfCollection.Count; i++)
                                        {
                                            bool flgInsert = true;
                                            for (int j = 0; j < listCollectionProductExisted.Count; j++)
                                            {
                                                if (listCollectionProductExisted[j].ProductID == listProductByRulesOfCollection[i].ProductID)
                                                {
                                                    flgInsert = false;
                                                }
                                            }
                                            if (flgInsert)
                                            {
                                                collectionProductService.Insert(new CollectionProduct
                                                {
                                                    CollectionID = collection.CollectionID,
                                                    ProductID    = listProductByRulesOfCollection[i].ProductID,
                                                });
                                            }
                                        }
                                        for (int i = 0; i < listCollectionProductExisted.Count; i++)
                                        {
                                            bool flgDelete = true;
                                            for (int j = 0; j < listProductByRulesOfCollection.Count; j++)
                                            {
                                                if (listProductByRulesOfCollection[j].ProductID == listCollectionProductExisted[i].ProductID)
                                                {
                                                    flgDelete = false;
                                                }
                                            }
                                            if (flgDelete)
                                            {
                                                collectionProductService.DeleteByPrimary(listCollectionProductExisted[i].ID);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    collectionProductService.DeleteByCollectionID(collection.CollectionID);
                                }
                            }
                            return(SString.ConverToString(collection.CollectionID));
                        }
                    }
                }
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        strErrorMessage += error.ErrorMessage;
                    }
                }
                return(strErrorMessage);
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(ex.Message);
            }
        }
예제 #17
0
		protected SNode GetDBRow()
		{
			SNode nhead = ParseOne();
			// get header
			SObject head = nhead as SObject;
			if (head == null)
				throw new ParseException("The DBRow header isn't present...");

			if (head.Name != "blue.DBRowDescriptor")
				throw new ParseException("Bad descriptor name");

			STuple fields = head.Members[0].Members[1].Members[0] as STuple;

			int len = GetLength();
			byte[] olddata = Reader.ReadBytes(len);

			List<byte> newdata = new List<byte>();
			rle_unpack(olddata, newdata);
			SNode body = new SDBRow(17, newdata);

			CacheFileReader blob = new CacheFileReader(newdata.ToArray());

			SDict dict = new SDict(999999); // TODO: need dynamic sized dict
			int step = 1;
			while (step < 6)
			{
				foreach (SNode field in fields.Members)
				{
					SNode fieldName = field.Members[0];
					SInt fieldType = field.Members[1] as SInt;
					int fieldTypeInt = fieldType.Value;

					byte boolcount = 0;
					byte boolbuf = 0;
					SNode obj = null;
					switch (fieldTypeInt)
					{
						case 2: // 16bit int
							if(step == 3)
								obj = new SInt(blob.ReadShort());
							break;
						case 3: // 32bit int
							if (step == 2)
								obj = new SInt(blob.ReadInt());
							break;
						case 4:
							obj = new SReal(blob.ReadFloat());
							break;
						case 5: // double
							if(step == 1)
								obj = new SReal(blob.ReadDouble());
							break;
						case 6: // currency
							if (step == 1)
								obj = new SLong(blob.ReadLong());
							break;
						case 11: // boolean
							if (step == 5)
							{
								if (boolcount == 0)
								{
									boolbuf = blob.ReadByte();
									boolcount = 0x1;
								}
								if (boolbuf != 0 && boolcount != 0)
									obj = new SInt(1);
								else
									obj = new SInt(0);
								boolcount <<= 1;
							}
							break;
						case 16:
							obj = new SInt(blob.ReadByte());
							break;
						case 17:
							goto case 16;
						case 18: // 16bit int
							goto case 2;
						case 19: // 32bit int
							goto case 3;
						case 20: // 64bit int
							goto case 6;
						case 21: // 64bit int
							goto case 6;
						case 64: // timestamp
							goto case 6;
						case 128: // string types
						case 129:
						case 130:
							obj = new SString("I can't parse strings yet - be patient");
							break;
						default:
							throw new ParseException("Unhandled ADO type " + fieldTypeInt);
					}

					if (obj != null)
					{
						dict.AddMember(obj);
						dict.AddMember(fieldName.Clone());
					}
				}

				step++;
			}

			SNode fakerow = new STuple(3);
			fakerow.AddMember(head);
			fakerow.AddMember(body);
			fakerow.AddMember(dict);
			return fakerow;
		}