public void RemoveRow(DataRow selectedRow)
        {
            selectedRow.Delete();

            Update(selectedRow.GetType());

            AcceptChanges();
        }
示例#2
0
 public SqlParameter[] RowToParam(DataRow row, ArrayList param)
 {
     try
     {
         ArrayList result = new ArrayList(param.Count);
         foreach (string paramName in param)
         {
             object val = null;
             string propertyName = paramName.Substring(1);
             if (row.Table.Columns.Contains(propertyName) == false || row.IsNull(propertyName) == false)
             {
                 PropertyInfo pi = row.GetType().GetProperty(propertyName);
                 val = pi.GetValue(row, null); ;
                 if (val == DBNull.Value)
                     val = null;
             }
             result.Add(CreateSqlParameter(paramName, val));
         }
         return (SqlParameter[])result.ToArray(typeof(SqlParameter));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
文件: Form1.cs 项目: Hagser/csharp
        private Weather GetWeather(DataRow dr)
        {
            Weather w = new Weather();
            Type source = dr.GetType();
            Type dest = w.GetType();
            foreach (PropertyInfo pi in dest.GetProperties())
            {

                if (dr.Table.Columns.Contains(pi.Name))
                {
                    string str = dr[pi.Name].ToString();
                    if (pi.PropertyType == typeof(bool))
                    {
                        bool bout = false;
                        bool.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(double))
                    {
                        double bout = 0;
                        double.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(DateTime))
                    {
                        DateTime bout = DateTime.MinValue;
                        DateTime.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(Int32))
                    {
                        Int32 bout = Int32.MinValue;
                        Int32.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else
                        pi.SetValue(w, str);
                }

            }
            try
            {
                string ew = dr["EW"].ToString();
                string ns = dr["NS"].ToString();
                if (!string.IsNullOrEmpty(ew) && !string.IsNullOrEmpty(ns))
                {
                    double dlat = double.Parse(ew.Replace(".", ","));
                    double dlng = double.Parse(ns.Replace(".", ","));

                    Weather wcoo = ConvertXYZToLatLngAlt(w.Id, dlat, dlng);
                    w.Lat = wcoo.Lat;
                    w.Lng = wcoo.Lng;
                }
            }
            catch (Exception ex)
            { }
            return w;
        }
示例#4
0
文件: Form1.cs 项目: Hagser/csharp
        private photo getPhoto(DataRow dr)
        {
            photo w = new photo();
            Type source = dr.GetType();
            Type dest = w.GetType();
            foreach (PropertyInfo pi in dest.GetProperties())
            {
                if (dr.Table.Columns.Contains(pi.Name))
                {
                    string str = dr[pi.Name].ToString();
                    if (pi.PropertyType == typeof(bool))
                    {
                        bool bout = false;
                        bool.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(double))
                    {
                        double bout = 0;
                        double.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(DateTime))
                    {
                        DateTime bout = DateTime.MinValue;
                        DateTime.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else if (pi.PropertyType == typeof(Int32))
                    {
                        Int32 bout = Int32.MinValue;
                        Int32.TryParse(str, out bout);
                        pi.SetValue(w, bout);
                    }
                    else
                        pi.SetValue(w, str);
                }

            }
            return w;
        }
示例#5
0
 /// <summary>
 /// 打印 DataRow .
 /// </summary>
 /// <param name="sb">输出缓冲区.</param>
 /// <param name="indent">缩进.</param>
 /// <param name="obj">对象.</param>
 public static void PrintDataRow(StringBuilder sb, int indent, DataRow obj)
 {
     int indentnext = indent + 1;
     String indentstr = GetIndentStr(indent);
     sb.AppendLine(string.Format("{0}# <{1}>", indentstr, obj.GetType().FullName));
     sb.AppendLine(string.Format("{0}HasErrors:\t{1}", indentstr, obj.HasErrors));
     sb.AppendLine(string.Format("{0}RowError:\t{1}", indentstr, obj.RowError));
     sb.AppendLine(string.Format("{0}RowState:\t{1}", indentstr, obj.RowState));
 }
示例#6
0
        public bool SaveToBaseDirectoryDeleted(DataRow[] dataRows)
        {
            if (dataRows.Length == 0) return false;
            Type tp = this.components.Components[dataRows[0].Table.TableName + "TableAdapter"].GetType();
            Object[] args = new Object[1];
            args[0] = dataRows;
            Type[] types = new Type[1];
            types[0] = dataRows.GetType();
            try
            {
                tp.GetMethod("Update", types).Invoke(this.components.Components[dataRows[0].Table.TableName + "TableAdapter"], args);
            }
            catch (Exception err)
            {
                Log("SaveToBaseDirectoryDeleted ERROR" + err.Message + " " + err.Source + err.InnerException.Message);  
                return false;
            }
            finally
            {

                Log("SaveToBaseDirectoryDeleted successfull");  
                
               
            }
            return true;
        }
示例#7
0
        //---------SAVE 
      
        public bool SaveToBaseDirectoryModifed(DataRow[] dataRows)
        {
           

            if (dataRows.Length == 0) return false;
            Type tp = this.components.Components[dataRows[0].Table.TableName + "TableAdapter"].GetType();
            Object[] _args = new Object[1];
            _args[0] = dataRows;
            Type[] types = new Type[1];
            types[0] = dataRows.GetType();

            //**Новые данные**//     


           
            try
            {

                tp.GetMethod("Update", types).Invoke(this.components.Components[dataRows[0].Table.TableName + "TableAdapter"], _args);
            }
            catch (DBConcurrencyException dbcx)
            {
                this.onDirectoryDBCError(dbcx);
                Log("SaveToBaseDirectoryModifed" + dbcx.Message);
                return false;
            }

            catch (SqlException sqlerr)
            {
                if (sqlerr.Class < 17)
                {
                    MessageBox.Show("Не отработана ошибка"+sqlerr.Message);
                    Log("SaveToBaseDirectoryModifed SQLERROR" + sqlerr.Message);
                }
                else

                    caughtGlobalError(sqlerr);
                return false;


            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                Log("SaveToBaseDirectoryModifed ERROR" + err.Message + " " + err.Source + err.InnerException.Message);                
                return false;
            }

           
            finally
            {
                Log("SaveToBaseDirectoryModifed successful;");                
           
            }
            return true;
        }