Example #1
1
        //public string ExcelFile {private get; set; }
        public static DataTable ReadData(string excelFile)
        {
            if (!System.IO.File.Exists(excelFile))
                return null;

            OleDbConnection excelConnection = new OleDbConnection();
            excelConnection.ConnectionString = string.Format("Provider=Microsoft.Jet.OleDb.4.0;Data Source='{0}';Extended Properties='Excel 8.0;HDR=YES'", excelFile);
            excelConnection.Open();
            DataTable dtSchema = excelConnection.GetSchema("Tables");
            if (dtSchema.Rows.Count == 0)
                return null;

            string strTableName = dtSchema.Rows[0]["Table_Name"] as string;
            string strSQL = string.Format("select * from [{0}]", strTableName);
            OleDbCommand cmdSelect = excelConnection.CreateCommand();
            cmdSelect.CommandText = strSQL;
            OleDbDataAdapter dbAdapter = new OleDbDataAdapter(cmdSelect);
            DataTable dtResult=new DataTable();
            dbAdapter.Fill(dtResult);

            dbAdapter.Dispose();
            excelConnection.Close();
            excelConnection.Dispose();

            return dtResult;
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
            OleDbConnection con = new OleDbConnection(chaine);
            OleDbCommand cmd = con.CreateCommand();
            OleDbCommand cmd1 = con.CreateCommand();
            cmd.CommandText = "select cin from assiste where id_module=" + label1.Text + " group by cin";
          
            try
            {
                con.Open();
                OleDbDataReader dr = cmd.ExecuteReader();
        
                while (dr.Read())
                {
                    //dataGridView1.Rows.Add(dr.GetValue(0), dr.GetValue(2), dr.GetValue(3), dr.GetValue(4), dr.GetValue(0));
                    cmd1.CommandText="select nom,prenom from etudiant where cin="+dr.GetValue(0);
                    
                    try { OleDbDataReader dr1 = cmd1.ExecuteReader(); dr1.Read(); dataGridView1.Rows.Add(dr.GetValue(0), dr1.GetValue(0), dr1.GetValue(1),0); }
                    catch (Exception ex) { }
                    
                }
                dr.Close();
                con.Close();

            }
            catch (Exception ex) { MessageBox.Show("Erreur : " + ex.Message); con.Close(); }
        }
Example #3
0
    public void check_privillage()
    {
        string Select_SQL, Select_SQL2, Select_SQL3, Update_SQL1;
        OleDbConnection SqlConnection1 = new OleDbConnection();
        SqlConnection1.ConnectionString = AccessDataSource1.ConnectionString;
        Select_SQL = "select module_name,page_name,user_name from module_user_mng,user_mng,module_mng where module_mng.module_id = module_user_mng.module_id and user_mng.user_id = module_user_mng.user_id and page_name='" + System.IO.Path.GetFileName(Request.PhysicalPath) + "' and user_name='" + Session["xsctintranet"] + "'";

        SqlConnection1.Open();
        OleDbCommand SqlCommand = SqlConnection1.CreateCommand();
        SqlCommand.CommandText = Select_SQL;
        OleDbDataReader SqlDataReader = SqlCommand.ExecuteReader();
        if (SqlDataReader.HasRows)
        {
            while (SqlDataReader.Read())
            {
                OleDbCommand SqlCommand2 = SqlConnection1.CreateCommand();
                Update_SQL1 = "insert into visit_mng (visit_module_name,visit_user_name,visit_date,visit_ip,visit_module_page) VALUES ('" + SqlDataReader.GetString(0) + "','" + SqlDataReader.GetString(2) + "','" + DateTime.Now.ToString() + "','" + Page.Request.UserHostAddress + "','" + SqlDataReader.GetString(1) + "')";
                SqlCommand2.CommandText = Update_SQL1;
                SqlCommand2.ExecuteNonQuery();

            }
        }
        else
        {
            OleDbCommand SqlCommand2 = SqlConnection1.CreateCommand();
            Select_SQL2 = "select * from module_mng where page_name='" + System.IO.Path.GetFileName(Request.PhysicalPath) + "'";
            SqlCommand2.CommandText = Select_SQL2;
            OleDbDataReader SqlDataReader2 = SqlCommand2.ExecuteReader();
            if (SqlDataReader2.HasRows)
            {
                Response.Write("您没有访问该页面的权限!");
                SqlDataReader2.Close();
                SqlDataReader.Close();
                SqlConnection1.Close();
                Response.End();
            }
            else
            {
                OleDbCommand SqlCommand3 = SqlConnection1.CreateCommand();
                Select_SQL3 = "select * from user_mng where user_name='" + Session["xsctintranet"] + "'";
                SqlCommand3.CommandText = Select_SQL3;
                OleDbDataReader SqlDataReader3 = SqlCommand3.ExecuteReader();
                if (SqlDataReader3.HasRows)
                { }
                else
                {
                    Response.Write("您没有访问该页面的权限!");
                    SqlDataReader3.Close();
                    SqlDataReader2.Close();
                    SqlDataReader.Close();
                    SqlConnection1.Close();
                    Response.End();
                }
                SqlDataReader3.Close();
            }
            SqlDataReader2.Close();
        }
        SqlDataReader.Close();
        SqlConnection1.Close();
    }
