private void btnCustomer_Click(object sender, EventArgs e)
        {
            using (var conn = new SqlConnection(conStr))
            {
                var cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "Select AccountNo,AccountName,Phone,Address,Balance,BranchID from Customer";
                conn.Open();

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                List <CustomerCls> customer = new List <CustomerCls>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    CustomerCls obj = new CustomerCls();
                    obj.AccNo   = Convert.ToInt32(dt.Rows[i]["AccountNo"].ToString());
                    obj.AccName = dt.Rows[i]["AccountName"].ToString();
                    obj.Address = dt.Rows[i]["Address"].ToString();
                    obj.Phone   = dt.Rows[i]["Phone"].ToString();
                    obj.Balance = Convert.ToDecimal(dt.Rows[i]["Balance"].ToString());
                    obj.Branch  = Convert.ToInt32(dt.Rows[i]["BranchID"].ToString());
                    customer.Add(obj);
                }
                using (CustomerPrintReport prForm = new CustomerPrintReport(customer))
                {
                    prForm.ShowDialog();
                }
            }
        }
Example #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            using (var conn = new SqlConnection(conStr))
            {
                CustomerCls customer = new CustomerCls();
                try
                {
                    customer.AccNo = Convert.ToInt32(textAccNo.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                customer.AccName = textAccName.Text;

                customer.Phone = textPhone.Text;

                customer.Address = textAddress.Text;
                try
                {
                    decimal blnc = Convert.ToDecimal(textBalance.Text);
                    customer.Balance = blnc;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                try
                {
                    int branches = Convert.ToInt32(cmbBranch.SelectedValue);
                    customer.Branch = branches;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                int count = 0;
                var cmd   = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "Delete from Customer where AccountNo=" + customer.AccNo + " and  AccountName='" + customer.AccName + "'";

                conn.Open();
                count = cmd.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("DELETED...");
                }
                else
                {
                    MessageBox.Show("ERROR!!!");
                }
            }
            LoadDataInGrid();
            ClearTextBox();
        }
Example #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (var conn = new SqlConnection(conStr))
            {
                CustomerCls customer = new CustomerCls();
                try
                {
                    customer.AccNo = Convert.ToInt32(textAccNo.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Account no needed");
                }
                customer.AccName = textAccName.Text;

                customer.Phone = textPhone.Text;

                customer.Address = textAddress.Text;
                try
                {
                    customer.Balance = Convert.ToDecimal(textBalance.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Enter your amount");
                }
                try
                {
                    int branches = Convert.ToInt32(cmbBranch.SelectedValue);
                    customer.Branch = branches;
                }
                catch (Exception)
                {
                    MessageBox.Show("Branch needed");
                }
                customer.Photo = null;
                FileStream   stream  = new FileStream(imgLocation, FileMode.Open, FileAccess.Read);
                BinaryReader binRead = new BinaryReader(stream);
                customer.Photo = binRead.ReadBytes((int)stream.Length);
                string   file     = imgLocation;
                string[] files    = file.Split('\\');
                string   fileName = files[files.Length - 1];
                string   filePath = @"E:\Evidence\Module6 XML ADO.NET CristalReport\Project\Project ADO.Net\BankManagementSolution\BankManagement\Pictures" + fileName;
                File.Copy(file, filePath, true);

                string query = "Insert into Customer (AccountNo,AccountName,Phone, Address,Balance,BranchID,ImageName,ImagePath,Photo) " +
                               "values ('" + customer.AccNo + "','" + customer.AccName + "','" + customer.Phone + "','" + customer.Address + "','" + customer.Balance + "','" + customer.Branch + "','" + fileName + "','" + filePath + "',@pics)";
                SqlCommand cmd = new SqlCommand(query, conn);
                cmd.Parameters.Add(new SqlParameter("@pics", customer.Photo));
                conn.Open();

                int count = 0;
                count = cmd.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("INSERTED...");
                }
                else
                {
                    MessageBox.Show("ERROR!!!");
                }
            }
            LoadDataInGrid();
            ClearTextBox();
        }