Example #1
0
        public static void insertData(string method, QueryParamter[] parameters)
        {
            connect();
            command = new SqlCommand(method, connection);
            command.CommandType = CommandType.StoredProcedure;

            foreach (QueryParamter parameter in parameters)
            {
                command.Parameters.Add("@" + parameter.Name, paramTypes[parameter.Type]).Value = parameter.Value;
            }

            command.ExecuteNonQuery();

        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            QueryParamter[] parameters = new QueryParamter[]
            {
                new QueryParamter("Id", comboBox2.SelectedValue.ToString(), "int")
            };

            DataTable table = DBUtils.getDataTable("GetProducts", parameters);

            int itemTotal = Int32.Parse(textBox3.Text) * Int32.Parse(table.Rows[0][4].ToString());

            dataGridView1.Rows.Add(table.Rows[0][1], table.Rows[0][2], table.Rows[0][3], table.Rows[0][4], textBox3.Text, itemTotal);

            int total = Int32.Parse(textBox1.Text) + itemTotal;

            textBox1.Text = total.ToString();
        }
Example #3
0
        public static DataSet getDataSet(string method, QueryParamter[] parameters)
        {
            connect();
            command = new SqlCommand(method, connection);
            command.CommandType = CommandType.StoredProcedure;

            foreach (QueryParamter parameter in parameters)
            {
                command.Parameters.Add("@" + parameter.Name, paramTypes[parameter.Type]).Value = parameter.Value;
            }

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);

            return dataset;
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            QueryParamter[] parameters = new QueryParamter[]
            {
                new QueryParamter("Name", textBox1.Text, "varchar"),
                new QueryParamter("Description", textBox2.Text, "varchar"),
                new QueryParamter("Price", textBox3.Text, "varchar"),
                new QueryParamter("SellingPrice", textBox4.Text, "varchar"),
            };

            DBUtils.insertData("AddProducts", parameters);

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";

            
            MessageBox.Show("New Product added");
        }
Example #5
0
        public static string getValue(string method, QueryParamter[] parameters, QueryParamter result)
        {
            connect();
            command = new SqlCommand(method, connection);
            command.CommandType = CommandType.StoredProcedure;

            foreach (QueryParamter parameter in parameters)
            {
                command.Parameters.Add("@" + parameter.Name, paramTypes[parameter.Type]).Value = parameter.Value;
            }

            SqlParameter parameterResult = command.Parameters.Add("@" + result.Name, paramTypes[result.Type]);
            parameterResult.Direction = ParameterDirection.Output;
            parameterResult.Size = 50;

            command.ExecuteNonQuery();


            return parameterResult.Value.ToString();
        }
Example #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            QueryParamter[] parameters = new QueryParamter[]
            {
                new QueryParamter("SuplrId", comboBox1.SelectedValue.ToString(), "int"),
                new QueryParamter("DateTime", dateTime, "varchar"),
                new QueryParamter("Total", textBox1.Text, "varchar"),
                new QueryParamter("AmountPaid", textBox2.Text, "varchar"),
            };

            DBUtils.insertData("AddPurchase", parameters);

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";

            dataGridView1.Rows.Clear();

            MessageBox.Show("Purchase data added");
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text.Equals(""))
            {
                MessageBox.Show("Please enter an account no");
                return;
            }
            else if (!textBox3.Text.StartsWith("2"))
            {
                MessageBox.Show("Account no must start with 2");
                return;
            }
            else if (textBox3.Text.Length != 6)
            {
                MessageBox.Show("Account no must be 6 digit");
                return;
            }
            else
            {
                try
                {
                    long.Parse(textBox3.Text);

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Account no must a number");
                    return;
                }
            }

            if (textBox2.Text.Equals(""))
            {
                MessageBox.Show("Please enter a name");
                return;
            }
            else if ((textBox2.Text.Length < 5) || (textBox2.Text.Length > 20))
            {
                MessageBox.Show("Name must be 5 to 20 characters");
                return;
            }

            if (textBox4.Text.Equals(""))
            {
                MessageBox.Show("Please enter an address");
                return;
            }

            string suplrId = textBox1.Text.Split(new char[] { '_' })[1];
            QueryParamter[] parameters = new QueryParamter[]
            {
                new QueryParamter("Id", suplrId, "int"),
                new QueryParamter("Name", textBox2.Text, "varchar"),
                new QueryParamter("AccountNo", textBox3.Text, "varchar"),
                new QueryParamter("Address", textBox4.Text, "varchar"),
            };

            DBUtils.insertData("AddSupplier", parameters);

            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";

            GetNextKey();

            MessageBox.Show("New Supplier added");
        }
Example #8
0
 private void GetNextKey()
 {
     QueryParamter outputParam = new QueryParamter("SuplrId", "", "varchar");
     string custId = DBUtils.getValue("NextSuplrId", new QueryParamter[] { }, outputParam);
     textBox1.Text = custId;
 }