2. SqlClientCode For Calling StoredProcedure for Getting Data
2. Service
Execute Code From Visual Studio For Update And Save
3. SqlClientCode For Getting Connection String
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
- public JsonResult BuyerList()
- {
- Chemical_DAL obj_dal = new Chemical_DAL();
- return Json(obj_dal.BuyerList());
- }
2. Service
- public class QUERY
- {
- public string SQL { get; set; }
- public Dictionary<string, string> PARAMETER { get; set; }
- public Dictionary<string, byte[]> BYTEPARAMETER { get; set; }
- }
- public List<Buyer> BuyerList() //public List<Buyer>
- {
- List<Buyer> buyerList = new List<Buyer>();
- string error = string.Empty;
- QUERY query = new QUERY();
- query.SQL = @"SELECT ID, BuyerShortName
- FROM dbo.tblBuyerList order by BuyerShortName asc";
- DataTable dt = new DataTable ();
- dt = cls.GetDataTable253_Mymun(query, out error);
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- Buyer Buyer = new Buyer();
- int BuyerID;
- Int32.TryParse(dt.Rows[i]["ID"].ToString().Trim(), out BuyerID);
- Buyer.ID = BuyerID;
- Buyer.BuyerShortName = dt.Rows[i]["BuyerShortName"].ToString();
- buyerList.Add(Buyer);
- }
- }
- return buyerList;
- }
- public DataTable GetDataTable253_Mymun(QUERY query, out string ERROR)
- {
- SqlConnection con = getConnection253_Mymun();
- var dt = new DataTable();
- try
- {
- con.Open();
- SqlCommand command = new SqlCommand();
- command.Connection = con;
- command.CommandType = CommandType.Text;
- command.CommandText = query.SQL;
- if (query.PARAMETER != null)
- {
- foreach (KeyValuePair<string, string> data in query.PARAMETER)
- {
- if (data.Value != null)
- command.Parameters.AddWithValue(data.Key, data.Value);
- else
- command.Parameters.AddWithValue(data.Key, DBNull.Value);
- }
- }
- if (query.BYTEPARAMETER != null)
- {
- foreach (KeyValuePair<string, byte[]> data in query.BYTEPARAMETER)
- {
- if (data.Value != null)
- command.Parameters.AddWithValue(data.Key, data.Value);
- else
- command.Parameters.AddWithValue(data.Key, DBNull.Value);
- }
- }
- SqlDataReader dr = command.ExecuteReader();
- ERROR = String.Empty;
- dt.Load(dr);
- }
- catch (SqlException ex)
- {
- ERROR = ex.ToString();
- }
- finally
- {
- con.Close();
- }
- return dt;
- }
Execute Code From Visual Studio For Update And Save
- public JsonResult SaveData(Menu.Models.ChemicalStore.DyesChemical savedobj)
- {
- ALLMENU allMenu = new ALLMENU();
- allMenu = (ALLMENU)Session["Menu"];
- Chemical_DAL obj_dal = new Chemical_DAL();
- return Json(obj_dal.SaveData(savedobj, allMenu.User.EMPLOYEE_ID));
- }
- public string SaveData(DyesChemical savedobj, string EMPLOYEE_ID)
- {
- string error = String.Empty;
- QUERY query = new QUERY();
- Dictionary<string, string> dict = new Dictionary<string, string>();
- string maxid = savedobj.ItemID;
- if (maxid == null)
- {
- query.SQL = @"insert into tblDCIMDyesAndChemicalItemList ( Entry_date,ItemTypeID, ItemGroupID, ItemName, ItemTypeListID, ItemStatusID, ItemBehaviourID, ItemDescription)values(@Entry_date,@ItemTypeID,@ItemGroupID,@ItemName,@ItemTypeListID,@ItemStatusID,@ItemBehaviourID,@ItemDescription)";
- dict.Add("@Entry_date", savedobj.Entry_date);
- dict.Add("@ItemTypeID", savedobj.ItemTypeID);
- dict.Add("@ItemGroupID", savedobj.ItemGroupID);
- dict.Add("@ItemName", savedobj.ItemName);
- dict.Add("@ItemTypeListID", savedobj.ItemTypeListID);
- dict.Add("@ItemStatusID", savedobj.ItemStatusID);
- dict.Add("@ItemBehaviourID", savedobj.ItemBehaviourID);
- dict.Add("@ItemDescription", savedobj.ItemDescription);
- query.PARAMETER = dict;
- cls.ExecuteSql253_Mymun(query, out error);
- if (error.Length > 0)
- {
- }
- else
- {
- query.SQL = @"SELECT MAX(ItemID) FROM dbo.tblDCIMDyesAndChemicalItemList";
- DataTable dt = cls.GetDataTable253_Mymun(query, out error);
- maxid = dt.Rows[0][0].ToString();
- }
- }
- return maxid;
- }
- public int ExecuteSql253_Mymun(QUERY query, out string ERROR)
- {
- SqlConnection con = getConnection253_Mymun();
- con.Open();
- int result = 0;
- try
- {
- SqlCommand command = new SqlCommand();
- command.Connection = con;
- command.CommandType = CommandType.Text;
- command.CommandText = query.SQL;
- if (query.PARAMETER != null)
- {
- foreach (KeyValuePair<string, string> data in query.PARAMETER)
- {
- if (data.Value != null)
- command.Parameters.AddWithValue(data.Key, data.Value);
- else
- command.Parameters.AddWithValue(data.Key, DBNull.Value);
- }
- }
- if (query.BYTEPARAMETER != null)
- {
- foreach (KeyValuePair<string, byte[]> data in query.BYTEPARAMETER)
- {
- if (data.Value != null)
- command.Parameters.AddWithValue(data.Key, data.Value);
- else
- command.Parameters.AddWithValue(data.Key, DBNull.Value);
- }
- }
- result = command.ExecuteNonQuery();
- ERROR = String.Empty;
- }
- catch (SqlException ex)
- {
- ERROR = ex.Message.ToString();
- }
- finally
- {
- con.Close();
- }
- return result;
- }
3. SqlClientCode For Getting Connection String
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
- public SqlConnection getConnection253_Mymun()
- {
- string connStr = @"data source=192.168.153.208;database=HamdunSoftProject;uid=sa;password=hamdunsoft1234";
- SqlConnection conn = new SqlConnection(connStr);
- return conn;
- }
No comments:
Post a Comment