protected void LoginButton_Click(object sender, EventArgs e)
        {
            PasswordErrorLB.Text = "";
            UserNameErrorLB.Text = "";
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            conn.Open();
            string checkUser = "SELECT count(*) FROM UserDataTable WHERE Username ='" + UserNameTB.Text + "'";
            SqlCommand com = new SqlCommand(checkUser, conn);
            int numUsers = Convert.ToInt32(com.ExecuteScalar().ToString());
            conn.Close();
            if (numUsers == 1)
            {
                conn.Open();
                string checkPassword = "SELECT Password FROM UserDataTable WHERE Username ='" + UserNameTB.Text + "'";
                SqlCommand com2 = new SqlCommand(checkPassword, conn);
                string password = com2.ExecuteScalar().ToString().Replace(" ", "");
                conn.Close();

                if(password == PasswordTB.Text)
                {
                    Session["New"] = UserNameTB.Text;
                    Response.Redirect("MainMenuPage.aspx");
                }
                else
                {
                    PasswordErrorLB.Text = "You Must Enter a Correct Password";
                }
            }
            else
            {
                UserNameErrorLB.Text = "You Must Enter a Correct Username";
            }
        }
Example #2
0
    public static string ConfirmQrCode(int qrCode, string newUserOpenId)
    {
        string originalUserOpenId = "";
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["constr"].Trim());
        SqlCommand cmd = new SqlCommand(" select qr_invite_list_owner from qr_invite_list where qr_invite_list_id = " + qrCode.ToString(), conn);
        conn.Open();
        SqlDataReader drd = cmd.ExecuteReader();
        if (drd.Read())
        {
            originalUserOpenId = drd.GetString(0);
        }
        drd.Close();
        conn.Close();
        cmd.CommandText = " insert into qr_invite_list_detail ( qr_invite_list_detail_id , qr_invite_list_detail_openid ) "
            + " values ('" + qrCode.ToString() + "' , '" + newUserOpenId.Replace("'", "").Trim() + "' ) ";
        conn.Open();
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch
        {

        }
        conn.Close();
        return originalUserOpenId.Trim();
    }
Example #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string flag = context.Request["flag"].ToString();
            string struid = context.Session["ID"].ToString();
            string strSQL = "update dbo.tabUsers set ";
            string strDataConn = ConfigurationManager.ConnectionStrings["SQLDataConnStr"].ConnectionString;
            SqlConnection dataConn = new SqlConnection(strDataConn);

            if (flag == "1")
            {
                string strusername = context.Request["username"].ToString();
                string strutell = context.Request["utell"].ToString();
                string struemail = context.Request["uemail"].ToString();
                strSQL += "UserName = '" + strusername + "',"+" UserTel = '"+strutell+"',"+"UserEmail = '"+struemail+"' where ID = '"+struid+"'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
            else if (flag == "2")
            {
                string strpw = context.Request["upassword"].ToString();
                strSQL +=  "UserPW = '" + strpw + "' where UserID = '" + struid + "'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
        }
Example #4
0
        protected void ButtonEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].ConnectionString);
                conn.Open();
                String contar_mensajes = "select count(*) from Mensaje_privado";
                SqlCommand command = new SqlCommand(contar_mensajes, conn);
                int contador = Convert.ToInt32(command.ExecuteScalar().ToString());
                conn.Close();

                conn.Open();
                String enviar_mensaje = "insert into Mensaje_privado (id_mensaje, id_remitente, id_buzon, leido, mensaje, asunto, fecha_de_envio) values (" + contador + ", " + Bandeja_Entrada.id_usuario + ", " + Bandeja_Entrada.id_destino + ", " + 0 + ", '" + TextBoxEM.Text + "', '" + LabelAsunto.Text + "', CURRENT_TIMESTAMP)";
                command = new SqlCommand(enviar_mensaje, conn);
                command.ExecuteNonQuery();
                Response.Write("Mensaje enviado!");
                Panel1.Visible = false;
                ButtonVolver.Visible = true;

                conn.Close();
            }
            catch (Exception ex)
            {
            }
        }
