public void TestMethod1()
        {
            // Arrange


            // Act
            FreeShipping freeShipping = this.CreateFreeShipping();


            // Assert
        }
Exemplo n.º 2
0
        private FreightTemplate ReadPostData(System.Collections.Specialized.NameValueCollection Form)
        {
            string          text            = "";
            FreightTemplate freightTemplate = new FreightTemplate();

            try
            {
                this.TaskMsg.msg           = "";
                freightTemplate.Name       = Form["Name"];
                freightTemplate.TemplateId = int.Parse(Form["TemplateId"]);
                if (!string.IsNullOrEmpty(freightTemplate.Name))
                {
                    freightTemplate.MUnit = int.Parse(Form["MUnit"]);
                    if (int.Parse(Form["FreeShip"]) == 0)
                    {
                        freightTemplate.FreeShip = false;
                    }
                    else
                    {
                        freightTemplate.FreeShip = true;
                    }
                    if (!freightTemplate.FreeShip)
                    {
                        if (int.Parse(Form["HasFree"]) == 0)
                        {
                            freightTemplate.HasFree = false;
                        }
                        else
                        {
                            freightTemplate.HasFree = true;
                            int num = 0;
                            freightTemplate.FreeShippings = new System.Collections.Generic.List <FreeShipping>();
                            while (!string.IsNullOrEmpty(Form["freeShippings[" + num + "][ModelId]"]) && this.TaskMsg.msg == "")
                            {
                                FreeShipping freeShipping = new FreeShipping();
                                freeShipping.ModeId          = int.Parse(Form["freeShippings[" + num + "][ModelId]"]);
                                freeShipping.ConditionType   = int.Parse(Form["freeShippings[" + num + "][ConditionType]"]);
                                freeShipping.ConditionNumber = Form["freeShippings[" + num + "][ConditionNumber]"];
                                string text2 = Form["freeShippings[" + num + "][FreeRegions]"];
                                if (!string.IsNullOrEmpty(text2))
                                {
                                    string[] array = text2.Split(new char[]
                                    {
                                        ','
                                    });
                                    if (array.Length > 0)
                                    {
                                        freeShipping.FreeShippingRegions = new System.Collections.Generic.List <FreeShippingRegion>();
                                        string[] array2 = array;
                                        for (int i = 0; i < array2.Length; i++)
                                        {
                                            string s    = array2[i];
                                            int    num2 = 0;
                                            if (int.TryParse(s, out num2) && num2 != 0)
                                            {
                                                FreeShippingRegion freeShippingRegion = new FreeShippingRegion();
                                                freeShippingRegion.RegionId = num2;
                                                freeShipping.FreeShippingRegions.Add(freeShippingRegion);
                                            }
                                        }
                                    }
                                }
                                ValidationResults validationResults = Validation.Validate <FreeShipping>(freeShipping, new string[]
                                {
                                    "ValFree"
                                });
                                text = "";
                                if (!validationResults.IsValid)
                                {
                                    foreach (ValidationResult current in ((System.Collections.Generic.IEnumerable <ValidationResult>)validationResults))
                                    {
                                        text += current.Message;
                                    }
                                    this.TaskMsg.msg = text;
                                }
                                freightTemplate.FreeShippings.Add(freeShipping);
                                num++;
                            }
                        }
                        int num3 = 0;
                        if (!string.IsNullOrEmpty(Form["shipperSelect[" + num3 + "][ModelId]"]) && this.TaskMsg.msg == "")
                        {
                            freightTemplate.SpecifyRegionGroups = new System.Collections.Generic.List <SpecifyRegionGroup>();
                            while (!string.IsNullOrEmpty(Form["shipperSelect[" + num3 + "][ModelId]"]))
                            {
                                if (!(this.TaskMsg.msg == ""))
                                {
                                    break;
                                }
                                SpecifyRegionGroup specifyRegionGroup = new SpecifyRegionGroup();
                                specifyRegionGroup.ModeId      = int.Parse(Form["shipperSelect[" + num3 + "][ModelId]"]);
                                specifyRegionGroup.FristPrice  = decimal.Parse(Form["shipperSelect[" + num3 + "][FristPrice]"]);
                                specifyRegionGroup.AddNumber   = decimal.Parse(Form["shipperSelect[" + num3 + "][AddNumber]"]);
                                specifyRegionGroup.FristNumber = decimal.Parse(Form["shipperSelect[" + num3 + "][FristNumber]"]);
                                specifyRegionGroup.AddPrice    = decimal.Parse(Form["shipperSelect[" + num3 + "][AddPrice]"]);
                                specifyRegionGroup.IsDefault   = false;
                                if (int.Parse(Form["shipperSelect[" + num3 + "][IsDefault]"]) == 1)
                                {
                                    specifyRegionGroup.IsDefault = true;
                                }
                                string text3 = Form["shipperSelect[" + num3 + "][SpecifyRegions]"];
                                if (!string.IsNullOrEmpty(text3))
                                {
                                    string[] array3 = text3.Split(new char[]
                                    {
                                        ','
                                    });
                                    if (array3.Length > 0)
                                    {
                                        specifyRegionGroup.SpecifyRegions = new System.Collections.Generic.List <SpecifyRegion>();
                                        string[] array4 = array3;
                                        for (int j = 0; j < array4.Length; j++)
                                        {
                                            string s2   = array4[j];
                                            int    num4 = 0;
                                            if (int.TryParse(s2, out num4) && num4 != 0)
                                            {
                                                SpecifyRegion specifyRegion = new SpecifyRegion();
                                                specifyRegion.RegionId = num4;
                                                specifyRegionGroup.SpecifyRegions.Add(specifyRegion);
                                            }
                                        }
                                    }
                                }
                                ValidationResults validationResults = Validation.Validate <SpecifyRegionGroup>(specifyRegionGroup, new string[]
                                {
                                    "ValRegionGroup"
                                });
                                text = "";
                                if (!validationResults.IsValid)
                                {
                                    foreach (ValidationResult current2 in ((System.Collections.Generic.IEnumerable <ValidationResult>)validationResults))
                                    {
                                        text += current2.Message;
                                    }
                                    this.TaskMsg.msg = text;
                                }
                                freightTemplate.SpecifyRegionGroups.Add(specifyRegionGroup);
                                num3++;
                            }
                        }
                        else
                        {
                            this.TaskMsg.msg = "没有运送方式选择";
                        }
                    }
                    else
                    {
                        freightTemplate.HasFree = false;
                    }
                }
                else
                {
                    this.TaskMsg.msg = "模板名称不能为空";
                }
                if (this.TaskMsg.msg == "")
                {
                    this.TaskMsg.state = "success";
                }
                else
                {
                    this.TaskMsg.state = "faild";
                }
            }
            catch (System.Exception ex)
            {
                this.TaskMsg.msg = "参数异常:" + ex.Message.ToString();
            }
            return(freightTemplate);
        }