Example #4
0
        public bool InsertFtpRecord(FileDetail fileDetail)
        {
            var lcsql =
                "insert into MasterFtp(FileName, CreateTime, Folder, Records, DlTime) values ( ?, ?,?,?,?)";


            var connectionString = ConfigurationManager.ConnectionStrings["vfpConnectionString"].ConnectionString;
            using (var connection = new OleDbConnection(connectionString))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SET NULL OFF";

                    command.ExecuteNonQuery();
                }
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = lcsql;
                    command.Parameters.AddWithValue("FileName", fileDetail.FileName);
                    command.Parameters.AddWithValue("CreateTime", fileDetail.FileDate);
                    command.Parameters.AddWithValue("Folder", fileDetail.Folder);
                    command.Parameters.AddWithValue("Records", fileDetail.Records);
                    command.Parameters.AddWithValue("DlTime", fileDetail.DownloadTime);

                    //connection.Open();
                    var retval = command.ExecuteNonQuery();
                    var success = (retval == 1);
                    return success;
                }
            }


        }
        private void button1_Click(object sender, EventArgs e)
        {
            
            string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
            OleDbConnection con = new OleDbConnection(chaine);
            OleDbCommand cmd = con.CreateCommand();
            OleDbCommand cmd1 = con.CreateCommand();

            cmd.CommandText = "Insert into etudiant values (" + Convert.ToInt32(txt_cin.Text) + ",'" + txt_nom.Text + "','" + txt_prenom.Text + "','" + comboBox1.Text + "')";
            

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("Ajout Module Réussi");
                con.Close();

                new acceuil(login).Show();
                this.Hide();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur" + ex.Message);
                con.Close();
            }



            //ckecked lisT 
             foreach(object itemChecked in checkedListBox1.CheckedItems) {
                 cmd1.CommandText = "Insert into assiste(cin,id_module,date_present) values(" + Convert.ToInt32(txt_cin.Text) + "," + hash[(string)itemChecked] + ",'" + DateTime.Now.ToString("dd-MM-yyyy") + "')";
                 try
                 {
                     con.Open();
                     cmd1.ExecuteNonQuery();
                     con.Close();


                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Erreur" + ex.Message);
                     con.Close();
                 }
             }





        }
        public static void CreateSyncTimestamp()
        {
            string DPDBLocation = Properties.Settings.Default.DPDBLocation;
            try
            {
                OleDbConnection DPDBconnection = null;

                DPDBconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=" + DPDBLocation);
                DPDBconnection.Open();

                OleDbCommand syncCmd = DPDBconnection.CreateCommand();

                string commandText = @"INSERT INTO Syncs (sync_datetime)
                                 VALUES (#$latestSync#)";

                commandText = commandText.Replace("$latestSync", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                //Save latest sync.
                syncCmd.CommandText = commandText;
                int numRowsAffected = syncCmd.ExecuteNonQuery();
                DPDBconnection.Close();
            }
            catch
            {
                throw;
            }
        }
        public List<InventoryPurchaseInfo> getAllInventoryPurchaseInfo()
        {
            List<InventoryPurchaseInfo> allInventoryPurchaseInfo = new List<InventoryPurchaseInfo>();
            using(OleDbConnection sqlconn = new OleDbConnection(database))
            {
                try
                {
                    sqlconn.Open();
                    OleDbCommand cmd = sqlconn.CreateCommand();

                    String select = "SELECT [inventory_item_id] FROM [INVENTORY_PURCHASE_INFO]";
                    cmd.CommandText = select;
                    OleDbDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        InventoryPurchaseInfo purchaseInfo = getSingleInventoryPurchaseInfo((int)reader["inventory_item_id"]);

                        allInventoryPurchaseInfo.Add(purchaseInfo);
                    }
                    return allInventoryPurchaseInfo;
                }
                catch (OleDbException ex)
                {
                    return allInventoryPurchaseInfo;
                }
                finally
                {
                    sqlconn.Close();
                }
            }
        }
Example #8
0
        public void update(string query)
        {
            OleDbConnection connection = new OleDbConnection();
            string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string path = (System.IO.Path.GetDirectoryName(executable));
            AppDomain.CurrentDomain.SetData("DataDirectory", path);
            connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/LMS.accdb";

            OleDbCommand command;
            command = connection.CreateCommand();
            try
            {
                command.CommandText = query;
                command.CommandType = CommandType.Text;
                connection.Open();
                //SqlCommand comm = new SqlCommand(query, connection);

                command.ExecuteNonQuery();

            }
            catch (Exception)
            {
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            
            string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
            OleDbConnection con = new OleDbConnection(chaine);
            OleDbCommand cmd = con.CreateCommand();
            cmd.CommandText = "update enseignant set mdp='" + txt_g_password.Text + "',nom=' "+txt_g_family.Text+"',prenom='"+txt_g_name.Text+"', grade='"+txt_g_grade.Text+"' where login='"+login+"'";
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("Modification Réussi");
                txt_g_password.Text = "";
                txt_g_family.Text = "";
                txt_g_name.Text = "";
                txt_g_grade.Text = "";
                con.Close();
                new acceuil(login).Show();
                this.Hide();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur" + ex.Message);
                con.Close();
            }
        }
Example #10
0
		internal override void LoadAll()
		{
			try
			{
				ISeriesDatabase database = (ISeriesDatabase)this.dbRoot.ClassFactory.CreateDatabase();
				//database._name = cn.DataSource;

				OleDbConnection cn = new OleDbConnection(this.dbRoot.ConnectionString); 
				cn.Open();
				OleDbCommand cmd = cn.CreateCommand();
				cmd.CommandText = "SELECT c.CATALOG_NAME, t.TABLE_SCHEMA FROM SYSTABLES t, QSYS2.SYSCATALOGS c";
				OleDbDataReader reader = cmd.ExecuteReader();
				while(reader.Read()) 
				{
					//database. = reader["CATALOG_NAME"].ToString();
					database._name = reader["TABLE_SCHEMA"].ToString();
					break;
				}
				reader.Close();
				cn.Close();
	
				database.dbRoot = this.dbRoot;
				database.Databases = this;
				this._array.Add(database);
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
		}
Example #11
0
 public static void Main()
 {
     String connect = "Provider=Microsoft.JET.OLEDB.4.0;"
       + @"data source=c:\booksharp\gittleman\ch15\Sales.mdb";
     OleDbConnection con = new OleDbConnection(connect);
     con.Open();
     Console.WriteLine
       ("Made the connection to the Sales database");
     OleDbCommand cmd = con.CreateCommand();
     cmd.CommandText = "SELECT * FROM Customer";
     OleDbDataReader reader = cmd.ExecuteReader();
     XmlDocument document = new XmlDocument();
     XmlElement customers = document.CreateElement("customers");
     document.AppendChild(customers);
     while (reader.Read()) {
       XmlElement customer = document.CreateElement("customer");
       customers.AppendChild(customer);
       XmlElement name = document.CreateElement("name");
       customer.AppendChild(name);
       name.AppendChild
        (document.CreateTextNode(reader.GetString(1)));
       XmlElement address = document.CreateElement("address");
       customer.AppendChild(address);
       address.AppendChild
        (document.CreateTextNode(reader.GetString(2)));
       XmlElement balance = document.CreateElement("balance");
       customer.AppendChild(balance);
       Decimal b = reader.GetDecimal(3);
       balance.AppendChild
                   (document.CreateTextNode(b.ToString()));
     }
     document.Save(Console.Out);
     reader.Close();
 }
Example #12
0
        public byte[] GetRommList()
        {
            try
            {
                string strConnection = ConfigurationManager.ConnectionStrings["DigiLock"].ConnectionString;
                OleDbConnection objConnection = new OleDbConnection(strConnection);
                objConnection.Open();//打开连接
                OleDbCommand odCommand = objConnection.CreateCommand();
                odCommand.CommandText = "SELECT ROOMNO,STATE,CARDQTY FROM ROOMLIST";
                OleDbDataReader reader = odCommand.ExecuteReader();
                List<RoomListModel> Roomlistmodel = new List<RoomListModel>();
                using (reader)
                {
                    while (reader.Read())
                    {
                        RoomListModel mRoom = new RoomListModel();
                        mRoom.State = dbh.ToString(reader["STATE"]);
                        mRoom.RoomNo = reader["RoomNo"].ToString().Substring(1, 3);
                        mRoom.CardQTY = dbh.ToInt32(reader["CARDQTY"]);
                        Roomlistmodel.Add(mRoom);
                    }
                    reader.Close();
                }
                objConnection.Close();
                return cmn.SerializeObject(Roomlistmodel);
            }
            catch (Exception err)
            {

                throw err;
            }
        }
Example #13
0
        public JsonResult changeProduct(string productName)
        {
            string allInfo = "";
            OleDbConnection conn1 = null;
            conn1 = new OleDbConnection(
            "Provider=Microsoft.Jet.OLEDB.4.0; " +
            "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~") + ("App_Data\\Products.mdb"));
            conn1.Open();
            OleDbDataReader dbReader1 = null;
            OleDbCommand cmd1 = conn1.CreateCommand();
            string allProductInfo = "SELECT * from Products where Products.product_name='" + productName + "';";
            cmd1.CommandText = allProductInfo;
            dbReader1 = cmd1.ExecuteReader();
            List<string> list = new List<string>();
            while (dbReader1.Read())
            {
                allInfo = "@" + (string)dbReader1.GetValue(1) + "@" + (string)dbReader1.GetValue(2) + "@" +
                    (string)dbReader1.GetValue(3) + "@" + (string)dbReader1.GetValue(4) + "@" +
                    (string)dbReader1.GetValue(5) + "@" + (string)dbReader1.GetValue(6);
                list.Add(allInfo);
                allInfo = "";
            }
            dbReader1.Close();
            list.Reverse();
            list.Insert(0, list.Count.ToString());
            conn1.Close();

            return Json(list, JsonRequestBehavior.AllowGet);
        }
Example #14
0
 /// <summary>
 /// 获取inpno
 /// </summary>
 /// <param name="p_strPatientId"></param>
 /// <param name="p_strVisitId"></param>
 /// <returns></returns>
 public string GetInpNo(string p_strPatientId, string p_strVisitId)
 {
     DataSet _dsR = new DataSet();
     string _strSQL = string.Format("select inp_no from pat_master_index where patient_id = '{0}'", p_strPatientId);
     ConnectionStringSettings sEmr = ConfigurationManager.ConnectionStrings["EMRConnectionString"];
     using (OleDbConnection connEMR = new OleDbConnection(sEmr.ConnectionString))
     {
         try
         {
             connEMR.Open();
             OleDbCommand cmdEMR = connEMR.CreateCommand();
             OleDbDataAdapter daEMR = new OleDbDataAdapter();
             cmdEMR.CommandText = _strSQL;
             daEMR.SelectCommand = cmdEMR;
             daEMR.Fill(_dsR);
             if (_dsR.Tables[0].Rows.Count == 1)
             {
                 return _dsR.Tables[0].Rows[0]["inp_no"].ToString();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     return "";
 }
Example #15
0
        /// <summary>
        /// Read the specified Excel file and returns the content
        /// </summary>
        /// <param name="excelFile"></param>
        /// <returns></returns>
        public DataTable Read(string excelFile)
        {
            string connectionString = string.Empty;

            string fileExtension = Path.GetExtension(excelFile);
            if (fileExtension == ".xls")
            {
                connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";" + "Extended Properties='Excel 8.0;HDR=YES;'";
            }
            else if (fileExtension == ".xlsx")
            {
                connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'";
            }

            using (var conn = new OleDbConnection(connectionString))
            {
                conn.Open();

                using (OleDbCommand command = conn.CreateCommand())
                {
                    DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    string sheetName = dtSheet.Rows[0]["TABLE_NAME"].ToString();

                    command.CommandText = string.Format("SELECT * FROM [{0}]", sheetName);

                    using (OleDbDataAdapter da = new OleDbDataAdapter(command))
                    {
                        var dt = new DataTable();

                        da.Fill(dt);
                        return dt;
                    }
                }
            }
        }
        public int product_service(string service_id, string product_id, int customer_id)
        {
            int row=0;

               cn = new OleDbConnection("Provider=MSDAORA;Data Source=192.168.0.217/orcl;Persist Security Info=True;User ID=hr;Password=hr;");

            cmd = cn.CreateCommand();
            try
            {
                cn.Open();

                string s = "update product_services set product_id='" + product_id + "' where service_id=(select service_id from customer_services where customer_id=" + customer_id + " and service_id='" + service_id + "')";
                Trans = cn.BeginTransaction();
                cmd = new OleDbCommand(s, cn,Trans);
                cmd.Transaction = Trans;
                row= cmd.ExecuteNonQuery();
                Trans.Commit();

            }
            catch (Exception e)
            {
                string s = e.Message;
                Trans.Rollback();
            }
            finally
            {
                cn.Close();
            }
            return row;
        }
Example #17
0
        /// <summary>
        /// Button НОВАЯ ПОЗИЦИЯ clicked
        /// </summary>
        /// <param name="sender">Button1 control</param>
        /// <param name="e">Event arguments</param>
        private void button1_Click(object sender, EventArgs e)
        {
            using (OleDbConnection dbConnect = new OleDbConnection(connectionString))
            {
                OleDbCommand command = dbConnect.CreateCommand();
                //
                // To create a new empty row we insert empty values except of id which is AUTOINCREMENTed
                //
                command.CommandText = "insert into data (name, description, link, categories) values ('','','','')";
                try
                {
                    dbConnect.Open();
                    command.ExecuteNonQuery();
                    dataGridView1.DataSource = connectionString;
                    dataGridView1.Refresh();
                    dbConnect.Close();
                }

                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);

                }

            }
            ShowData();
        }
Example #18
0
        public void BumpNamedCounter(string sCounter)
        {
            int c = GetNamedCounter(sCounter);

            c++;

            OleDbConnection oConn = new OleDbConnection(m_sCounterConnString);

            m_page.Trace.Write("Connect=" + oConn.ConnectionString);
            oConn.Open();

            OleDbCommand oCmd = oConn.CreateCommand();
            string sCmd;
            if (c == 0)
                {
                sCmd = "INSERT INTO Counters (CounterName, [Count]) VALUES ('" + sCounter + "', 0)";
                }
            else
                {
                sCmd = "UPDATE Counters SET [Count] = " + c.ToString() + " WHERE CounterName = '" + sCounter +"'";
                }

            m_page.Trace.Write("command: "+sCmd);
            oCmd.CommandText = sCmd;
            oCmd.ExecuteNonQuery();

            oCmd = null;
            oConn.Close();
        }
        public List<AccessLevel> getAllAccessLevels()
        {
            List<AccessLevel> allAccessLevels = new List<AccessLevel>();
            using (OleDbConnection sqlconn = new OleDbConnection(database))
            {
                try
                {
                    sqlconn.Open();
                    OleDbCommand cmd = sqlconn.CreateCommand();

                    String select = "SELECT * FROM [ACCESS_LEVEL]";
                    cmd.CommandText = select;

                    OleDbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        AccessLevel accessLevel = new AccessLevel();
                        accessLevel.setLevel(reader["level"].ToString());
                        accessLevel.setID((int)reader["ID"]);
                        allAccessLevels.Add(accessLevel);
                    }
                    return allAccessLevels;
                }
                catch (OleDbException ex)
                {
                    return allAccessLevels;
                }
                finally
                {
                    sqlconn.Close();
                }
            }
        }
Example #20
0
        private static void RunSqlQueryReturnValue(string queryText, Dictionary<string, object> parametters, CommandType commandType, Action<OleDbDataReader> action, string connectionString)
        {
            using (OleDbConnection oConn = new OleDbConnection(connectionString))
            {
                using (OleDbCommand oRS = oConn.CreateCommand())
                {
                    oConn.Open();
                    oRS.CommandType = commandType;
                    oRS.CommandText = queryText;
                    if (parametters != null && parametters.Count > 0)
                    {
                        foreach (var parametter in parametters)
                        {
                            oRS.Parameters.AddWithValue(parametter.Key, parametter.Value);
                        }
                    }

                    OleDbDataReader rdr = oRS.ExecuteReader(CommandBehavior.CloseConnection);
                    if (action != null)
                    {
                        action(rdr);
                    }
                }
            }
        }
Example #21
0
//刷新
        private void Btn_Review_Click(object sender, EventArgs e)
        {
            SeedList.Items.Clear();
            OleDbConnection odcConnection = new OleDbConnection(strConn);
                odcConnection.Open();
                OleDbCommand odCommand = odcConnection.CreateCommand();
                odCommand.CommandText = "select id,employee_dept,employee_name,employee_no,award_flag from Seedlist order by id asc";
                  OleDbDataReader odrReader = odCommand.ExecuteReader();
                  while (odrReader.Read())
                  {
                      ListViewItem li = new ListViewItem();
                      li.SubItems.Clear();
                      li.SubItems[0].Text = odrReader[0].ToString();
                      li.SubItems.Add(odrReader[1].ToString());
                      li.SubItems.Add(odrReader[2].ToString());
                      li.SubItems.Add(odrReader[3].ToString());
                      li.SubItems.Add(odrReader[4].ToString());
                      SeedList.Items.Add(li);
                  }
                  odrReader.Close();
                  odCommand.CommandText = "select count(*) as result from seedlist";
                  OleDbDataReader odrCount = odCommand.ExecuteReader();
                  odrCount.Read();
                  LabInfo.Text = "当前系统中共有待抽奖人员 " + odrCount[0].ToString() + " 人";
                  odrCount.Close();
                  odCommand.CommandText = "select count(*) as result from seedlist where award_flag = '1'";
                  odrCount = odCommand.ExecuteReader();
                  odrCount.Read();
                  LabInfo.Text += ",其中已中奖人员 " + odrCount[0].ToString() + " 人";
                  odrCount.Close();
                  odcConnection.Close();
        }
Example #22
0
		public void setup ()
		{
			if (Directory.Exists (_dataDir))
				Directory.Delete (_dataDir, true);

			string initSql = @"CREATE TABLE Table1 (
				UserId                                  int                 NOT NULL PRIMARY KEY,
				UserName                                varchar(256)        NOT NULL,
				Description                             varchar(256)
			)";

			OleDbConnection connection = new OleDbConnection (_connectionString);
			try {
				connection.Open ();
				DbCommand cmd = connection.CreateCommand ();
				cmd.CommandText = initSql;
				cmd.CommandType = CommandType.Text;
				cmd.ExecuteNonQuery ();
			}
			catch (Exception) {
			}
			finally {
				connection.Close ();
			}
		}