Example #5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            DataTable dtNew = new DataTable();
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("select * from all_triathlon_timing", con))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    con.Close();

                    int count = dt.Rows.Count;
                    if (count != 0)
                    {

                        using (SqlCommand cmdNew = new SqlCommand("select GUID from all_triathlon_timing where BIBNumber='" + txt123Bib.Text.Trim() + "'", con))
                        {
                            con.Open();
                            SqlDataAdapter daNew = new SqlDataAdapter(cmdNew);
                            daNew.Fill(dtNew);

                            string abc = dtNew.Rows[0][0].ToString();
                            Response.Redirect("GetCertificate.aspx?abc=" + abc);
                        }
                    }
                }
            }
        }
Example #6
0
        public IEnumerable<Message> GetData()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("SELECT [ID], [Date], [Message] FROM [dbo].[Messages]", connection))
                {
                    command.Notification = null;

                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += DependencyOnChange;

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    using (var reader = command.ExecuteReader())
                        return reader.Cast<IDataRecord>()
                            .Select(x => new Message()
                            {
                                ID = x.GetInt32(0),
                                Date = x.GetDateTime(1),
                                Text = x.GetString(2)
                            }).ToList();
                }
            }
        }
Example #7
0
        private void onload()
        {
            string strSQLconnection = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aviation.mdf; Trusted_Connection=True;User Instance=True";
            SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
            SqlCommand sqlCommand = new SqlCommand("SELECT p.username,p.nama,p.jawatan,p.bahagian,p.telefon_bimbit,p.telefon_pejabat,p.email FROM profil_pegawai p, supervisor s WHERE p.username = s.ic ORDER BY p.nama", sqlConnection);

                try
                {
                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();

                    SqlDataAdapter mySqlAdapter = new SqlDataAdapter(sqlCommand);
                    DataSet myDataSet = new DataSet();
                    mySqlAdapter.Fill(myDataSet);

                    gridpenyelia.DataSource = myDataSet;
                    gridpenyelia.DataBind();

                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();
                }
                catch (SqlException ex)
                {
                }
                finally
                {

                }
        }
