Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1] CRUD OPERATION CONNECTED ARCHITECTURE
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- getAll();
- }
- MySqlConnection CN;
- MySqlCommand CMD;
- MySqlDataReader DR;
- DataTable DT;
- int curr_index = 0;
- public void getAll()
- {
- CN = new MySqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
- CN.Open();
- CMD = new MySqlCommand("select * from crudopr", CN);
- DR = CMD.ExecuteReader();
- DT = new DataTable("con");
- DT.Load(DR);
- navigate(curr_index);
- }
- public void navigate(int a)
- {
- if (DT.Rows.Count > 0)
- {
- textbox1.Text = DT.Rows[a][0].ToString();
- textBox2.Text = DT.Rows[a][1].ToString();
- textBox3.Text = DT.Rows[a][2].ToString();
- }
- }
- private void btn1_Click(object sender, EventArgs e)
- {
- curr_index = 0;
- navigate(curr_index);
- }
- private void btn4_Click(object sender, EventArgs e)
- {
- curr_index = DT.Rows.Count - 1;
- navigate(curr_index);
- }
- private void btn2_Click(object sender, EventArgs e)
- {
- if (curr_index > 0)
- {
- curr_index--;
- navigate(curr_index);
- }
- }
- private void btn3_Click(object sender, EventArgs e)
- {
- if (curr_index < DT.Rows.Count - 1)
- {
- curr_index++;
- navigate(curr_index);
- }
- }
- private void btn5_Click(object sender, EventArgs e)
- {
- textbox1.Text = String.Empty;
- textBox2.Text = String.Empty;
- textBox3.Text = String.Empty;
- }
- private void btn6_Click(object sender, EventArgs e)
- {
- CN = new MySqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
- CN.Open();
- CMD = new MySqlCommand("insert into crudopr values('" + textbox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')", CN);
- CMD.ExecuteNonQuery();
- getAll();
- }
- private void btn7_Click(object sender, EventArgs e)
- {
- CN = new MySqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
- CN.Open();
- CMD = new MySqlCommand("update crudopr set name='" + textBox2.Text + "',city='" + textBox3.Text + "'where id='" + textbox1.Text + "'", CN);
- CMD.ExecuteNonQuery();
- getAll();
- }
- private void btn8_Click(object sender, EventArgs e)
- {
- CN = new MySqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
- CN.Open();
- CMD = new MySqlCommand("delete from crudopr where id='" + textbox1.Text + "'", CN);
- CMD.ExecuteNonQuery();
- getAll();
- }
- }
- }
- </startup>
- <connectionStrings>
- <add name="con" connectionString="server=127.0.0.1;port=3306;database=dotnet1;uid=root" providerName="MySql.Data.MySqlClient"/>
- </connectionStrings>
- </configuration>
- 2] DELIGATE (CONSOLE APPLICATION)
- [program.cs]
- namespace InfowayAtm
- {
- public delegate void InfowauAtm();
- class Program
- {
- private long accountno;
- private int atmpin;
- private int widrowl;
- public event InfowauAtm SelectedEvent;
- public event InfowauAtm RejectedEvent;
- public long Accountno
- {
- get
- {
- return accountno;
- }
- set
- {
- accountno = value;
- }
- }
- public int Atmpin
- {
- get
- {
- return atmpin;
- }
- set
- {
- atmpin = value;
- }
- }
- public int Widrowl
- {
- get
- {
- return widrowl;
- }
- set
- {
- widrowl = value;
- }
- }
- public string Getresult(int widrowl, string CardHolderName)
- {
- CardHolderName = "Rohan Ramola";
- string result = "";
- if (Widrowl > 10000)
- {
- RejectedEvent();
- result = "Ony your are withdrawl more then 10000 amount Sorry..!! :";
- }
- else
- {
- SelectedEvent();
- result = "withdrawl your amount.collect Amount...!!";
- }
- return result;
- }
- }
- }
- [main.cs]
- namespace InfowayAtm
- {
- class main
- {
- static void Main(string [] args)
- {
- Console.WriteLine("Welcome Infoway Atm");
- try
- {
- Program pro = new Program();
- pro.SelectedEvent += new InfowauAtm(events);
- pro.RejectedEvent += rej;
- pro.SelectedEvent += sel;
- Console.WriteLine("Enter your Account NUmber ::");
- pro.Accountno = long.Parse(Console.ReadLine());
- Console.WriteLine("Enter your ATM PIN number ::");
- pro.Atmpin = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter your withdrawl amount");
- pro.Widrowl = int.Parse(Console.ReadLine());
- if (pro.Widrowl < 10000)
- {
- pro.SelectedEvent -= sel;
- }
- string CardHolderName = "YASH";
- Console.WriteLine(pro.Getresult(pro.Widrowl, CardHolderName));
- Console.WriteLine("Account Holder ::" + "" + CardHolderName);
- }
- catch (Exception av)
- {
- Console.WriteLine(av.Message);
- }
- Console.ReadKey();
- }
- private static void sel()
- {
- Console.WriteLine("u r selected");
- }
- private static void rej()
- {
- Console.WriteLine("u r rejected");
- }
- private static void more()
- {
- Console.WriteLine("withdrawl more then 10000");
- }
- private static void widrol()
- {
- Console.WriteLine("plese withdrawl lesss then 10000");
- }
- private static void events()
- {
- Console.WriteLine("Transaction in process");
- int x = 0;
- Console.WriteLine("you want to print u r recipt And You want to recive msg on u r phone::: yes(Enter any other then '0') or No(0)");
- x = int.Parse(Console.ReadLine());
- if (x >= 1)
- {
- Console.WriteLine("Take amount withdrawl resipt");
- Console.WriteLine("Enter your mobile For sms ::");
- long ds = long.Parse(Console.ReadLine());
- Console.WriteLine("Your Amount withdrawl sms is send your mobile ::" + "" + ds);
- }
- else
- {
- Console.WriteLine("Thank You..!!");
- }
- }
- }
- }
- 3] LOGIN WITH SESSION
- SIMPLELOGIN.ASPX.CS[WEB FORM]
- namespace Login
- {
- public partial class Simplelogin : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- MySqlConnection CN = new MySqlConnection("server=127.0.0.1; port=3306;database=dac20;uid=root");
- CN.Open();
- MySqlCommand CMD = new MySqlCommand("select * from login where username=@username and pwd=@password", CN);
- CMD.Parameters.AddWithValue("@username", Textb1.Text);
- CMD.Parameters.AddWithValue("@password", Textb2.Text);
- MySqlDataAdapter DA = new MySqlDataAdapter(CMD);
- DataTable DT = new DataTable();
- DA.Fill(DT);
- if (DT.Rows.Count > 0)
- {
- Response.Redirect("Details.aspx");
- }
- else
- {
- Response.Redirect("Register.aspx");
- }
- }
- protected void btnlogin_Click(object sender, EventArgs e)
- {
- }
- }
- }
- SIMPLELOGIN.ASPX
- <body>
- <form id="form1" runat="server">
- <table>
- <tr>
- <td>USERNAME:</td>
- <td><asp:TextBox ID="Textb1" runat="server"></asp:TextBox></br>
- </tr>
- <tr><td>PASSWORD:</td>
- <td><asp:TextBox ID="Textb2" runat="server"></asp:TextBox></td>
- </tr>
- <tr>
- <td><asp:Button ID="btnlogin" runat="server" Text="LOGIN" OnClick="btnlogin_Click" /></td>
- <td><asp:Button ID="btnreset" runat="server" Text="RESET" /></td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="lblError" runat="server" ></asp:Label>
- </td>
- </tr>
- </table>
- </form>
- </body>
- REGISTER.ASPX[WEB FORM]
- <form id="form1" runat="server">
- <table>
- <tr>
- <td>FIRST NAME:</td>
- <td><asp:TextBox ID="fname" runat="server"></asp:TextBox></br>
- </tr>
- <tr>
- <td>LAST NAME:</td>
- <td><asp:TextBox ID="lname" runat="server"></asp:TextBox></br>
- </tr>
- <tr>
- <td>QUALIFICATION:</td>
- <td><asp:TextBox ID="quali" runat="server"></asp:TextBox></br>
- </tr>
- <tr>
- <td>EMAIL:</td>
- <td><asp:TextBox ID="email" runat="server"></asp:TextBox></br>
- </tr>
- <tr>
- <td><asp:Button ID="reg" runat="server" Text="SUBMIT" OnClick="reg_Click" /></td>
- <td><asp:Button ID="reset" runat="server" Text="RESET" /></td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="lblError1" runat="server" ></asp:Label>
- </td>
- </tr>
- </table>
- </form>
- REGISTER.ASPX.CS
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void reg_Click(object sender, EventArgs e)
- {
- MySqlConnection CN = new MySqlConnection("server=127.0.0.1; port=3306;database=dac20;uid=root");
- CN.Open();
- // MySqlCommand CMD = new MySqlCommand("insert into registeruser (fname,lname,qualification,email) values(@fname,@lname,@qualification,@email)", CN);
- MySqlCommand CMD = new MySqlCommand("insert into registeruser (fname,lname,qualification,email) values('"+fname.Text+"','"+lname.Text+"','"+quali.Text+"','"+email.Text+"')", CN);
- CMD.ExecuteNonQuery();
- Response.Redirect("Simplelogin.aspx");
- }
- DETAIL.ASPX.CS
- protected void Page_Load(object sender, EventArgs e)
- {
- MySqlConnection CN = new MySqlConnection("server=127.0.0.1; port=3306;database=dac20;uid=root");
- CN.Open();
- MySqlCommand CMD = new MySqlCommand("select distinct(qualification) from registeruser");
- CMD.ExecuteNonQuery();
- Response.Redirect("Details.aspx");
- }
- DETAIL.ASPX
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- Select the stream which You want to search Job News:
- <asp:DropDownList ID="DropDownList1" runat="server">
- </asp:DropDownList>
- </form>
- </body>
- GLOBAL.ASPX.CS
- public class Global : System.Web.HttpApplication
- {
- protected void Application_Start(object sender, EventArgs e)
- {
- }
- protected void Session_Start(object sender, EventArgs e)
- {
- Session["login"] = null;
- }
- protected void Session_End(object sender, EventArgs e)
- {
- Session["login"] = null;
- }
- protected void Application_End(object sender, EventArgs e)
- {
- }
- }
- 4] FILEUPLOADING
- FILEUPLOAD.ASPX.CS[WEB FORM]
- namespace FileUpload1
- {
- public partial class FileUpload : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
- string contentType = FileUpload1.PostedFile.ContentType;
- using (Stream fs = FileUpload1.PostedFile.InputStream)
- {
- using (BinaryReader br = new BinaryReader(fs))
- {
- //byte[] bytes = br.ReadBytes((Int32)fs.Length);
- using (MySqlConnection CN = new MySqlConnection("server=127.0.0.1;port=3306;database=dac20;uid=root"))
- {
- string query = "insert into tblFile1 values(@Name,@ContentType)";
- using (MySqlCommand CMD = new MySqlCommand(query))
- {
- CMD.Connection = CN;
- CMD.Parameters.AddWithValue("@Name", filename);
- CMD.Parameters.AddWithValue("@ContentType", contentType);
- //CMD.Parameters.AddWithValue("@Data", bytes);
- CN.Open();
- CMD.ExecuteNonQuery();
- CN.Close();
- }
- }
- }
- }
- lblMsg.Text = "File Uploaded Successfully";
- }
- }
- }
- FILEUPLOAD.ASPX
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:FileUpload ID="FileUpload1" runat="server" />
- <br />
- <asp:Button ID="btnUpload" runat="server" Text="Upload File" OnClick="btnUpload_Click" />
- <hr />
- <asp:Label ID="lblMsg" runat="server"></asp:Label>
- </div>
- </form>
- </body>
- 5] LINQ
- Program.cs(class library)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- namespace LinqQuery
- {
- class Program
- {
- static void Main(string[] args)
- {
- //var query1 = from cust in GetALLcustomers()
- // select cust;
- //foreach (Customer c in GetALLcustomers())
- //{
- // Console.WriteLine("customerId {0}, ContactName {1} city{2}", c.CustomerId, c.ContactName, c.City);
- // //Console.WriteLine("Customer Id {0}, Contact Name {1} lives in city {2}", c.CustomerId, c.ContactName, c.City);
- //}
- //var query2 = from emp in GetAllEmployee()
- // where emp.EmpName.StartsWith("x")
- // orderby emp.EmpName descending
- // select new Employee { EmployeeId = emp.EmployeeId, EmpName = emp.EmpName, sal = emp.sal };
- //foreach (Employee emp in GetAllEmployee())
- //{
- // Console.WriteLine("EmployeeId {0}, EmpName {1} sal{2}", emp.EmployeeId, emp.EmpName, emp.sal);
- //}
- //Console.ReadKey();
- //Console.WriteLine(" ");
- var query3 = from prd in GetAllProducts()
- where prd.ProductName.Contains("c")
- orderby prd.ProductName descending
- select new Product { ProductId = prd.ProductId, ProductName = prd.ProductName, UnitPrice = prd.UnitPrice, AvlQty = prd.AvlQty };
- foreach (Product prd in GetAllProducts())
- {
- Console.WriteLine("productId {0}, productName {1} unitPrice {2} avlquty {3}", prd.ProductId, prd.ProductName, prd.UnitPrice, prd.AvlQty);
- }
- Console.ReadLine();
- Console.WriteLine(" ");
- //var query4 = from cust in GetALLcustomers()
- // join
- // ord in GetAllOrders()
- // on cust.CustomerId equals ord.CustomerId
- // join
- // Prd in GetAllProducts()
- // on ord.ProductId equals Prd.ProductId
- // join
- // emp in GetAllEmployee()
- // on ord.EmployeeId equals emp.EmployeeId
- // join
- // sup in GetAllSupplier()
- // on Prd.SupplierId equals sup.SupplierId
- // join
- // cat in GetAllCategory()
- // on Prd.CategoryId equals cat.CategoryId
- // select new { OrderNumber = ord.OrderId, CustomerName = cust.ContactName, TotalAmount = ord.Quantity * ord.UnitPrice, DeliveryDate = ord.RequiredDate, Product = Prd.ProductName, Employee = emp.EmpName, Supplier = sup.supplierName, Category = cat.CategoryName };
- //foreach (var co in query4)
- //{
- // Console.WriteLine("Order Id {0}, Customer Name {1} total amount {2} Delivery Date {3}, Product Name {4} EmpName {5} SupplierName {6} CategoryName {7}", co.OrderNumber, co.CustomerName, co.TotalAmount, co.DeliveryDate.ToShortDateString(), co.Product, co.Employee, co.Supplier, co.Category);
- //}
- //try
- //{
- //Console.WriteLine(" xml example$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
- //var myXmlOrder = new XElement("Employee", new XAttribute("EmployeeId", 1), new XAttribute("EmpName", "priyanka"), new XAttribute("sal", 145536), new XElement("Categorys", new XAttribute("CategoryId", 1), new XAttribute("CategoryName", "Pravin R. D."), new XAttribute("Description", 1)));
- //Console.WriteLine(myXmlOrder);
- //myXmlOrder.Save(@"z:\InfowayOrder.xml");
- //Console.ReadKey();
- //}
- //catch (UnauthorizedAccessException)
- //{
- // throw;
- //}
- }
- public static List<Customer> GetALLcustomers()
- {
- return new List<Customer>() {
- new Customer() { CustomerId = 1, ContactName = "pinky", City = "pune" },
- new Customer() { CustomerId = 2, ContactName = "nilupama", City = "konva" },
- new Customer() {CustomerId=3,ContactName="kanna", City="gova"}
- };
- }
- public static List<Employee>GetAllEmployee()
- {
- return new List<Employee>()
- {
- new Employee() {EmployeeId=01,EmpName="Alice",sal=1200},
- new Employee() {EmployeeId=02, EmpName="Martin",sal=580 },
- new Employee() {EmployeeId=03,EmpName="xtz",sal=8000}
- };
- }
- public static List<Product>GetAllProducts()
- {
- return new List<Product>()
- {
- new Product() {ProductId=1,ProductName="computer",UnitPrice=123,AvlQty=3, CategoryId=1, SupplierId=1 },
- new Product() {ProductId=2,ProductName="pendrive",UnitPrice=345,AvlQty=4, CategoryId=2, SupplierId=2 },
- new Product() {ProductId=3,ProductName="bottle",UnitPrice=35,AvlQty=32, CategoryId=3, SupplierId=2 }
- };
- }
- public static List<Order>GetAllOrders()
- {
- return new List<Order>()
- {
- new Order() { OrderId=1,OrderDate=DateTime.Now, RequiredDate=DateTime.Now, Quantity=2, UnitPrice=254, CustomerId=1, EmployeeId=01, ProductId=1 },
- new Order() {OrderId=2, OrderDate=DateTime.Now, RequiredDate=DateTime.Now, Quantity=3, UnitPrice=210, CustomerId=2, EmployeeId=02, ProductId=3 },
- new Order() { OrderId=3,OrderDate=DateTime.Now,RequiredDate=DateTime.Now, Quantity=1,UnitPrice=3,CustomerId=3, EmployeeId=03,ProductId=2 }
- };
- }
- public static List<Supplier>GetAllSupplier()
- {
- return new List<Supplier>()
- {
- new Supplier() {SupplierId=1, supplierName="ABC", SupplierAddress="Kothrud,Pune" },
- new Supplier() { SupplierId=2, supplierName="xyz",SupplierAddress="D.P Road" },
- new Supplier() {SupplierId=3,supplierName="PQR",SupplierAddress="Pune" }
- };
- }
- public static List<Category> GetAllCategory()
- {
- return new List<Category>()
- {
- new Category() {CategoryId=1,CategoryName="priya",Description="some good product"},
- new Category() { CategoryId=2,CategoryName="surbhi",Description="supplies product" },
- new Category() {CategoryId=3,CategoryName="dghjjkk",Description="employee goods"}
- };
- }
- //private static List<Employee> GetallEmp()
- //{
- // var Employees = from xmlEmployee in XElement.Load(@"c:\users\dac37\documents\visual studio 2015\Projects\Day4-6-17\LinqQuery\XMLFile1.xml").Elements()
- // select new Employee
- // {
- // EmployeeId= int.Parse(xmlEmployee.Attribute("EmployeeId").Value),
- // EmpName = xmlEmployee.Attribute("EmpName").Value,
- // sal = int.Parse(xmlEmployee.Attribute("sal").Value),
- // };
- // return Employees.ToList();
- //}
- }
- }
- CUSTOMER.CS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LinqQuery
- {
- class Customer
- {
- public int CustomerId { get; set; }
- public string ContactName { get; set; }
- public string City { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement