private void materialRaisedButton2_Click(object sender, EventArgs e) { //string cono = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"E:\\Samama\\grandee project\\samama.mdf\";Integrated Security=True"; using (IDbConnection db = new SqlConnection(cono)) { if (db.State == ConnectionState.Closed) { db.Open(); string querry = "select s.id_sale, c.id_cus,c.cus_name,c.cus_phone,c.cus_account, s.date,s.item,s.vehicle_no,s.bags,s.rate,s.total_ammount,s.paid_amount,s.balance_amount " + "from Sales s, Customer c " + "where s.id_cus = c.id_cus AND c.id_cus = '" + materialSingleLineTextField4.Text + "' AND date between'" + dateTimePicker2.Value + "'and'" + dateTimePicker3.Value + "' "; // salesrepBindingSource1.DataSource = db.Query<salesrep>(querry, commandType: CommandType.Text); List <salesrep> list = db.Query <salesrep>(querry, commandType: CommandType.Text).ToList(); db.Close(); using (frmprint n = new frmprint(c, list, dateTimePicker2.Value.ToShortDateString(), dateTimePicker3.Value.ToShortDateString())) n.ShowDialog(); //SqlConnection sql = new SqlConnection(cono); //sql.Open(); //string qury = "select SUM(balance_amount) from Sales s,Customer c where s.id_cus = c.id_cus AND s.id_cus = '" + materialSingleLineTextField4.Text + "' AND date between'" + dateTimePicker2.Value + "'and'" + dateTimePicker3.Value + "' "; //SqlCommand ss = new SqlCommand(qury, sql); //SqlDataReader sqr; //try //{ // sqr = ss.ExecuteReader(); // while (sqr.Read()) // { // a = sqr.GetInt32(0); // } // MessageBox.Show(a.ToString()); //} //catch //{ // ss.ExecuteNonQuery(); //} //cono.Clone(); } } }
private void materialRaisedButton3_Click(object sender, EventArgs e) { using (IDbConnection db = new SqlConnection(cono)) { if (db.State == ConnectionState.Closed) { db.Open(); string querry = "select s.id_sale, c.id_cus,c.cus_name,c.cus_phone,c.cus_account, s.date,s.item,s.vehicle_no,s.bags,s.rate,s.total_ammount,s.paid_amount,s.balance_amount " + "from Sales s, Customer c " + "where s.id_cus = c.id_cus AND c.id_cus = '" + id + "' AND date between'" + todate + "'and'" + fromdate + "' "; // salesrepBindingSource1.DataSource = db.Query<salesrep>(querry, commandType: CommandType.Text); List <salesrep> list = db.Query <salesrep>(querry, commandType: CommandType.Text).ToList(); db.Close(); SqlConnection sql = new SqlConnection(cono); sql.Open(); string qury = "SELECT BalanceAmount from Balances WHERE b_cusId='" + id + "'"; SqlCommand ss = new SqlCommand(qury, sql); SqlDataReader sqr; try { sqr = ss.ExecuteReader(); while (sqr.Read()) { b = sqr.GetInt32(0); } sqr.Close(); } catch { ss.ExecuteNonQuery(); } sql.Close(); SqlConnection sqls = new SqlConnection(cono); sqls.Open(); string qurey = "select SUM(balance_amount) from Sales s,Customer c where s.id_cus = c.id_cus AND s.id_cus = '" + id + "' AND date between'" + todate + "'and'" + fromdate + "' "; SqlCommand sso = new SqlCommand(qurey, sqls); SqlDataReader sq; try { sq = sso.ExecuteReader(); while (sq.Read()) { a = sq.GetInt32(0); } sq.Close(); } catch { sso.ExecuteNonQuery(); } sqls.Close(); using (frmprint n = new frmprint(b, list, todate, fromdate)) n.ShowDialog(); } SqlConnection con = new SqlConnection(cono); con.Open(); SqlCommand sc = new SqlCommand("Update Balances set BalanceAmount=BalanceAmount +'" + a + "' where b_cusId='" + id + "';", con); int o = sc.ExecuteNonQuery(); MessageBox.Show(o + "iupdate"); con.Close(); } }