Example #8
0
        private void listBox1_Click(object sender, EventArgs e)
        {
            string strTableName = this.listBox1.SelectedValue.ToString();//获取数据表名称
            using (SqlConnection con = new SqlConnection(//创建数据库连接对象
 @"server=(local);uid=sa;Pwd=6221131;database='" + strDatabase + "'"))
            {
                string strSql =//创建SQL字符串
                    @"select  name 字段名, xusertype 类型编号, length 长度 into hy_Linshibiao 
from  syscolumns  where id=object_id('" + strTableName + "') ";
                strSql +=//添加字符串信息
@"select name 类型,xusertype 类型编号 into angel_Linshibiao from 
systypes where xusertype in (select xusertype 
from syscolumns where id=object_id('" + strTableName + "'))";
                con.Open();//打开数据库连接
                SqlCommand cmd = new SqlCommand(strSql, con);//创建命令对象
                cmd.ExecuteNonQuery();//执行SQL命令
                con.Close();//关闭数据库连接
                SqlDataAdapter da = new SqlDataAdapter(//创建数据适配器
                    @"select 字段名,类型,长度 from 
hy_Linshibiao t,angel_Linshibiao b where t.类型编号=b.类型编号", con);
                DataTable dt = new DataTable();//创建数据表
                da.Fill(dt);//填充数据表
                this.dataGridView1.DataSource = dt.DefaultView;//设置数据源
                SqlCommand cmdnew = new SqlCommand(//创建命令对象
                    "drop table hy_Linshibiao,angel_Linshibiao", con);
                con.Open();//打开数据库连接
                cmdnew.ExecuteNonQuery();//执行SQL命令
                con.Close();//关闭数据库连接
            }
        }
Example #9
0
        protected void BindDDL2()
        {
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand cmd1 = new SqlCommand("select DISTINCT s.ProjectID,s.ProjectnameTH from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "'", con);
            SqlDataReader reader1 = cmd1.ExecuteReader();
            int count = 0;
            while (reader1.Read())
            {
                count++;
            }
            con.Close();
            if (count == 0)
            {
                DropDownList2.Items.Add(new ListItem("ไม่มีข้อมูล", "none"));
                DropDownList2.Items.FindByValue("none").Selected = true;
            }
            else
            {
                DataTable dt = new DataTable();

                SqlCommand cmdxx = new SqlCommand("select DISTINCT s.ProjectID,s.ProjectnameTH from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "'", con);
                con.Open();
                dt.Load(cmdxx.ExecuteReader());
                con.Close();

                DropDownList2.DataSource = dt;
                DropDownList2.DataTextField = "ProjectnameTH";
                DropDownList2.DataValueField = "ProjectID";
                DropDownList2.DataBind();
                DropDownList2.Items.Add(new ListItem("Choose", "choose"));
                DropDownList2.Items.FindByValue("choose").Selected = true;
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            String sc = @"Data Source=.\sqlexpress;Initial Catalog=MASTER;Integrated Security=true;Connect Timeout=1;Pooling=false";

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(sc);

                c.Open();
                c.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().Name);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
            }
            finally
            {
                if (/*c != null &&*/ c.State != ConnectionState.Closed)
                    c.Close();

                Console.ReadKey();
            }
        }
Example #11
0
        public void run()
        {
            string liveConString = ConfigurationManager.AppSettings["dailyconstring"];
            string reportConString = ConfigurationManager.AppSettings["dailyconstringReportingServer"];
            string EngageConString = ConfigurationManager.AppSettings["engageconstring"];
            string VidConString = ConfigurationManager.AppSettings["dailyconstringReportingServer"];
            string targetMonth = ConfigurationManager.AppSettings["TargetMonth"];
            string previousMonth = ConfigurationManager.AppSettings["PreviousMonth"];
            string monthEndSubsUpdateQueries = ConfigurationManager.AppSettings["MonthEndSubsUpdateQueries"];//'|' delimited, string replace targetmonth,previousmonth
            //string NowConString = ConfigurationManager.AppSettings[""];
            try
            {
                SqlConnection con = new SqlConnection();
                DataSet dsResult = new DataSet();
                con.ConnectionString = reportConString;
                con.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandTimeout = 1200;
                //cmd.CommandText = @"select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct u.userid),0) as 'numbers' from users u inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid where cast(registrationdate as date) = '" + traverserDate.Date.ToString("yyyy-MM-dd") + @"'  and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er  inner join users u on u.userid=er.userid inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)>='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er  inner join users u on u.userid=er.userid inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)='" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode  from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.UserId not in( select er.userid from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)< '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode  from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.UserId in( select er.userid from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)< '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er inner join users u on u.userid=er.userid inner join country c on c.code=u.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)>='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode from entitlementrequests er  inner join users u on u.userid=er.userid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid where case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er inner join users u on u.userid=er.userid inner join country c on c.code=u.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)='" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t";

                cmd.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void CreateGetClothingProcedureIfNull()
        {
            using (SqlConnection con = new SqlConnection(Settings.AdventureWorksConStr))
            {
                SqlCommand checkIfProcExists = new SqlCommand();
                checkIfProcExists.CommandText = "IF (OBJECT_ID('GetProductsByGender') IS NOT NULL) " +
                                                "DROP PROCEDURE GetProductsByGender " +
                                                "";
                checkIfProcExists.Connection = con;

                con.Open();

                using (SqlDataReader dr = checkIfProcExists.ExecuteReader())
                {
                }

                con.Close();

                SqlCommand command = new SqlCommand();
                command.CommandText = "CREATE PROCEDURE GetProductsByGender (@strGender varchar(5)) " +
                                      "AS " +
                                      "SELECT ProductModelID, Name " +
                                      "FROM Production.ProductModel " +
                                      "WHERE Name LIKE @strGender";
                command.Connection = con;

                con.Open();

                using (SqlDataReader dr = command.ExecuteReader())
                {
                }
            }
        }
        // Lấy Messages cần gửi
        public List<DiscussMessage> GetMessagesChat()
        {
            var messageChat = new List<DiscussMessage>();
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT dbo.Messages.Id, dbo.Messages.[Content], dbo.Messages.SenderId, dbo.Messages.SendDate, dbo.Messages.Type
                                                            FROM  dbo.Messages
                                                            WHERE dbo.Messages.Sent = 'N' ORDER BY dbo.Messages.SendDate ASC", connection))
                {
                    command.Notification = null;
                    if (connection.State == ConnectionState.Closed)
                        connection.Open();
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        messageChat.Add(item: new DiscussMessage
                        {
                            Id = reader["Id"].ToString(),
                            Content = reader["Content"].ToString(),
                            SenderId = reader["SenderId"].ToString(),
                            UserName = "",
                            SendDate = reader["SendDate"].ToString(),
                            Type = reader["Type"].ToString(),
                            GroupId = ""
                        });
                    }
                }
            }

            return messageChat;
        }
 public mobile_employees Insert(mobile_employees id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_MOBILE_EMPLOYEES", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@mobile_unit_id", id.mobile_unit_id);
     cmd.Parameters.AddWithValue("@employee_id", id.employee_id);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_MOBILE_EMPLOYEES", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@mobile_unit_id", id.mobile_unit_id);
     cmd.Parameters.AddWithValue("@employee_id", id.employee_id);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.mobile_employee_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
        //The DAL managers contain methods that assign parameters to Procedures Stored
        //in the Database. each method return relevant infromation - dataSets that binds
        //to grids, objects and values to be assigned and used and true/false values so
        //show if information in the DB has been entered/replaced/updated
        public bool CreateAccount(Customer newCustomer, Account newAccount)
        {
            bool userCreated = false, accountCreated = false;

            using (cxn = new SqlConnection(this.ConnectionString))
            {
                using (cmd = new SqlCommand("spCreateCustomer", cxn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = newCustomer.FirstName;
                    cmd.Parameters.Add("@Surname", SqlDbType.NVarChar, 50).Value = newCustomer.Surname;
                    cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = newCustomer.Email;
                    cmd.Parameters.Add("@Phone", SqlDbType.NVarChar, 50).Value = newCustomer.Phone;
                    cmd.Parameters.Add("@AddressLine1", SqlDbType.NVarChar, 50).Value = newCustomer.AddressLine1;
                    cmd.Parameters.Add("@AddressLine2", SqlDbType.NVarChar, 50).Value = newCustomer.AddressLine2;
                    cmd.Parameters.Add("@City", SqlDbType.NVarChar, 50).Value = newCustomer.City;
                    cmd.Parameters.Add("@County", SqlDbType.NVarChar, 50).Value = newCustomer.County;
                    cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@OnlineCustomer", SqlDbType.Bit).Value = newCustomer.OnlineCustomer;

                    cxn.Open();
                    int rows = cmd.ExecuteNonQuery();
                    cxn.Close();

                    if (rows > 0)
                    {
                        newCustomer.CustomerID = Convert.ToInt32(cmd.Parameters["@CustomerID"].Value);
                        newAccount.CustomerID = newCustomer.CustomerID;
                        userCreated = true;
                    }
                }

                using (cmd = new SqlCommand("spCreateAccount", cxn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@AccountType", SqlDbType.NVarChar, 50).Value = newAccount.AccountType;
                    cmd.Parameters.Add("@SortCode", SqlDbType.Int, 8).Value = newAccount.SortCode;
                    cmd.Parameters.Add("@InitialBalance", SqlDbType.Int, 8).Value = newAccount.Balance;
                    cmd.Parameters.Add("@OverDraft", SqlDbType.Int, 8).Value = newAccount.OverDraftLimit;
                    cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 4).Value = newAccount.CustomerID;
                    cmd.Parameters.Add("@AccountNumber", SqlDbType.Int, 8).Direction = ParameterDirection.Output;

                    cxn.Open();
                    int rows = cmd.ExecuteNonQuery();
                    cxn.Close();

                    if (rows > 0)
                    {
                        newAccount.AccountNumber = Convert.ToInt32(cmd.Parameters["@AccountNumber"].Value);
                        accountCreated = true;
                    }
                }
                if (userCreated && accountCreated)
                    return true;
                else
                    return false;
            }
        }
Example #16
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(constr);
                con.Open();
                SqlCommand cmd2 = new SqlCommand(" UPDATE CPE02 SET Approve='1' WHERE ProjectID = '" + DropDownList2.SelectedValue.ToString() + "'  ", con);
                cmd2.ExecuteNonQuery();
                con.Close();

                Button2.Visible = true;
                string text = "select * from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "' and s.ProjectID = @ProjectID";
                if (DropDownList1.SelectedValue.ToString() == "approved")
                {
                    Button2.Visible = false;
                    text = "select * from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "' and s.ProjectID = @ProjectID and c.Approve = '1'";
                }
                else if (DropDownList1.SelectedValue.ToString() == "waiting")
                {
                    text = "select * from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "' and s.ProjectID = @ProjectID and c.Approve = '0'";
                }
                if (DropDownList2.SelectedValue != "choose")
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand(text, con);
                    cmd.Parameters.AddWithValue("@ProjectID", DropDownList2.SelectedValue.ToString());
                    SqlDataReader dr = cmd.ExecuteReader();
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else
                {
                    Button2.Visible = false;
                }
        }
        public List<DiscussMessageModel> RegisterDiscussMessages()
        {
            var messageChat = new List<DiscussMessageModel>();
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT *
                                                      FROM [dbo].[Comments]", connection))
                {
                    command.Notification = null;
                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        messageChat.Add(item: new DiscussMessageModel
                        {
                            Id = reader["Id"].ToString(),
                            Username = reader["Username"].ToString(),
                            Message = reader["Message"].ToString(),
                            FilePath = reader["FilePath"].ToString(),
                            Avatar = "dist/img/avatar.png",
                            Status = reader["Status"].ToString(),
                            CreatedDate = DateTime.Parse(reader["CreatedDate"].ToString())
                        });
                    }
                }

            }
            return messageChat;
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     con = new SqlConnection(ConfigurationManager.ConnectionStrings["devi"].ToString());
    
     
     
     if (Request.QueryString["t"] != null)
     {
         temp = Convert.ToInt16(Request.QueryString["t"].ToString());
         uid = Convert.ToInt16(Request.QueryString["id"].ToString());
         
         if (temp == 1)
         {
             con.Open();
             cmd = new SqlCommand("update user1_reg set userkey='1' where id='"+uid+"'",con);
             cmd.ExecuteNonQuery();
             con.Close();
         }
         if (temp == 2)
         {
             con.Open();
             cmd = new SqlCommand("update user1_reg set userkey='2' where id='" + uid + "'", con);
             cmd.ExecuteNonQuery();
             con.Close();
         }
     }
     
     
 }
