Example #1
0
        internal static int GetApplicationID(OleDbConnection connection, string applicationName, bool createIfNeeded)
        {
            OleDbCommand lookupCommand = new OleDbCommand("SELECT ApplicationId FROM aspnet_Applications WHERE ApplicationName = @AppName", connection);
            lookupCommand.Parameters.Add(new OleDbParameter("@AppName", applicationName));

            object lookupResult = lookupCommand.ExecuteScalar();
            if ((lookupResult != null) && (lookupResult is int)) {
                return (int)lookupResult;
            }

            if (createIfNeeded) {
                OleDbCommand createCommand = new OleDbCommand("INSERT INTO aspnet_Applications (ApplicationName) VALUES (@AppName)",
                    connection);
                createCommand.Parameters.Add(new OleDbParameter("@AppName", applicationName));

                if (createCommand.ExecuteNonQuery() != 0) {
                    lookupResult = lookupCommand.ExecuteScalar();
                    if ((lookupResult != null) && (lookupResult is int)) {
                        return (int)lookupResult;
                    }
                }
            }

            return 0;
        }
Example #2
0
    public bool DoLogin(string username, string password, bool IsAdmin)
    {
        OleDbCommand com = new OleDbCommand("", MySchool.SLConnection);
        bool ReturnMe = false;
        if (IsAdmin)
            com.CommandText = "select UID, UPass from LoginInfo where UName = '" + username + "' and UPass = '" + password + "'";
        else
            com.CommandText = "select UID, pass from UserInfo where UserName = '" + username + "' and Pass ='" + password + "'";

        com.Connection.Open();

        if (com.ExecuteScalar() != null)
        {
            if (IsAdmin)
            {
                TheSessions.EmploeeID = com.ExecuteScalar().ToString();
                TheSessions.EmploeeName = username;
                TheSessions.IsAdmin = true;
            }
            else
            {
                TheSessions.StudentID = com.ExecuteScalar().ToString();
                TheSessions.StudentName = username;
                TheSessions.IsAdmin = false;
            }
            ReturnMe = true;
        }
        else
            ReturnMe = false;

        com.Connection.Close();
        return ReturnMe;
    }
