public ProductDetail GetProductDetail(int pid)
 {
     ProductDetail detail = new ProductDetail();
     Type typeOfClass = detail.GetType();
     DataTable dt = dbHelper.ExecuteDataTable("select * from AliProductDetail where pid = " + pid, null);
     if (dt == null || dt.Rows.Count == 0) return null;
     foreach (DataRow row in dt.Rows)
     {
         foreach (DataColumn col in dt.Columns)
         {
             string propertyName = col.ColumnName;
             PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
             if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
             {
                 string element = (string)row[propertyName];
                 FormElement el = JsonConvert.FromJson<FormElement>(element);
                 pInfo.SetValue(detail, el, null);
             }
         }
     }
     detail.pid = pid;
     detail.CustomAttr = GetCustomAttr(pid);
     detail.SysAttr = GetSystemAttr(pid, Constants.AttrType_SysAttr);
     detail.FixAttr = GetSystemAttr(pid, Constants.AttrType_FixAttr);
     return detail;
 }
 public void Insert(ProductDetail detail)
 {
     Type typeOfClass = detail.GetType();
     PropertyInfo[] pInfo = typeOfClass.GetProperties();
     string sqlCondi = "INSERT INTO AliProductDetail(pid,gmtModified";
     string sqlValue = ")values(@pid, @gmtModified";
     string sqlEnd = ");";
     List<SQLiteParameter> parameter = new List<SQLiteParameter>();
     parameter.Add(new SQLiteParameter("@pid", detail.pid));
     parameter.Add(new SQLiteParameter("@gmtModified", detail.gmtModified));
     foreach (PropertyInfo info in pInfo)
     {
         if (info.PropertyType.Name == "FormElement")
         {
             sqlCondi = sqlCondi + ", " + info.Name;
             sqlValue = sqlValue + ", @" + info.Name;
             object val = info.GetValue(detail, null);
             string json = JsonConvert.ToJson(val);
             parameter.Add(new SQLiteParameter("@" + info.Name, json));
         }
     }
     string InsSql = sqlCondi + sqlValue + sqlEnd;
     dbHelper.ExecuteNonQuery(InsSql, parameter.ToArray());
 }
 public void Update(ProductDetail detail)
 {
     Type typeOfClass = detail.GetType();
     PropertyInfo[] pInfo = typeOfClass.GetProperties();
     string sqlCondi = "Update AliProductDetail SET gmtModified=@gmtModified";
     string sqlEnd = " where pid = @pid";
     List<SQLiteParameter> parameter = new List<SQLiteParameter>();
     parameter.Add(new SQLiteParameter("@gmtModified", detail.gmtModified));
     foreach (PropertyInfo info in pInfo)
     {
         if (info.PropertyType.Name == "FormElement")
         {
             sqlCondi = sqlCondi + "," + info.Name + " = @" + info.Name;
             object val = info.GetValue(detail, null);
             string json = JsonConvert.ToJson(val);
             parameter.Add(new SQLiteParameter("@" + info.Name, json));
         }
     }
     parameter.Add(new SQLiteParameter("@pid", detail.pid));
     string UpdateSql = sqlCondi + sqlEnd;
     dbHelper.ExecuteNonQuery(UpdateSql, parameter.ToArray());
 }
 public void InsertOrUpdate(ProductDetail detail)
 {
     string sql = "select count(1) from AliProductDetail where pid = " + detail.pid;
     int count = Convert.ToInt32(dbHelper.ExecuteScalar(sql, null));
     if (count > 0)
     {
         Update(detail);
     }
     else {
         Insert(detail);
     }
     UpdateCustomAttr(detail.pid, detail.CustomAttr);
     UpdateSystemAttr(detail.pid, Constants.AttrType_SysAttr, detail.SysAttr);
     UpdateSystemAttr(detail.pid, Constants.AttrType_FixAttr, detail.FixAttr);
 }
Exemple #5
0
 private void DownProductDetail_DoWork(object sender, DoWorkEventArgs e)
 {
     AliProduct product = productsManager.GetAliProduct(PrevSelectedId);
     ProductDetail detail = impProductDetail.GetEditFormElements(product);
     productsManager.InsertOrUpdateProdcutDetail(detail);
     this.AliProductDetail = productsManager.GetProductDetail(PrevSelectedId);
     this.BeginInvoke(new Action(() =>
     {
         this.LoadProductIamges();
         this.LoadProductDetailValue();
         //this.ProductGrid.Focus();
     }));
 }
