Example #1
0
        public void AddProductHierarchys(XElement XMLProHei)
        {
            if (conn.State == System.Data.ConnectionState.Closed)
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    log.Error("Cannot open the Database due to: ", ex);
                    return;
                }
            }
            try
            {
                IEnumerable <XElement> Prohei =
                    from phs in XMLProHei.Elements("Statement").Elements("PRODHIERTABLE").Elements("access")
                    select phs;
                foreach (XElement ph in Prohei)
                {
                    ProHierarchy Pro = new ProHierarchy();
                    Pro.BrandCode    = ph.Element("BrandCode").Value;
                    Pro.BrandName    = ph.Element("BrandName").Value;
                    Pro.SubBrandCode = ph.Element("SubBrandCode").Value;
                    Pro.SubbrandName = ph.Element("SubbrandName").Value;
                    Pro.ProductID    = ph.Element("ProductID").Value;
                    Pro.CompanyID    = ph.Element("CompanyID").Value;
                    Pro.Status       = ph.Element("Status").Value;
                    int result = Pro.Inert_ProHei(Pro, conn);
                    if (result == 1)
                    {
                        log.Info("Insert to PRODHIERTABLE successfull: " + Pro.BrandCode);
                    }
                    else
                    {
                        log.Info("Insert to PRODHIERTABLE failed: " + Pro.BrandCode);
                    }
                }
                conn.Close();
            }

            catch (Exception ex)
            {
                log.Error("Insert into CUSTMSTTABLE failed due to: " + ex);
                return;
            }
        }
 public int Inert_ProHei(ProHierarchy ProH, SqlConnection conn)
 {
     using (SqlCommand cmd = new SqlCommand("spr_INSERT_PRODHIERTABLE", conn))
     {
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@BrandCode", SqlDbType.VarChar).Value = ProH.BrandCode;
         cmd.Parameters.Add("@BrandName", SqlDbType.VarChar).Value = ProH.BrandName;
         cmd.Parameters.Add("@SubBrandCode", SqlDbType.VarChar).Value = ProH.SubBrandCode;
         cmd.Parameters.Add("@SubbrandName", SqlDbType.VarChar).Value = ProH.SubbrandName;
         cmd.Parameters.Add("@ProductID", SqlDbType.VarChar).Value = ProH.ProductID;
         cmd.Parameters.Add("@CompanyID", SqlDbType.VarChar).Value = ProH.CompanyID;
         cmd.Parameters.Add("@Status", SqlDbType.Decimal).Value = ProH.Status;
         int result = cmd.ExecuteNonQuery();
         return result;
     }
 }
Example #3
0
 public void AddProductHierarchy(ProHierarchy ProHei)
 {
     if (conn.State == System.Data.ConnectionState.Closed)
     {
         try
         {
             conn.Open();
         }
         catch (Exception ex)
         {
             log.Error("Cannot open the Database due to: ", ex);
             return;
         }
     }
     try
     {
         using (SqlCommand cmd = new SqlCommand("spr_INSERT_PRODHIERTABLE", conn))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add("@BrandCode", SqlDbType.VarChar).Value    = ProHei.BrandCode;
             cmd.Parameters.Add("@BrandName", SqlDbType.VarChar).Value    = ProHei.BrandName;
             cmd.Parameters.Add("@SubBrandCode", SqlDbType.VarChar).Value = ProHei.SubBrandCode;
             cmd.Parameters.Add("@SubbrandName", SqlDbType.VarChar).Value = ProHei.SubbrandName;
             cmd.Parameters.Add("@ProductID", SqlDbType.VarChar).Value    = ProHei.ProductID;
             cmd.Parameters.Add("@CompanyID", SqlDbType.VarChar).Value    = ProHei.CompanyID;
             cmd.Parameters.Add("@Status", SqlDbType.Decimal).Value       = ProHei.Status;
             int result = cmd.ExecuteNonQuery();
             conn.Close();
             if (result == 1)
             {
                 log.Info(ProHei.BrandCode.ToString() + " - Insert to PRODHIERTABLE successfull");
                 return;
             }
             else
             {
                 log.Error(ProHei.BrandCode.ToString() + " - Insert to PRODHIERTABLE failed");
                 return;
             }
         }
     }
     catch (Exception ex)
     {
         //throw ex;
         log.Error(ProHei.BrandCode.ToString() + " - Failed to insert: ", ex);
         return;
     }
 }