Example #23
0
 private void FrmMain_Load(object sender, EventArgs e)
 {
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
     string strPath = System.IO.Directory.GetCurrentDirectory() + BGimage;
     this.BackgroundImage = Image.FromFile(strPath);
     BtnStart.Image = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + "\\images\\btn_start.png");
     //从数据库里读出所有可抽奖人员
     OleDbConnection odcConnection = new OleDbConnection(strConn);
     odcConnection.Open();
     OleDbCommand odCommand = odcConnection.CreateCommand();
     odCommand.CommandText = "select count(*) as result from seedlist";
     OleDbDataReader odrCount = odCommand.ExecuteReader();
     odrCount.Read();
     int allcount = Int32.Parse(odrCount[0].ToString());
     odrCount.Close();
     if (allcount < 9)
     {
         odcConnection.Close();
         MessageBox.Show("可供抽奖的人数不足,无法抽奖");
         this.Close();
     }
     else
     {
         //读取所有记录到数据
         SeedsList.Items.Clear();
         odCommand.CommandText = "select id,employee_dept,employee_name,employee_no from Seedlist where award_flag = '0' order by id asc";
         OleDbDataReader odrReader = odCommand.ExecuteReader();
         while (odrReader.Read())
         {
             SeedsList.Items.Add(odrReader[0].ToString() + ";" + odrReader[1].ToString() + ";" + odrReader[2].ToString() + ";" + odrReader[3].ToString());
         }
         odrReader.Close();
         odcConnection.Close();
     }           
 }
        public List<ConsultaDocumentoDistribuicao> ConsultaDocumentoDistribuicao(int codigo)
        {
            var result = new List<ConsultaDocumentoDistribuicao>();
            using (var cnx = new OleDbConnection(ConfigurationManager.ConnectionStrings["banco"].ConnectionString))
            using (var cmd = cnx.CreateCommand())
            {
                cnx.Open();
                cmd.CommandText = "Select Codigo, documentodistribuicao, item, material, quantidade, desativado From lc_status_itemdoc_dist where codigo = '" + codigo.ToString() +"'";

                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var item = new ConsultaDocumentoDistribuicao();
                    item.Codigo = (string)reader["codigo"];
                    item.DocumentoDistribuicao = (int)reader["documentodistribuicao"];
                    item.Item = (int)reader["item"];
                    item.Material = (int)reader["material"];
                    item.Quantidade = (Decimal)reader["quantidade"];
                    item.Ativo = (string)reader["desativado"];
                    result.Add(item);
                }
            }

            return result;
        }