Example #3
0
  public static bool FormsAuthenticate(string userName, string password)
  {
    bool authenticated = false;

    switch (Mode)
    {
      case AuthenticationMode.None:
        authenticated = FormsAuthentication.Authenticate(userName, password);
        break;

      case AuthenticationMode.Database:
        using (OleDbConnection connection = AppContext.GetDatabaseConnection())
        {
          string format = String.Format("select count(*) from {0}User where UserName = '{1}' and Password = '{{0}}' and Active = 1", AppSettings.ConfigurationTablePrefix, userName);

          using (OleDbCommand command = new OleDbCommand(String.Format(format, password), connection))
          {
            authenticated = Convert.ToInt32(command.ExecuteScalar()) > 0;

            if (!authenticated)
            {
              command.CommandText = String.Format(format, HashPassword(password));
              authenticated = Convert.ToInt32(command.ExecuteScalar()) > 0;
            }
          }
        }
        break;
    }

    return authenticated;
  }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //TheSessions.StudentID = "494108";

        DataTable DT = new DataTable("ReadedBooks");
        OleDbConnection AccessCon = MySchool.LibraryCodeConnection;
        OleDbCommand AccessCMD = new OleDbCommand("", AccessCon);
        try
        {
            if (TheSessions.StudentID != null)
            {
                OleDbDataAdapter AccessDA = new OleDbDataAdapter("SELECT motaraded.[number], book.name_book, motaraded.[date], book.code_printl, '' As name_printl, book.code_fari, '' As name_fari, book.code_tahasos, '' As name_tahasos, book.code_alnasher, '' As name_alnasher, (SELECT TOP 1 fm1 + ' ' + lm1 AS msl FROM masol WHERE ([number] = book.[number]) AND (k1 = 'مؤلف')) As masol FROM (motaraded INNER JOIN book ON motaraded.[number] = book.[number]) WHERE (motaraded.code_name = " + TheSessions.StudentID + ")", MySchool.LibraryConnection);
                AccessDA.Fill(DT);
            }

            AccessCon.Open();
            foreach (DataRow DR in DT.Rows)
            {
                if (DR["code_printl"].ToString() != string.Empty)
                {
                    AccessCMD.CommandText = "Select name_printl from printl Where code_printl = " + DR["code_printl"].ToString();
                    DR["name_printl"] = AccessCMD.ExecuteScalar();
                }
                else { DR["name_printl"] = string.Empty; }

                if (DR["code_fari"].ToString() != string.Empty)
                {
                    AccessCMD.CommandText = "Select name_fari from fari Where code_fari = " + DR["code_fari"].ToString();
                    DR["name_fari"] = AccessCMD.ExecuteScalar();
                }
                else
                { DR["name_fari"] = string.Empty; }
                if (DR["code_tahasos"].ToString() != string.Empty)
                {
                    AccessCMD.CommandText = "Select name_tahasos from tahasos Where code_tahasos = " + DR["code_tahasos"].ToString();
                    DR["name_tahasos"] = AccessCMD.ExecuteScalar();
                }
                else
                { DR["name_tahasos"] = string.Empty; }
                if (DR["code_alnasher"].ToString() != string.Empty)
                {
                    AccessCMD.CommandText = "Select name_alnasher from alnasher Where code_alnasher = " + DR["code_alnasher"].ToString();
                    DR["name_alnasher"] = AccessCMD.ExecuteScalar();
                }
                else
                { DR["name_alnasher"] = string.Empty; }
            }
            AccessCon.Close();

            GridViewReadedBooks.DataSource = DT;
            ViewState["ReadedBooksTable"] = DT;
            GridViewReadedBooks.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }
    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                System.Data.OleDb.OleDbConnection conn = new
                       System.Data.OleDb.OleDbConnection();
                conn.ConnectionString = @"Provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;" +
                                        @"Data source= C:\Users\Ahmed Kamel Taha\Documents\Visual Studio 2015\Projects\ASP Training\bns.accdb";
                conn.Open();
                string q = "select count(*) from users where name='" + TextBox1.Text + "' And password='"+ TextBox2.Text+"';";
                OleDbCommand comm = new OleDbCommand(q, conn);

                if (Convert.ToInt32(comm.ExecuteScalar().ToString()) == 1)
                {
                    Session["user"] = TextBox1.Text;


                    Response.Redirect("index.aspx");
   
                }
                else
                {
                    Response.Write("<script> alert(\"wrong pass or user\"); </script>");

                }
                conn.Close();

            }catch(Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
Example #6
0
 public static int InsertIntoOringalTransaction(BankAccount bankAccount, Transaction transaction, string categoryName)
 {
     string cmdText = "INSERT INTO tblOrginalTransaction(";
     cmdText += "Verified, TransactionID, TransactionDate, TransactionAmount, Merchant, BankMemo, BankAccountId, TransactionType";
     if (!string.IsNullOrEmpty(transaction.CheckNumber))
         cmdText += ", CheckNumber";
     if (categoryName != "")
         cmdText += ", CategoryName";
     cmdText += ") Values(";
     cmdText += "false";
     cmdText += ", '" + transaction.TransactionID + "'";
     cmdText += ", #" + Convert.ToString(transaction.TransactionDate) + "#";
     cmdText += ", " + Convert.ToString(transaction.TransactionAmount);
     cmdText += ", '" + transaction.MerchantName.Replace(@"'", "''") + "'";
     cmdText += ", '" + transaction.BankMemo.Replace(@"'", "''") + "'";
     cmdText += ", " + Convert.ToString(bankAccount.BankAccountID);
     cmdText += ", '" + transaction.TransactionType + "'";
     if (!string.IsNullOrEmpty(transaction.CheckNumber))
         cmdText += ", '" + transaction.CheckNumber + "'";
     if (categoryName != "")
         cmdText += ", '" + categoryName + "'";
     cmdText += ")";
     string identity = " SELECT @@Identity";
     int orginalTransactionID;
     using (OleDbConnection myConnection = new OleDbConnection(
     ConfigurationManager.ConnectionStrings["BeanCounterDB"].ToString()))
     {
         myConnection.Open();
         using (OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection))
             myCommand.ExecuteNonQuery();
         using (OleDbCommand myCommand = new OleDbCommand(identity, myConnection))
             orginalTransactionID = Convert.ToInt32(myCommand.ExecuteScalar().ToString());
     }
     return orginalTransactionID;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        string query = this.Request.QueryString.ToString();
        int index = query.IndexOf('=');
        query = query.Substring(index + 1);
        int FlatID = Convert.ToInt32(query);

        string UserName;

        OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["RealEstate"].ConnectionString);
        OleDbCommand cmd = new OleDbCommand(String.Format("SELECT UserName FROM Flats WHERE FlatID = {0}", FlatID), conn);
        cmd.Connection = conn;

        conn.Open();
        UserName = cmd.ExecuteScalar().ToString();
        conn.Close();

        if (this.User.Identity.Name == UserName || this.User.IsInRole("Manager") || this.User.IsInRole("Operator"))
        {
            this.ButtonDeleteRecord.Visible = true;
        }
        else
        {
            this.ButtonDeleteRecord.Visible = false;
        }
    }
 public static int? isStudentRegistered(int? sessionID, int? year, int? term, int? stdID)
 {
     OleDbConnection connection = new OleDbConnection(global::ResultManagement.Properties.Settings.Default.ConnectionString);
     int? Registered_Session_ID = null;
     string cmdStr = @"SELECT Registered_Session.ID
                     FROM Registered_Session
                     WHERE
                     Std_ID = @Std_ID AND
                     Sess_ID = @Sess_ID AND
                     Reg_Year = @Reg_Year AND
                     Reg_Term = @Reg_Term";
     OleDbCommand cmd = new OleDbCommand(cmdStr, connection);
     cmd.Parameters.Add("@Std_ID", OleDbType.Integer).Value = stdID;
     cmd.Parameters.Add("@Sess_ID", OleDbType.Integer).Value = sessionID;
     cmd.Parameters.Add("@Reg_Year", OleDbType.Integer).Value = year;
     cmd.Parameters.Add("@Reg_Term", OleDbType.Integer).Value = term;
     try
     {
         connection.Open();
         Registered_Session_ID = (int?)cmd.ExecuteScalar();
     }
     finally
     {
         connection.Close();
     }
     return Registered_Session_ID;
 }
		public void run()
		{
			OleDbConnection con = null;
			OleDbTransaction txn;
			Exception exp = null;
			try
			{
				BeginCase("OleDbTransaction Rollback");

				//
				//prepare data
				base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);

				string Result = "";
				con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
				con.Open();
				txn = con.BeginTransaction();
				OleDbCommand cmd = new OleDbCommand("Update Employees Set LastName = 'StamLastName' Where EmployeeID = 100", con, txn);
				cmd.ExecuteNonQuery();
				txn.Rollback();

				//
				//
				cmd = new OleDbCommand("Select LastName From Employees Where EmployeeID = 100", con);
				Result = cmd.ExecuteScalar().ToString();
				Compare(Result,"Last100" );
				this.Log(Result);

			} 
			catch(Exception ex){exp = ex;}
			finally{EndCase(exp); exp = null;}

			if (con.State == ConnectionState.Open) con.Close();
		}
