Ejemplo n.º 1
0
        private void tsbtnEdit_Click(object sender, EventArgs e)
        {
            var newuser = new NewTable(id);
            var result  = newuser.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    conn = new SqlConnection(connStr);
                    conn.Open();

                    cmd = new SqlCommand();
                    cmd = conn.CreateCommand();

                    cmd.CommandText = "Update  Tables Set Name=@Name,GroupId=@GroupId,Number=@Number,Amount=@Amount,Type=@Type,Status=@Status Where Id=@Id";

                    cmd.Parameters.AddRange(new SqlParameter[]
                    {
                        new SqlParameter("@Id", id),
                        new SqlParameter("@Name", newuser.name),
                        new SqlParameter("@GroupId", newuser.groupid),
                        new SqlParameter("@Number", newuser.number),
                        new SqlParameter("@Amount", newuser.amount),
                        new SqlParameter("@Type", newuser.amounttype),
                        new SqlParameter("@Status", newuser.status)
                    });

                    resultt = (int)cmd.ExecuteNonQuery();

                    if (resultt == 1)
                    {
                        Msg msg = new Msg("Məlumat uğurla dəyişdirildi", 221);
                        msg.ShowDialog();
                        cmd.Dispose();
                        ShowTable();
                    }
                    else
                    {
                        Msg msg = new Msg("Xəta baş verdi, dəyişdirilmədi", 237);
                        msg.ShowDialog();
                    }

                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    throw;
                }
                finally { }
            }
        }
Ejemplo n.º 2
0
        private void tsbtnNew_Click(object sender, EventArgs e)
        {
            var newuser = new NewTable(0);
            var result  = newuser.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    conn = new SqlConnection(connStr);
                    conn.Open();

                    cmd = new SqlCommand();
                    cmd = conn.CreateCommand();

                    cmd.CommandText = "Insert Into Tables (Name,GroupId,Number,Amount,Type,Status) Values (@Name,@GroupId,@Number,@Amount,@Type,@Status)";

                    cmd.Parameters.AddRange(new SqlParameter[]
                    {
                        new SqlParameter("Name", newuser.name),
                        new SqlParameter("GroupId", newuser.groupid),
                        new SqlParameter("Number", newuser.number),
                        new SqlParameter("Amount", newuser.amount),
                        new SqlParameter("Type", newuser.amounttype),
                        new SqlParameter("Status", newuser.status)
                    });

                    resultt = (int)cmd.ExecuteNonQuery();

                    if (resultt > 0)
                    {
                        Msg msg = new Msg("Məlumat uğurla daxil olundu", 221);
                        msg.ShowDialog();
                        cmd.Dispose();
                        ShowTable();
                    }
                    else
                    {
                        Msg msg = new Msg("Xəta baş verdi, məlumat daxil edilmədi", 237);
                        msg.ShowDialog();
                    }

                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    throw;
                }
                finally { }
            }
        }