Example #19
0
    protected void Button4_Click(object sender, EventArgs e)//开启或关闭聊天室
    {            

	if (!DataAccess.chat.IsOpen())
        {
            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HomeChatConnectionString"].ToString());
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "UPDATE [chat] SET isopen=0;UPDATE [chat] SET IsOpen=1 WHERE [email protected]";
            cmd.Parameters.AddWithValue("@id", chatnum);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
		    Application["IsOpen"] = 1;    
            Response.Redirect("manage.aspx");
        }
        else
        {
            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HomeChatConnectionString"].ToString());
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "UPDATE [chat] SET IsOpen=0 delete from KickedUser";
            cmd.Parameters.AddWithValue("@id", chatnum);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

            cmd.CommandText = "UPDATE [user] SET IsOnline=0 WHERE UserID<>1";//UserID=1的是用户名为‘大家’的用户,将永远开启
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
		    Application["IsOpen"] = 0;
            Response.Redirect("manage.aspx");
        }
        
    }
 public demobilization Insert(demobilization id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_DEMOBILIZATION", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_DEMOBILIZATION", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.demo_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
Example #21
0
 protected void btnChk_Click(object sender, EventArgs e)
 {
     string constr = WebConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
     SqlConnection conn = new SqlConnection(constr);
     conn.Open();
     String Checkuser = "select count(*) from person where Username ='" + TextUser.Text + "'";
     SqlCommand com = new SqlCommand(Checkuser, conn);
     int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
     conn.Close();
     if (temp == 1)
     {
         conn.Open();
         string checkPasswordQuery = "select passWord from person where Username ='" + TextUser.Text + "'";
         string test = "select Fname from person where Username ='" + TextUser.Text + "'";
         string id = "select PersID from person where Username ='" + TextUser.Text + "'";
         SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
         SqlCommand testComm = new SqlCommand(test, conn);
         SqlCommand idComm = new SqlCommand(id,conn);
         string password = passComm.ExecuteScalar().ToString().Replace(" ", "");
         string testtest = testComm.ExecuteScalar().ToString().Replace(" ", "");
         string persid = idComm.ExecuteScalar().ToString().Replace(" ", "");
         if (password == TextPass.Text)
         {
             Session["New"] = testtest;
             Session["status"] = true;
             Session["ID"] = persid;
             Response.Redirect("~/form");
         }
     }
 }
        protected void btn_Aemp_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {

                if (rd_Male.Checked == true)
                {
                    SqlCommand cmd1 = new SqlCommand("select count(*) from Retail1_emp where Eid ='" + txt_Eid.Text + "'and Store='" + storeName + "'", con);
                    SqlCommand cmd = new SqlCommand("insert into Retail1_emp(Eid,Ssn,Name,Sex,Title,Edate,Salary,Store) values ('" + txt_Eid.Text + "','" + txt_Ssn.Text + "','" + txt_Name.Text + "','" + rd_Male.Text + "','" + txt_Title.Text + "','" + txt_Edate.Text + "','" + txt_Salary.Text + "','" + storeName +"')", con);
                    con.Open();
                    int count = Convert.ToInt32(cmd1.ExecuteScalar().ToString());
                    if (count == 1)
                    {

                        lbl_Aemp.Text = "EMPLOYEE ALREADY EXISTS!!";
                    }
                    else
                    {
                        cmd.ExecuteNonQuery();
                        lbl_Aemp.Text = "EMPLOYEE ADDED SUCCESSFULLY!!";
                    }
                    //cmd.ExecuteNonQuery();
                    //  MultiView1.ActiveViewIndex = 5;
                    txt_Eid.Text = "";
                    txt_Name.Text = "";
                    txt_Title.Text = "";
                    txt_Salary.Text = "";
                    txt_Edate.Text = "";
                    txt_Ssn.Text = "";
                }
                else if (rd_Female.Checked == true)
                {
                    SqlCommand cmd2 = new SqlCommand("select count(*) from Retail1_emp where Eid ='" + txt_Eid.Text + "'and Store='" + storeName + "'", con);
                    SqlCommand cmd = new SqlCommand("insert into Retail1_emp(Eid,Ssn,Name,Sex,Title,Edate,Salary,Store) values ('" + txt_Eid.Text + "','" + txt_Ssn.Text + "','" + txt_Name.Text + "','" + rd_Female.Text + "','" + txt_Title.Text + "','" + txt_Edate.Text + "','" + txt_Salary.Text + "','" + storeName + "')", con);
                    con.Open();
                    int count = Convert.ToInt32(cmd2.ExecuteScalar().ToString());
                    if (count == 1)
                    {

                        lbl_Aemp.Text = "EMPLOYEE ALREADY EXISTS!!";
                    }
                    else
                    {
                        cmd.ExecuteNonQuery();
                        lbl_Aemp.Text = "EMPLOYEE ADDED SUCCESSFULLY!!";
                    }
                    // cmd.ExecuteNonQuery();
                    // MultiView1.ActiveViewIndex = 5;
                    txt_Eid.Text = "";
                    txt_Name.Text = "";
                    txt_Title.Text = "";
                    txt_Salary.Text = "";
                    txt_Edate.Text = "";
                    txt_Ssn.Text = "";
                }
            }
            MultiView1.ActiveViewIndex = 5;
            lbl_Aemp.Visible = true;
        }