Example #10
0
  private static string GetRole(OleDbConnection connection)
  {
    IPrincipal user = HttpContext.Current.User;
    string role = "public";

    if (user.Identity != null && user.Identity.IsAuthenticated)
    {
      if (AppAuthentication.Mode == AuthenticationMode.None)
      {
        role = "admin";
      }
      else
      {
        string sql = String.Format("select Role from {0}User where UserName = '{1}' and Role is not null",
            AppSettings.ConfigurationTablePrefix, user.Identity.Name);
        OleDbCommand command = new OleDbCommand(sql, connection);
        role = command.ExecuteScalar() as string;

        if (String.IsNullOrEmpty(role))
        {
          role = "private";
        }
      }
    }

    return role;
  }
Example #11
0
 public string LoadContain()
 {
     if (QAMainMenu.SelectedValue == "")
     {
         return "";
     }
     string ThePath = string.Empty;
     string RetData = string.Empty;
     OleDbConnection Con = MySchool.QAConnection;
     OleDbCommand CMD = new OleDbCommand("SELECT Data_Path FROM QAMenu WHERE (QAID = " + QAMainMenu.SelectedValue.ToString() + ")", Con);
     try
     {
         Con.Open();
         ThePath = CMD.ExecuteScalar().ToString();
         if (ThePath != string.Empty)
         {
             ThePath = MapPath(ThePath);
         }
         if (File.Exists(ThePath))
         {
             TextReader TR = new StreamReader(ThePath);
             RetData = TR.ReadToEnd();
         }
     }
     catch (Exception ex)
     {
         RetData = ex.Message;
     }
     Con.Close();
     return RetData;
 }
