Beispiel #1
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            //  updateuser_level();

            if (CmbOstan.Equals("") || TxtPostName.Text.Equals("") || CmbVoltage.Text.Equals(""))
            {
                MessageBox.Show(this, "اطلاعات ناقص هستند", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }

            //try
            //{
            //-----------------------------------------------------
            Classconn     clscon = new Classconn();
            SqlConnection con    = new SqlConnection(clscon.connstr);
            //SqlCommand cmd = new SqlCommand("UPDATE tbl_user SET  (name,family,sale_tavalod,shomare_meli,email,madrak,telephone,username,password) Values (@name,@family,@sale_tavalod,@shomare_meli,@email,@madrak,@telephone,@username,@password) WHERE id_user = id_user ", con);
            SqlCommand cmd = new SqlCommand("update tbl_name_post set ostan=@ostan,name_post=@name_post,voltage=@voltage where id_name_post= @id_name_post", con);

            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("ostan", CmbOstan.Text);
            cmd.Parameters.AddWithValue("name_post", TxtPostName.Text);
            cmd.Parameters.AddWithValue("voltage", CmbVoltage.Text);
            cmd.Parameters.AddWithValue("id_name_post", label13.Text);
            //cmd.Parameters.AddWithValue("id", label14.Text);

            //--------------------------------------------------
            con.Open();
            cmd.ExecuteNonQuery();
            // updateuser_level();
            MessageBox.Show(this, "تغییرات با موفقیت به ثبت رسید", "اتمام عملیات", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            BtnOk.Enabled    = true;
            BtnEdit.Enabled  = false;
            TxtPostName.Text = "";

            this.tbl_name_postTableAdapter.Fill(this.barghDataSetnamepost.tbl_name_post);
            con.Close();
        }
Beispiel #2
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            if (CmbOstan.Equals("") || TxtPostName.Text.Equals("") || CmbVoltage.Text.Equals(""))
            {
                MessageBox.Show(this, "اطلاعات ناقص هستند", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                return;
            }
            //-----------------------------------------------------------------
            Classconn     clscon = new Classconn();
            SqlConnection con    = new SqlConnection(clscon.connstr);
            SqlCommand    com    = new SqlCommand();
            //int i = 0;
            //com = new SqlCommand("SELECT COUNT(*) FROM View_user_level WHERE username= '******' and password='******' ", con);


            //if (con.State == ConnectionState.Closed)
            //{
            //    con.Open();
            //    i = (int)com.ExecuteScalar();
            //}//end if

            //con.Close();

            //if (i > 0)
            //{
            //    MessageBox.Show(this, "کاربر با این مشخصات قبلا ثبت نام شده است", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);

            //    return;
            //}

            ////------------------------------------------------------------

            string cmdString  = "INSERT INTO  tbl_name_post (ostan,voltage,name_post) Values (@ostan,@voltage,@name_post)";
            string connString = clscon.connstr;

            using (SqlConnection conn = new SqlConnection(connString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandText = cmdString;
                    comm.Parameters.AddWithValue("ostan", CmbOstan.Text);
                    comm.Parameters.AddWithValue("name_post", TxtPostName.Text);
                    comm.Parameters.AddWithValue("voltage", CmbVoltage.Text);


                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                        MessageBox.Show(this, "اطلاعات با موفقیت به ثبت رسید", "اتمام عملیات", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                        this.tbl_name_postTableAdapter.Fill(this.barghDataSetnamepost.tbl_name_post);
                        TxtPostName.Text = "";
                    }
                    catch
                    {
                        MessageBox.Show(this, "برنامه قادر به ذخیره سازی اطلاعات نیست", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
                    }
                }
            }
        }