Example #23
0
    protected void ButtonLog_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
        con.Open();

        string checkUser = "select count(*) from [Table] where UserName ='" + TextBoxUser.Text + "'";
        SqlCommand com = new SqlCommand(checkUser, con);

        int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
        con.Close();
        if (temp == 1)
        {
            con.Open();
            string checkPass = "select password from [Table] where UserName ='" + TextBoxUser.Text + "'";
            SqlCommand passCom = new SqlCommand(checkPass, con);
            string password = passCom.ExecuteScalar().ToString().Replace(" ","");

            if (password == TextBoxPW.Text)
            {
                Session["new"] = TextBoxUser.Text;
                Response.Write("Password correct");
                Response.Redirect("Claim.aspx");
            }
            else {
                Response.Write("Password incorrect");
            }
        }
        else {
            Response.Write("Username is incorrect");
        }
        
    }
Example #24
0
 /// <summary>
 /// Kiem tra ket noi DataBase
 /// </summary>
 /// <returns></returns>
 public bool CheckConnection()
 {
     // Adapter and DataSet
     conn = Utils.getConnection();
     strSQL = "SELECT Count(EmployeeID) FROM tblEmployee";
     sqlCommand = new SqlCommand(strSQL, conn);
     try
     {
         if (conn.State == ConnectionState.Broken)
         {
             conn.Close();
             conn.Open();
         }
         else if(conn.State == ConnectionState.Closed)
         {
             conn.Open();
         }
         sqlCommand.ExecuteNonQuery();
         return true;
     }
     catch(Exception)
     {
         return false;
     }
     finally
     {
         conn.Close();
     }
 }
        public void RegisterDiscussMessages()
        {
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT [Id]
                                                          ,[Username]
                                                          ,[Message]
                                                          ,[FilePath]
                                                          ,[Status]
                                                          ,[CreatedDate]
                                                      FROM [dbo].[Discuss] ORDER BY [dbo].[Discuss].CreatedDate desc", connection))
                {
                    command.Notification = null;

                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var reader = command.ExecuteReader();

                }

            }
           
        }
        protected void loginButton_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            string checkUser = "SELECT COUNT(*) FROM center_table WHERE code='"+usernameTextBox.Text+"' ";
            SqlCommand command = new SqlCommand(checkUser,connection);
            int temp = Convert.ToInt32(command.ExecuteScalar().ToString());
            connection.Close();
            if (temp==1)
            {
                connection.Open();
                string checkPass = "SELECT password FROM center_table WHERE code='" + usernameTextBox.Text + "'";
                SqlCommand passCommand = new SqlCommand(checkPass,connection);
                string password = passCommand.ExecuteScalar().ToString();

                if (password==passTextBox.Text)
                {
                    Session["loginSession"] = usernameTextBox.Text;
                    msgLabel.Text="Login Successfull";
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    msgLabel.Text = "Incorrect password !";
                }
            }
            else
            {
                msgLabel.Text="UserName Is not Correct";
            }
        }
 public requirements Insert(requirements id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_REQUIREMENTS", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@requirement_desc", id.requirement_desc);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_REQUIREMENTS", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@requirement_desc", id.requirement_desc);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.req_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
 public job_category Insert(job_category id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_JOB_CATEGORY", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@job_category_name", id.job_category_name);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_JOB_CATEGORY", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@job_category_name", id.job_category_name);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.job_cat_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