Example #12
0
        public static int Add(SachDto sach)
        {
            OleDbConnection cn;
            cn = DataProvider.ConnectionData();

            string strSQL;
            strSQL = "Insert into Sach(TenSach,LoaiSach,TacGia,TrangThai,SoTrang,NgonNgu) values (?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@TenSach", OleDbType.WChar);
            cmd.Parameters.Add("@LoaiSach", OleDbType.Integer);
            cmd.Parameters.Add("@TacGia", OleDbType.WChar);
            cmd.Parameters.Add("@TrangThai", OleDbType.Boolean);
            cmd.Parameters.Add("@SoTrang", OleDbType.Integer);
            cmd.Parameters.Add("@NgonNgu", OleDbType.Integer);
            cmd.Parameters["@TenSach"].Value = sach.TenSach;
            cmd.Parameters["@LoaiSach"].Value = sach.LoaiSach;
            cmd.Parameters["@TacGia"].Value = sach.TacGia;
            cmd.Parameters["@TrangThai"].Value = sach.TrangThai;
            cmd.Parameters["@SoTrang"].Value = sach.SoTrang;
            cmd.Parameters["@NgonNgu"].Value = sach.NgonNgu;

            cmd.ExecuteNonQuery();
            strSQL = "Select @@IDENTITY";
            cmd = new OleDbCommand(strSQL, cn);
            sach.MSach = (int)cmd.ExecuteScalar();
            cn.Close();
            return sach.MSach;
        }
Example #13
0
        public string ExecuteScalar(string sql)
        {
            try
            {
                using (OleDbConnection connection = new OleDbConnection(_ConnectionString))
                {

                    WriteLog(sql);
                    connection.Open();
                    var cmd = new OleDbCommand(sql, connection);
                    object o = cmd.ExecuteScalar();

                    string s = null;
                    if (o != null && Object.Equals(o, System.DBNull.Value) == false)
                    {
                        s = o.ToString();
                    }

                    WriteLog("查询结果:" + s);

                    return s;
                }
            }
            catch (Exception ex)
            {
                if (AfterExceptionThrow != null) AfterExceptionThrow(ex);
                else throw ex;
                return null;
            }
        }
