// GET: ItemType public ActionResult AllTypes() { List <Item_type> obj = new List <Item_type>(); using (SqlConnection con = new SqlConnection(cs)) { // //Authorization string query = "Select * from [Item_type]"; using (SqlCommand cmd = new SqlCommand(query)) { cmd.Connection = con; // opening connection con.Open(); cs = con.State.ToString(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Item_type np = new Item_type(); np.I_type_id = (int)sdr["I_type_id"]; np.I_type_name = (string)sdr["I_type_name"]; obj.Add(np); } } } return(View(obj)); }
public ActionResult NewItems() { // get categories List <Item_type> obj = new List <Item_type>(); List <Karigar> kobj = new List <Karigar>(); List <Saleman> sobj = new List <Saleman>(); // New_Item tobj = new New_Item(); New_Item Parent = new New_Item(); string karigarqery = "Select * from [Karigar]"; string itemquery = "Select * from [Item_type]"; string salemanquery = "Select * from [Saleman]"; string tagquery = "SELECT TOP 1 [I_tag_no] FROM [Items] ORDER BY [I_id] DESC"; using (SqlConnection con = new SqlConnection(cs)) { using (SqlCommand cmd = new SqlCommand(itemquery)) { cmd.Connection = con; // opening connection con.Open(); cs = con.State.ToString(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Item_type np = new Item_type(); np.I_type_id = (int)sdr["I_type_id"]; np.I_type_name = (string)sdr["I_type_name"]; obj.Add(np); } con.Close(); } using (SqlCommand cmd = new SqlCommand(salemanquery)) { cmd.Connection = con; // opening connection con.Open(); cs = con.State.ToString(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Saleman snp = new Saleman(); snp.S_id = (int)sdr["S_id"]; snp.S_name = (string)sdr["S_name"]; sobj.Add(snp); } con.Close(); } using (SqlCommand cmd = new SqlCommand(karigarqery)) { cmd.Connection = con; // opening connection con.Open(); cs = con.State.ToString(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Karigar knp = new Karigar(); knp.K_id = (int)sdr["K_id"]; knp.K_name = (string)sdr["K_name"]; kobj.Add(knp); } con.Close(); } using (SqlCommand cmd = new SqlCommand(tagquery)) { cmd.Connection = con; con.Open(); cs = con.State.ToString(); SqlDataReader tdr = cmd.ExecuteReader(); New_Item tnp = new New_Item(); if (tdr.Read()) { tnp.I_tag_no = (int)tdr["I_tag_no"] + 1; temptag = tnp.I_tag_no.ToString(); } else { tnp.I_tag_no = 5000; temptag = tnp.I_tag_no.ToString(); } Parent.I_tag_no = tnp.I_tag_no; con.Close(); } } Parent.Iobj = obj; Parent.Kobj = kobj; Parent.Sobj = sobj; return(View(Parent)); }