Example #29
0
 /// <summary>
 /// Добавление наград
 /// </summary>
 /// <param name="newR">Новая награда</param>
 /// <returns></returns>
 public bool AddReward(Reward newR)
 {
     using (var connection = new SqlConnection(ConnectionString()))
     {
         if (newR.Image == null)
         {
         var command = new SqlCommand(
         "INSERT INTO dbo.Rewards (Title, Description) " +
         "VALUES (@Title, @Description)", connection);
         command.Parameters.AddWithValue("@Title", newR.Title);
         command.Parameters.AddWithValue("@Description", newR.Description);
         connection.Open();
         return command.ExecuteNonQuery() == 1;
         }
         else
         {
         var command = new SqlCommand(
         "INSERT INTO dbo.Rewards (Title, Description, Image) " +
         "VALUES (@Title, @Description, @Image)", connection);
         command.Parameters.AddWithValue("@Title", newR.Title);
         command.Parameters.AddWithValue("@Description", newR.Description);
         command.Parameters.AddWithValue("@Image", newR.Image);
         connection.Open();
         return command.ExecuteNonQuery() == 1;
         }
     }
 }
Example #30
0
    protected void Button_Login_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
        conn.Open();
        string checkuser = "select count(*) from User_Data where UserName='" + TextBoxUserName.Text + "'";
        SqlCommand con = new SqlCommand(checkuser, conn);
        int temp = Convert.ToInt32(con.ExecuteScalar().ToString());
        conn.Close();

        if (temp == 1)
        {
            conn.Open();
            string checkPasswordQuery = "select password from User_Data where UserName='" + TextBoxUserName.Text + "'";
            SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
            string password = passComm.ExecuteScalar().ToString().Replace(" ","");
            if (password == TextBoxPassword.Text)
            {
                Session["New"] = TextBoxUserName.Text;
                Response.Write("Login Successful");
                Response.Redirect("ReportACrime.aspx");
            }
            else
            {
                Response.Write("Password incorrect");
            }

        }
        else
        {
            Response.Write("User does not exist ");
        }
    }