Example #14
0
        public static long fcnGetIRRegCount()
        {
            //get current count of web registrations

            string strSQL;

            long lngRes = 0;

            using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn))
            {
                conDB.Open();

                strSQL = "SELECT Count(lngRegistrationWebID) AS lngRegCount " +
                        "FROM tblWebIndRegistrations;";

                using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB))
                {
                    try { lngRes = Convert.ToInt32(cmdDB.ExecuteScalar()); }
                    catch { lngRes = 0; }
                }

                conDB.Close();
            }

            return lngRes;
        }
        public static int GetCount()
        {
            OleDbConnection dbConnection;
            OleDbCommand dbCommand;
            object obj;
            string buff;
            int result = 0;

            try
            {
                dbConnection = new OleDbConnection(ConnectionStringsManager.GetConnectionString());
                dbCommand = new OleDbCommand(_SELECT_COUNT, dbConnection);

                dbConnection.Open();

                try
                {
                    obj = dbCommand.ExecuteScalar();
                    buff = obj.ToString();

                    Int32.TryParse(buff, out result);
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return result;
        }
Example #16
0
 public string selectOne(string q)
 {
     OleDbCommand cmd = new OleDbCommand(q, connection);
     object o = cmd.ExecuteScalar();
     if (o == null) return "";
     else return o.ToString();
 }
Example #17
0
 public int getid()
 {
     int z=0;
     OleDbCommand cmd = new OleDbCommand("Select max(t_id) from [transaction]",con);
     try
     {
         con.Open();
         object a = cmd.ExecuteScalar();
         if (a == DBNull.Value)
         {
             z = 1;
         }
         else
         {
             z = (int)a + 1;
         }
     }
     catch (Exception)
     {
         return -1;
     }
     finally
     {
         con.Close();
     }
     return z;
 }
Example #18
0
 public void AccessGuideJoinExcel(string Access, string AccTable, string Excel)
 {
     try
     {
         string tem_sql = "";//定义字符串
         string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Access + ";Persist Security Info=True";//记录连接Access的语句
         System.Data.OleDb.OleDbConnection tem_conn = new System.Data.OleDb.OleDbConnection(connstr);//连接Access数据库
         System.Data.OleDb.OleDbCommand tem_comm;//定义OleDbCommand类
         tem_conn.Open();//打开连接的Access数据库
         tem_sql = "select Count(*) From " + AccTable;//设置SQL语句,获取记录个数
         tem_comm = new System.Data.OleDb.OleDbCommand(tem_sql, tem_conn);//实例化OleDbCommand类
         int RecordCount = (int)tem_comm.ExecuteScalar();//执行SQL语句,并返回结果
         //每个Sheet只能最多保存65536条记录。
         tem_sql = @"select top 65535 * into [Excel 8.0;database=" + Excel + @".xls].[Sheet2] from 帐目";//记录连接Excel的语句
         tem_comm = new System.Data.OleDb.OleDbCommand(tem_sql, tem_conn);//实例化OleDbCommand类
         tem_comm.ExecuteNonQuery();//执行SQL语句,将数据表的内容导入到Excel中
         tem_conn.Close();//关闭连接
         tem_conn.Dispose();//释放资源
         tem_conn = null;
         MessageBox.Show("导入完成");
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message,"提示!");
     }
 }
        public frmCollectRefundAmt(long _lngGGCCRegistrationWebID)
        {
            InitializeComponent();

            string strSQL = "";

            using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn))
            {
                conDB.Open();

                strSQL = "SELECT curDeposit " +
                        "FROM tblWebGGCCRegistrations " +
                        "WHERE lngGGCCRegistrationWebID=" + _lngGGCCRegistrationWebID.ToString();

                using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB))
                {
                    decimal decDeposit = 0;

                    try { decDeposit = Convert.ToDecimal(cmdDB.ExecuteScalar()); }
                    catch { decDeposit = 0; }

                    lblDeposit.Text = decDeposit.ToString("C");

                    txtAmt.Text = decDeposit.ToString();
                }

                conDB.Close();
            }
        }
        public BL.Domain.Ticket CreateTicket(BL.Domain.Ticket ticket)
        {
            string insertStatement = "INSERT INTO Ticket(AccountId, [Text],DateOpened, State, DeviceName) VALUES(@accountId, @text, @dateOpened, @state,@deviceName)";
            using (var connection = this.GetConnection())
            {
                OleDbCommand command = new OleDbCommand(insertStatement, connection);
                command.Parameters.AddWithValue("@accountId", ticket.AccountId);
                command.Parameters.AddWithValue("@text", ticket.Text);
                command.Parameters.AddWithValue("@dateOpened",
                ticket.DateOpened.ToString("yyyy-MM-dd HH:mm:ss"));
                command.Parameters.AddWithValue("@state", (byte)ticket.State);
                if (ticket is HardwareTicket)
                    command.Parameters.AddWithValue("@deviceName",
                    ((HardwareTicket)ticket).DeviceName);
                else
                    command.Parameters.AddWithValue("@deviceName", DBNull.Value);
                connection.Open();
                command.ExecuteNonQuery();
                string retrievalQuery = "Select @@Identity";
                OleDbCommand retrievalOfNewNbrCommand = new OleDbCommand(retrievalQuery, connection);
                ticket.TicketNumber = Convert.ToInt32(retrievalOfNewNbrCommand.ExecuteScalar());

                connection.Close();
            } return ticket;
        }