Example #25
0
        /// <summary>
        /// Determines if the server can be connected to
        /// </summary>
        /// <param name="connString"></param>
        /// <returns></returns>
        protected internal static bool CanConnect(string connString)
        {
            bool connect = false;

            try
            {
                using (OleDbConnection connection = new OleDbConnection(connString))
                {
                    connection.Open();

                    using (OleDbCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "Select count(*) from sysdba.Account";
                        command.ExecuteScalar();

                        connect = true;
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Cannot connect to the underlying database");
            }

            return connect;
        }
        public int getUserAccessLevel(int userId)
        {
            int accessLevel = -1;

            using (OleDbConnection sqlconn = new OleDbConnection(database))
            {
                try
                {
                    sqlconn.Open();
                    OleDbCommand cmd = sqlconn.CreateCommand();

                    string select = "SELECT [access_level] FROM [USERS] WHERE [user_id] = @userId";
                    cmd.CommandText = select;
                    cmd.Parameters.Add("userId", OleDbType.VarChar, 255).Value = userId;

                    OleDbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        accessLevel = (int)reader["access_level"];
                    }
                    return accessLevel;
                }
                catch (OleDbException ex)
                {
                    return accessLevel;
                }
                finally
                {
                    sqlconn.Close();
                }
            }
        }
        public List<Abastecimento> ListarAbastecimento()
        {
            var result = new List<Abastecimento>();
            using (var cnx = new OleDbConnection(ConfigurationManager.ConnectionStrings["banco"].ConnectionString))
            using (var cmd = cnx.CreateCommand())
            {
                cnx.Open();
                cmd.CommandText = "Select Codigo, motorista, quantidade, hodometro, distribuicao, autorizacao, tipo, local, terminal, observacao, datahora, ativo from abastecimento order by codigo ";

                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var item = new Abastecimento();
                    item.Codigo = (int)reader["codigo"];
                    item.Motorista = (int)reader["motorista"];
                    item.Quantidade = (decimal)reader["quantidade"];
                    item.Hodometro = (int)reader["hodometro"];
                    item.Distribuicao = (int)reader["distribuicao"];
                    item.Autorizacao = (string)reader["autorizacao"];
                    item.Tipo = (int)reader["tipo"];
                    item.Local = (int)reader["local"];
                    item.Terminal = (int)reader["terminal"];
                    item.DataHora = (DateTime)reader["datahora"];
                    item.Ativo = (int)reader["ativo"];
                    item.Observacao = Convert.IsDBNull(reader["observacao"]) ? "" : (string)reader["observacao"];
                    result.Add(item);
                }
            }

            return result;
        }
