示例#1
0
        public static bool save_web_db(ShipmentItem d)
        {
            using (SqlConnection conn = sql_conn())
            {
                try
                {
                    conn.Open();
                    SqlCommand myCommand = new SqlCommand();
                    myCommand.Connection  = conn;
                    myCommand.CommandText = "UPDATE [ShipmentItems] SET RealWeightNet = @wt, Heigth = @he, Width = @wi Where Length = @le ";

                    myCommand.Parameters.AddWithValue("@wt", Funkcije.pretvori(d.RealWeightNet));

                    myCommand.Parameters.AddWithValue("@he", Funkcije.pretvori(d.Heigth));
                    myCommand.Parameters.AddWithValue("@wi", Funkcije.pretvori(d.Width));
                    myCommand.Parameters.AddWithValue("@le", Funkcije.pretvori(d.Length));



                    myCommand.ExecuteNonQuery();
                }
                catch (Exception ee)
                {
                    MessageBox.Show("Neuspjelo spajanje na web bazu!!", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        private static void popuni_sve_varijable_u_klasi(ShipmentItem d, SqlDataReader myReader)
        {
            var props = d.GetType().GetProperties();

            foreach (var prop in props)
            {
                string s = prop.PropertyType.FullName;
                if (prop.Name == "Barcode" || s.Contains("ObservableCollection"))
                {
                    continue;
                }

                if (s.Contains("Nullable") && myReader[prop.Name].ToString() == "")
                {
                    prop.SetValue(d, null);
                }
                else if (s.Contains("Int32"))
                {
                    prop.SetValue(d, Convert.ToInt32(Funkcije.pretvori((myReader[prop.Name]))));
                }
                else if (s.Contains("Int16"))
                {
                    prop.SetValue(d, Convert.ToInt16(Funkcije.pretvori((myReader[prop.Name]))));
                }
                else if (s.Contains("Double"))
                {
                    prop.SetValue(d, Funkcije.pretvori((myReader[prop.Name])));
                }
                else if (s.Contains("Decimal"))
                {
                    prop.SetValue(d, (decimal)Funkcije.pretvori((myReader[prop.Name])));
                }
                else if (s.Contains("Boolean") || s.Contains("DateTime") || s.Contains("Byte"))
                {
                    prop.SetValue(d, (myReader[prop.Name]));
                }
                else if (s.Contains("String"))
                {
                    prop.SetValue(d, (myReader[prop.Name]).ToString());
                }
            }

            props = d.Shipment.GetType().GetProperties();

            foreach (var prop in props)
            {
                string s = prop.PropertyType.FullName;
                if (prop.Name == "Barcode" || s.Contains("ObservableCollection"))
                {
                    continue;
                }
                if ((s.Contains("Nullable") || s.Contains("Byte")) && myReader[prop.Name].ToString() == "")
                {
                    prop.SetValue(d.Shipment, null);
                }
                else if (s.Contains("Int32"))
                {
                    prop.SetValue(d.Shipment, Convert.ToInt32(Funkcije.pretvori((myReader[prop.Name]))));
                }
                else if (s.Contains("Int16"))
                {
                    prop.SetValue(d.Shipment, Convert.ToInt16(Funkcije.pretvori((myReader[prop.Name]))));
                }
                else if (s.Contains("Double"))
                {
                    prop.SetValue(d.Shipment, Funkcije.pretvori((myReader[prop.Name])));
                }
                else if (s.Contains("Decimal"))
                {
                    prop.SetValue(d.Shipment, (decimal)Funkcije.pretvori((myReader[prop.Name])));
                }
                else if (s.Contains("Boolean") || s.Contains("DateTime") || s.Contains("Byte"))
                {
                    prop.SetValue(d.Shipment, (myReader[prop.Name]));
                }
                else if (s.Contains("String"))
                {
                    prop.SetValue(d.Shipment, (myReader[prop.Name]).ToString());
                }
            }
        }