Example #21
0
 public static object ExecuteScalar(string sql)
 {
     if (myOleDbConnection == null)
         Connect();
     OleDbCommand myOleDbCommand = new OleDbCommand(sql, myOleDbConnection);
     return myOleDbCommand.ExecuteScalar();
 }
    public string LoadContain()
    {
        if (Request.QueryString["CourseId"] == null)
        {
            return string.Empty;
        }

        string ThePath = string.Empty;
        string RetData = string.Empty;
        using (OleDbConnection Con = new OleDbConnection(constr))
        {
            OleDbCommand cmd = new OleDbCommand(String.Format("SELECT TOP 1 DataPath FROM CoursenotimeDataPath WHERE CourseId = {0}", Request.QueryString["CourseId"]), Con);
            try
            {
                Con.Open();
                ThePath = cmd.ExecuteScalar().ToString();
                //if (ThePath != string.Empty)
                //    ThePath = MapPath(DB.CourseNoTimeFileDir + ThePath);
                ThePath = DB.CourseNoTimeFileDir + ThePath;

                TextReader TR = new StreamReader(ThePath);
                RetData = TR.ReadToEnd();
                TR.Close();
                TR.Dispose();

            }
            catch (Exception ex)
            {
                RetData = ex.Message;
            }
            Con.Close();
        }

        return HttpUtility.HtmlDecode(RetData);
    }
Example #23
0
    //返回一个单值,一般用select操作
    public string ExecScalar(OleDbCommand myCmd)
    {
        string strSql;
        try
        {
            if (myCmd.Connection.State != ConnectionState.Open)
            {
                myCmd.Connection.Open();
            }

            strSql=Convert.ToString(myCmd.ExecuteScalar());
            return strSql ;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            if (myCmd.Connection.State == ConnectionState.Open)
            {
                myCmd.Connection.Close();
            }
        }
    }
Example #24
0
        public static string fcnDecrypt(string _strTextToDecrypt)
        {
            string strRes = "";
            string strPassphrase = "";

            using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn))
            {
                conDB.Open();

                string strSQL = "SELECT strEncPassPhrase " +
                                "FROM tblCampDefaults";

                using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB))
                    strPassphrase = cmdDB.ExecuteScalar().ToString();

                conDB.Close();
            }

            try { strRes = fcnDecrypt(_strTextToDecrypt, strPassphrase); }
            catch { }

            if (strRes == "") strRes = _strTextToDecrypt;

            return strRes;
        }