Example #28
0
//刷新
        private void Btn_Review_Click(object sender, EventArgs e)
        {
            SeedList.Items.Clear();
             string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.IO.Directory.GetCurrentDirectory() + "\\database\\SeedData.mdb;";
                OleDbConnection odcConnection = new OleDbConnection(strConn);
                odcConnection.Open();
                OleDbCommand odCommand = odcConnection.CreateCommand();
                odCommand.CommandText = "select id,award,employee_dept,employee_name,employee_no from Awardlist order by id asc";
                  OleDbDataReader odrReader = odCommand.ExecuteReader();
                  while (odrReader.Read())
                  {
                      ListViewItem li = new ListViewItem();
                      li.SubItems.Clear();
                      li.SubItems[0].Text = odrReader[0].ToString();
                      li.SubItems.Add(odrReader[1].ToString());
                      li.SubItems.Add(odrReader[2].ToString());
                      li.SubItems.Add(odrReader[3].ToString());
                      li.SubItems.Add(odrReader[4].ToString());
                      SeedList.Items.Add(li);
                  }
                  odrReader.Close();
                  odCommand.CommandText = "select count(*) as result from Awardlist ";
                  OleDbDataReader odrCount = odCommand.ExecuteReader();
                  odrCount.Read();
                  LabInfo.Text = "中奖人员共 " + odrCount[0].ToString() + " 人";
                  odrCount.Close();
                  odcConnection.Close();
        }       
		public void Write(LogEntry entry)
		{
			using (OleDbConnection conn = new OleDbConnection(connStr))
			{
				using (OleDbCommand cmd = conn.CreateCommand()) 
				{
					cmd.CommandText = @"
						INSERT INTO [Request]
						(Date, Method, URL, Referral, ASPNETSessionID, UserHost, UserAddress, UserAgent)
						VALUES
						(@Date, @Method, @URL, @Referral, @ASPNETSessionID, @UserHost, @UserAddress, @UserAgent)
					";

					cmd.Parameters.Add("@Date", entry.Date);
					cmd.Parameters.Add("@Method", entry.Method);
					cmd.Parameters.Add("@URL", Convert.ToString(entry.Url));
					cmd.Parameters.Add("@Referral", Convert.ToString(entry.Referral));
					cmd.Parameters.Add("@ASPNETSessionID", entry.ASPNETSessionID);
					cmd.Parameters.Add("@UserHost", entry.UserHost);
					cmd.Parameters.Add("@UserAddress", entry.UserAddress);
					cmd.Parameters.Add("@UserAgent", entry.UserAgent);

					conn.Open();
					cmd.ExecuteNonQuery();
				}
			}
		}
Example #30
0
        public static DataTable LoadMDB(FileInfo file, string tableName)
        {
            string myConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
                               "Data Source={0};" +
                               "Persist Security Info=True;" +
                               "Jet OLEDB:Database Password=myPassword;", file.FullName);
            try
            {
                // Open OleDb Connection
                using (OleDbConnection myConnection = new OleDbConnection(myConnectionString))
                {
                    myConnection.Open();

                    // Execute Queries
                    using (OleDbCommand cmd = myConnection.CreateCommand())
                    {
                        cmd.CommandText = string.Format("SELECT * FROM `{0}`", tableName);
                        using (OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            // Load the result into a DataTable
                            DataTable myDataTable = new DataTable();
                            myDataTable.Load(reader);
                            return myDataTable;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("OLEDB Connection FAILED: " + ex.Message);
                return null;
            }
        }