Exemplo n.º 1
0
 /// <summary>
 /// 从本地读取用户
 /// </summary>
 protected void RedUser()
 {
     try
     {
         DataSet ds = XmlSerializeHelper.XmlToDataTable(db.ReadXML());
         if (ds.Tables[0].Rows.Count > 5)
         {
             DataTable dt = CommonHelp.DtSelectTop(5, ds.Tables[0]);
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 cbox_user.Items.Add(dt.Rows[i]["name"].ToString());
             }
         }
         else
         {
             for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
             {
                 cbox_user.Items.Add(ds.Tables[0].Rows[i]["name"].ToString());
             }
         }
     }
     catch { }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 这个方法很有用,用于将从his获取的数据,插入一个临时表TempTest。从表中分析原始数据是否有问题。
        /// </summary>
        static void testCopyDataTableToDB(int SynCode, string tempTableName)
        {
            try
            {
                DB_Help dbHelp    = new DB_Help();
                DataSet dsSynData = dbHelp.GetPIVAsDB("SELECT TOP 100 SynID,EndTime,SynData FROM " +
                                                      "SynLog  where SynCode = " + SynCode.ToString() + " order by SynID desc");

                //获取表结构
                DataSet dsHis = dbHelp.GetPIVAsDB("select top 1 * from " + tempTableName);
                foreach (DataRow item in dsSynData.Tables[0].Rows)
                {
                    string  str = item["SynData"].ToString();
                    DataSet ds  = XmlSerializeHelper.XmlToDataTable(str);
                    if (ds.Tables != null && ds.Tables.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr = ds.Tables[0].Rows[i];
                            foreach (DataColumn dc in dsHis.Tables[0].Columns)//dsHis肯定有表结构
                            {
                                try
                                {
                                    if (dc.Caption.ToLower().Equals("id") || dc.Caption.ToLower().Equals("usedrugid"))
                                    {
                                        continue;//列不存在时跳出本次
                                    }
                                    if (!ds.Tables[0].Columns.Contains(dc.Caption))
                                    {
                                        ds.Tables[0].Columns.Add(dc.Caption, dc.DataType);
                                        continue;//列不存在时添加,然后跳出本次
                                    }

                                    if (!dc.DataType.Name.ToLower().Equals("string"))
                                    {
                                        if (string.IsNullOrEmpty(dr[dc.Caption].ToString()))
                                        {
                                            dr[dc.Caption] = DBNull.Value;
                                        }
                                        else if (dc.DataType.Name.ToLower().Equals("boolean"))
                                        {
                                            bool b = dr[dc.Caption].ToString().Trim().Equals("0") ? false : true;
                                            dr[dc.Caption] = b;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    InternalLogger.Log.Error("1234567890:" + ex.Message);
                                }
                            }
                        }
                        dbHelp.CopyDataTableToDB(ds.Tables[0], tempTableName);
                        Console.WriteLine("一次同步" + SynCode.ToString() + "结束,同步时间:"
                                          + item["EndTime"].ToString());
                    }
                }
                Console.WriteLine("全部同步" + SynCode.ToString() + "结束");
            }
            catch (Exception EX)
            {
                InternalLogger.Log.Error("从xmlcopy数据到数据库表出错:" + EX.Message);
            }
        }