Example #25
0
    public string LoadPage()
    {
        string Path = string.Empty;
        OleDbConnection Con = new OleDbConnection(constr);
        OleDbCommand CMD = new OleDbCommand("SELECT Data_Path FROM MenuItem Where ItemID = " + MainMenu.SelectedValue.ToString(), Con);
        try
        {
            Con.Open();
            Path = CMD.ExecuteScalar().ToString();

        }
        catch { }
        Con.Close();
        if (Path == string.Empty)
        {
            //HtmlEditorQA.Html = string.Empty;
            return string.Empty;
        }
        Path = MapPath(Path);
        if (!File.Exists(Path))
        {
            return string.Empty;
        }
        else
        {
            TextReader TR = new StreamReader(Path);
            string tt = TR.ReadToEnd().ToString();

            TR.Close();
            TR.Dispose();
            return tt;
        }
    }
 //--function for returning a value queried by the user witht the help of an datareader--->
 public string  execute_scalar(string s)
 {   this.connect();
     OleDbCommand cmd = new OleDbCommand(s, this.con);
     return_result = Convert.ToString(cmd.ExecuteScalar());
     this.disconnect();
     return return_result;
  }
 public BL.Domain.TicketResponse CreateTicketResponse(BL.Domain.TicketResponse response)
 {
     if (response.Ticket != null)
     {
         string insertStatement = "INSERT INTO TicketResponse([Text], [Date], IsClientResponse"
         + ", Ticket_TicketNumber) VALUES (@text, @date"
         + ", @isClientResponse, @tickedNumber)";
         using (var connection = this.GetConnection())
          {
             OleDbCommand command = new OleDbCommand(insertStatement, connection);
             command.Parameters.AddWithValue("@text", response.Text);
             command.Parameters.AddWithValue("@date", response.Date.ToString("yyyy-MM-dd HH:mm:ss"));
             command.Parameters.AddWithValue("@isClientResponse", response.IsClientResponse);
             command.Parameters.AddWithValue("@tickedNumber", response.Ticket.TicketNumber);
             connection.Open();
             command.ExecuteNonQuery();
             // Retrieve primary key ‘Id' of inserted ticketresponse
             //When retrieving this data from Access, we must create and execute 2 commands
             string retrievalQuery = "Select @@Identity";
             OleDbCommand retrievalOfNewNbrCommand = new OleDbCommand(retrievalQuery, connection);
             response.Id = Convert.ToInt32(retrievalOfNewNbrCommand.ExecuteScalar());
             connection.Close(); // good practice!
          }
         return response;
     }
     else
         throw new ArgumentException("The ticketresponse has no ticket attached to it");
 }
Example #28
0
    public string LoadPage()
    {
        LblError.Visible = false;
        //Load data from file to RadEditor
        string Path = string.Empty;
        OleDbConnection Con = MySchool.QAConnection;
        OleDbCommand CMD = new OleDbCommand("SELECT Data_Path FROM QAMenu Where QAID = " + QAMainMenu.SelectedValue.ToString(), Con);
        try
        {
            Con.Open();
            Path = CMD.ExecuteScalar().ToString();

        }
        catch { }
        Con.Close();
        if (Path == string.Empty)
        {
            //HtmlEditorQA.Html = string.Empty;
            return string.Empty;
        }
        Path = MapPath(Path);
        if (!File.Exists(Path))
        {
            return string.Empty;
        }
        else
        {
            TextReader TR = new StreamReader(Path);
            return TR.ReadToEnd().ToString();
        }
    }
Example #29
0
    public int EnterToSite(UserDetails userDetails)//בודק על פי האימייל והסיסמא האם המשתשמש שמנסה להיכנס לאתר קיים או לא
    {
        OleDbCommand myCmd = new OleDbCommand("CheckIfUserExist", myConnection);
        myCmd.CommandType = CommandType.StoredProcedure;

        OleDbParameter objParam;

        objParam = myCmd.Parameters.Add("@Email", OleDbType.BSTR);
        objParam.Direction = ParameterDirection.Input;
        objParam.Value = userDetails.email;

        objParam = myCmd.Parameters.Add("@Password", OleDbType.BSTR);
        objParam.Direction = ParameterDirection.Input;
        objParam.Value = userDetails.password;

        int x = 0;
        try
        {
            myConnection.Open();
            x = (int)myCmd.ExecuteScalar();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            myConnection.Close();
        }
        return x;

    }
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            try
            {
                connection.Open();
                string qry1 = "select Upload from FilesTable where Number=" + 2 + "";
                OleDbCommand cmd = new OleDbCommand(qry1, connection);
                cmd.ExecuteNonQuery();

                string fileName = cmd.ExecuteScalar().ToString();
                string fileExtension = ".txt/.jpg/.pdf/.docx/.xls";

                // Set Response.ContentType
                Response.ContentType = GetContentType(fileExtension);

                // Append header
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);

                // Write the file to the Response
                Response.TransmitFile(Server.MapPath("~/Files/" + fileName));
                Response.End();
            }
            catch
            { }
            finally
            {
                connection.Close();
            }
        }