Exemple #6
0
 private void clickEvent_Click(object sender, EventArgs e)
 {
     SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
     int id = (int)ProductGrid.Rows[context.Position.Row].Tag;
     if (id != PrevSelectedId)
     {
         PrevSelectedId = id;
         this.AliProductDetail = productsManager.GetProductDetail(PrevSelectedId);
         this.LoadProductIamges();
         this.LoadProductDetailValue();
         //this.ProductGrid.Focus();
         if (AliProductDetail == null)
         {
             BackgroundWorker backgroundWorker = new BackgroundWorker();
             backgroundWorker.DoWork += new DoWorkEventHandler(DownProductDetail_DoWork);
             backgroundWorker.RunWorkerAsync();
             backgroundWorker.Dispose();
         }
     }
 }
Exemple #7
0
        public ProductDetail PrintElementsValue(HtmlNode htmlNode)
        {
            ProductDetail detail = new ProductDetail();
            Type typeOfClass = detail.GetType();
            IEnumerable<HtmlNode> nodeTags = htmlNode.SelectNodes(@".//input[@type='hidden'] | .//input[@type='text']");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    if ("_fmp.pr._0.u" == name || "_fmp.pr._0.us" == name)
                    {
                        continue;
                    }
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);

                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;

                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            detail.CustomAttr = new Dictionary<FormElement, FormElement>();
            HtmlNodeCollection customNameTags = htmlNode.SelectNodes(@".//tr[@class='custom-attr-item']/td/input[@name='_fmp.pr._0.u']");
            HtmlNodeCollection customValueTags = htmlNode.SelectNodes(@".//tr[@class='custom-attr-item']/td/input[@name='_fmp.pr._0.us']");
            if (customNameTags != null)
            {
                for (int i = 0; i < customNameTags.Count; i ++ )
                {
                    HtmlNode nameNode = customNameTags[i];
                    string id = nameNode.GetAttributeValue("id", "");
                    string type = nameNode.GetAttributeValue("type", "");
                    string name = nameNode.GetAttributeValue("name", "");
                    string value = nameNode.GetAttributeValue("value", "");
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement nameEl = new FormElement();
                    nameEl.Id = id;
                    nameEl.Type = type;
                    nameEl.Name = name;
                    nameEl.Value = value;

                    HtmlNode valueNode = customValueTags[i];
                    string vid = valueNode.GetAttributeValue("id", "");
                    string vtype = valueNode.GetAttributeValue("type", "");
                    string vname = valueNode.GetAttributeValue("name", "");
                    string vvalue = valueNode.GetAttributeValue("value", "");
                    System.Diagnostics.Trace.WriteLine("Id:" + vid + "  type:" + vtype + "  name:" + vname + "  value:" + vvalue);
                    FormElement valueEl = new FormElement();
                    valueEl.Id = vid;
                    valueEl.Type = vtype;
                    valueEl.Name = vname;
                    valueEl.Value = vvalue;
                    detail.CustomAttr.Add(nameEl, valueEl);
                }
            }

            nodeTags = htmlNode.SelectNodes(@".//input[@type='radio']");
            System.Diagnostics.Trace.WriteLine("radiobox===========================");

            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    bool chk = node.Attributes["checked"] != null;
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    el.Checked = chk;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  checked:" + chk + "  value:" + value);
                    string propertyName = GetRadioBoxPropertyName(id, name, value);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            System.Diagnostics.Trace.WriteLine("radiobox===========================");

            nodeTags = htmlNode.SelectNodes(@".//input[@type='checkbox']");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    bool chk = node.Attributes["checked"] != null;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  checked:" + chk + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    el.Checked = chk;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }

            System.Diagnostics.Trace.WriteLine("select===========================");
            nodeTags = htmlNode.SelectNodes(@".//select");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = "select";
                    string name = node.GetAttributeValue("name", "");
                    string value = GetSelectValue(node);
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }

                }
            }
            System.Diagnostics.Trace.WriteLine("select===========================");

            nodeTags = htmlNode.SelectNodes(@".//textarea");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.InnerHtml;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = "textarea";
                    el.Name = name;
                    el.Value = value;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            return detail;
        }