Exemplo n.º 3
0
        public FreightTemplate GetFreightTemplate(int templateId, bool includeDetail)
        {
            FreightTemplate template         = new FreightTemplate();
            DbCommand       sqlStringCommand = this.database.GetSqlStringCommand(" SELECT * FROM Hishop_FreightTemplate_Templates Where TemplateId =@TemplateId");

            if (includeDetail)
            {
                sqlStringCommand.CommandText = sqlStringCommand.CommandText + " SELECT * FROM Hishop_FreightTemplate_FreeShipping g,vw_Hishop_FreightTemplate_FreeShippingRegions r Where g.FreeId=r.FreeId and TemplateId =@TemplateId";
                sqlStringCommand.CommandText = sqlStringCommand.CommandText + " SELECT g.*,r.RegionIds FROM Hishop_FreightTemplate_SpecifyRegionGroups g  LEFT JOIN  vw_Hishop_FreightTemplate_SpecifyRegions r on (g.GroupId=r.GroupId) where  g.TemplateId =@TemplateId";
            }
            this.database.AddInParameter(sqlStringCommand, "TemplateId", DbType.Int32, templateId);
            using (IDataReader reader = this.database.ExecuteReader(sqlStringCommand))
            {
                if (reader.Read())
                {
                    if (reader["TemplateId"] != DBNull.Value)
                    {
                        template.TemplateId = (int)reader["TemplateId"];
                    }
                    template.Name     = (string)reader["Name"];
                    template.FreeShip = (bool)reader["FreeShip"];
                    template.HasFree  = (bool)reader["HasFree"];
                    template.MUnit    = (byte)reader["MUnit"];
                }
                if (!includeDetail)
                {
                    return(template);
                }
                reader.NextResult();
                template.FreeShippings = new List <FreeShipping>();
                while (reader.Read())
                {
                    FreeShipping item = new FreeShipping {
                        TemplateId      = (int)reader["TemplateId"],
                        ModeId          = (byte)reader["ModeId"],
                        FreeId          = (int)((decimal)reader["FreeId"]),
                        ConditionNumber = (string)reader["ConditionNumber"],
                        ConditionType   = (byte)reader["ConditionType"],
                        RegionIds       = (string)reader["RegionIds"]
                    };
                    template.FreeShippings.Add(item);
                }
                reader.NextResult();
                template.SpecifyRegionGroups = new List <SpecifyRegionGroup>();
                while (reader.Read())
                {
                    SpecifyRegionGroup group = new SpecifyRegionGroup {
                        TemplateId  = (int)reader["TemplateId"],
                        GroupId     = (int)reader["GroupId"],
                        FristNumber = (int)reader["FristNumber"],
                        FristPrice  = (decimal)reader["FristPrice"],
                        AddNumber   = (int)reader["AddNumber"],
                        AddPrice    = (decimal)reader["AddPrice"],
                        ModeId      = (byte)reader["ModeId"],
                        IsDefault   = (bool)reader["IsDefault"]
                    };
                    string str = "";
                    if (DBNull.Value != reader["RegionIds"])
                    {
                        str = (string)reader["RegionIds"];
                    }
                    group.RegionIds = str;
                    template.SpecifyRegionGroups.Add(group);
                }
            }
            return(template);
        }