public LanguageDir GetSingle(Int32 Id) { LanguageDir obj = new LanguageDir(); try { string query = "select * from language_dirs where ID = " + Id + ""; SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); DataTable dt = new DataTable(); SqlDataAdapter dA = new SqlDataAdapter(cmd); dA.Fill(dt); obj = (from x in dt.AsEnumerable() select new LanguageDir { Id = x.Field <Int32>("id"), Module = x.Field <Int32>("module"), Remarks = x.Field <String>("remarks"), Status = x.Field <Int32>("status"), TextEn = x.Field <String>("text_en"), TextId = x.Field <String>("text_id"), TextTh = x.Field <String>("text_th"), TextMs = x.Field <String>("text_ms"), TextPage = x.Field <String>("text_page"), TextZh = x.Field <String>("text_zh"), }).ToList().FirstOrDefault(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public static object Add(LanguageDir obj) { Int32 LoginUserId = 0; if (HttpContext.Current.Session["UserId"] != null) { LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString()); } try { if (obj.Id == 0) { ILanguageDirService.PostData(obj); } else { ILanguageDirService.UpdateData(obj); } return(true); } catch (Exception ex) { Console.WriteLine("Add language dir action: " + ex.Message); return(false); } }
public LanguageDir UpdateData(LanguageDir obj) { try { obj = ILanguageDirRepo.UpdateData(obj); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public LanguageDir DeleteData(Int32 Id) { LanguageDir obj = new LanguageDir(); try { obj = ILanguageDirRepo.DeleteData(Id); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public LanguageDir UpdateData(LanguageDir obj) { try { //string query = obj.ObjectToQuery<LanguageDir>("update"); string query = "UPDATE language_dirs SET text_id = '" + obj.TextId + "', status = '" + obj.Status + "', remarks = '" + obj.Remarks + "', module = '" + obj.Module + "', text_page = '" + obj.TextPage + "', text_en = '" + obj.TextEn + "', text_th = N'" + obj.TextTh + "', text_ms = N'" + obj.TextMs + "', text_zh = N'" + obj.TextZh + "' where ID = " + obj.Id + ";"; SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); cmd.ExecuteNonQuery(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public LanguageDir DeleteData(Int32 Id) { LanguageDir obj = GetSingle(Id); try { string query = obj.ObjectToQuery <LanguageDir>("update"); SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); cmd.ExecuteNonQuery(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public LanguageDir PostData(LanguageDir obj) { try { //string query = obj.ObjectToQuery<LanguageDir>("insert") + "SELECT SCOPE_IDENTITY()"; string query = @"INSERT INTO language_dirs(module, remarks, status, text_en, text_id, text_th, text_ms, text_page, text_zh) VALUES ('" + obj.Module + "','" + obj.Remarks + "','" + obj.Status + "','" + obj.TextEn + "','" + obj.TextId + "',N'" + obj.TextTh + "',N'" + obj.TextMs + "','" + obj.TextPage + "',N'" + obj.TextZh + "'); SELECT SCOPE_IDENTITY()"; SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); // cmd.ExecuteNonQuery(); obj.Id = Convert.ToInt32(cmd.ExecuteScalar()); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
protected void Page_Load(object sender, EventArgs e) { Int32 LoginUserId = 0; if (HttpContext.Current.Session["UserId"] != null) { LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString()); } string path = AppDomain.CurrentDomain.BaseDirectory; DirectoryInfo currentDir = new DirectoryInfo(path); DirectoryInfo parentDir = new DirectoryInfo(currentDir.Parent.FullName + "\\Silverlake.Web\\"); FileInfo[] Files = parentDir.GetFiles("*.aspx"); TextPage.DataSource = Files; TextPage.DataTextField = "Name"; TextPage.DataValueField = "Name"; TextPage.DataBind(); //TextPage.Items.Insert(0, new ListItem() //{ // Text = "Select", // Value = "" //}); string idString = Request.QueryString["id"]; if (idString != null && idString != "") { int id = Convert.ToInt32(idString); LanguageDir languageDir = ILanguageDirService.GetSingle(id); ID.Value = languageDir.Id.ToString(); Module.Value = languageDir.Module.ToString(); TextId.Value = languageDir.TextId; TextPage.Value = languageDir.TextPage.ToString(); TextEn.Value = languageDir.TextEn.ToString(); TextMs.Value = languageDir.TextMs.ToString(); TextZh.Value = languageDir.TextZh.ToString(); TextTh.Value = languageDir.TextTh.ToString(); Status.Value = languageDir.Status.ToString(); Remarks.Value = languageDir.Remarks; } }
public Int32 DeleteBulkData(List <Int32> Ids) { Int32 result = 0; try { string query = ""; Ids.ForEach(Id => { LanguageDir obj = GetSingle(Id); query += obj.ObjectToQuery <LanguageDir>("update"); }); SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); result = cmd.ExecuteNonQuery(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(result); }