示例#1
0
 /// <summary>
 /// Gets the template for the gear specifications of a given gear variation
 /// A List (_GearSpecifications) is filled
 /// </summary>
 private static void GetGearSpecs()
 {
     _GearSpecifications.Clear();
     using (var con = new OleDbConnection(global.ConnectionString))
     {
         con.Open();
         string query = $@"Select RowID, ElementName, Description, ElementType, Sequence
                        from tblGearSpecs where Version = '2' and GearVarGuid ={{{_gearVarGuid}}}
                        order by sequence";
         using (var dt = new DataTable())
         {
             var adapter = new OleDbDataAdapter(query, con);
             adapter.Fill(dt);
             foreach (DataRow row in dt.Rows)
             {
                 var spec = new GearSpecification();
                 spec.Property   = row["ElementName"].ToString();
                 spec.Type       = row["ElementType"].ToString();
                 spec.Notes      = row["Description"].ToString();
                 spec.RowGuid    = row["RowID"].ToString();
                 spec.DataStatus = fad3DataStatus.statusFromDB;
                 var seq = 0;
                 if (int.TryParse(row["Sequence"].ToString(), out seq))
                 {
                     spec.Sequence = seq;
                 }
                 _GearSpecifications.Add(spec);
             }
         }
         con.Close();
     }
 }
示例#2
0
        /// <summary>
        /// returns a List<> of gear specifications
        /// </summary>
        /// <param name="variationGuid">gear variation guid</param>
        /// <returns></returns>
        public static List <GearSpecification> GearVariationSpecs(string variationGuid)
        {
            List <GearSpecification> gearSpecs = new List <GearSpecification>();
            var dt = new DataTable();

            using (var conection = new OleDbConnection(global.ConnectionString))
            {
                conection.Open();
                string query = $"Select RowID, ElementName,ElementType,Sequence,Description from tblGearSpecs where Version = '2' AND GearVarGuid={{{variationGuid}}}";
                using (var adapter = new OleDbDataAdapter(query, conection))
                {
                    adapter.Fill(dt);

                    for (int n = 0; n < dt.Rows.Count; n++)
                    {
                        DataRow           dr = dt.Rows[n];
                        GearSpecification gs = new GearSpecification(dr["ElementName"].ToString(), dr["ElementType"].ToString(), dr["RowID"].ToString(), (int)dr["Sequence"]);
                        gs.Notes      = dr["Description"].ToString();
                        gs.DataStatus = fad3DataStatus.statusFromDB;
                        gearSpecs.Add(gs);
                    }
                }
            }
            return(gearSpecs);
        }
        private bool SaveProperties()
        {
            _gearSpecs.Clear();
            foreach (ListViewItem lvi in lvSpecs.Items)
            {
                fad3DataStatus ds;
                Enum.TryParse(lvi.SubItems[3].Text, out ds);
                var spec = new GearSpecification
                {
                    Property   = lvi.Text,
                    Type       = lvi.SubItems[1].Text,
                    Notes      = lvi.SubItems[2].Text,
                    DataStatus = ds,
                    RowGuid    = lvi.Name,
                };

                if (spec.Sequence != lvi.Index + 1 && ds != fad3DataStatus.statusNew)
                {
                    spec.DataStatus = fad3DataStatus.statusEdited;
                    spec.Sequence   = lvi.Index + 1;
                }

                _gearSpecs.Add(spec);
            }

            foreach (var item in _deletedSpecsRow)
            {
                var spec = new GearSpecification
                {
                    RowGuid    = item,
                    DataStatus = fad3DataStatus.statusForDeletion
                };
                _gearSpecs.Add(spec);
            }

            return(ManageGearSpecsClass.SaveGearSpecs(_gearSpecs));
        }
示例#4
0
        public static bool SaveGearSpec(string gearVariationGuid, GearSpecification spec)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(global.ConnectionString))
            {
                conn.Open();
                int    version = 2;
                string sql     = $@"Insert into tblGearSpecs (ElementName, ElementType, Description, Sequence, Version, RowId, GearVarGuid)
                              values (
                              '{spec.Property}',
                              '{spec.Type}',
                              '{spec.Notes}',
                              {spec.Sequence},
                              '{version}',
                              {{{spec.RowGuid}}},
                              {{{gearVariationGuid}}})";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    try
                    {
                        success = (update.ExecuteNonQuery() > 0);
                    }
                    catch (OleDbException)
                    {
                        success = false;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex.Message, ex.StackTrace);
                        success = false;
                    }
                }
            }
            return(success);
        }