public static NhaXe CreateNhaXe(string Tennhaxe, string Anh, int Soluongxe, string Trusochinh, string Nguoidaidien, string Sodienthoai, string Gioithieungan, string Gioithieuchitiet, int Tinh) { vexedtEntities context = new vexedtEntities(); var nx = nhaxeRepo.Add(new NhaXe { Tennhaxe = Tennhaxe, Sodienthoai = Sodienthoai, Trusochinh = Trusochinh, Soluongxe = Soluongxe, Nguoidaidien = Nguoidaidien, Gioithieuchitiet = Gioithieuchitiet, Gioithieungan = Gioithieungan, Anh = Anh, Tinh = Tinh }); nhaxeRepo.Save(); return(nx); }
public static NhaXe UpdateNhaXe(int Id, string Tennhaxe, string Anh, int Soluongxe, string Trusochinh, string Nguoidaidien, string Sodienthoai, string Gioithieungan, string Gioithieuchitiet, int Tinh) { var nx = nhaxeRepo.Find(Id); vexedtEntities context = new vexedtEntities(); if (nx != null) { nx.Tennhaxe = Tennhaxe; nx.Sodienthoai = Sodienthoai; nx.Trusochinh = Trusochinh; nx.Soluongxe = Soluongxe; nx.Nguoidaidien = Nguoidaidien; nx.Gioithieuchitiet = Gioithieuchitiet; nx.Gioithieungan = Gioithieungan; nx.Anh = Anh; nx.Tinh = Tinh; } nhaxeRepo.Save(); return(nx); }
protected void btnSave_Click(object sender, EventArgs e) { vexedtEntities context = new vexedtEntities(); try { var nx = nhaxeRepo.Add(new NhaXe { Tennhaxe = Tennhaxe.Text, Sodienthoai = Sodienthoai.Text, Trusochinh = Trusochinh.Text, Soluongxe = int.Parse(Soluongxe.Text), Nguoidaidien = Nguoidaidien.Text, Gioithieuchitiet = Gioithieuchitiet.Text, Gioithieungan = Gioithieungan.Text, Anh = txtImg.Text, Tinh = int.Parse(Tinh.SelectedValue) }); nhaxeRepo.Save(); Tennhaxe.Text = ""; Sodienthoai.Text = ""; Trusochinh.Text = ""; Soluongxe.Text = ""; Nguoidaidien.Text = ""; Gioithieuchitiet.Text = ""; Gioithieungan.Text = ""; txtImg.Text = ""; catimg.Visible = false; Tinh.Items[0].Selected = true; MSG.Text = string.Format(ErrorMessage.Success, "Thêm nhà xe " + Tennhaxe.Text); MSG.ForeColor = Color.Green; } catch (Exception ex) { MSG.ForeColor = Color.Green; MSG.Text = string.Format(ErrorMessage.Fail, "Thêm nhà xe"); throw new Exception(ErrorMessage.UnknowError + ":" + ex.Message); } }
protected void btnUpdate_Click(object sender, EventArgs e) { NhaxeRepository nhaxeRepo = new NhaxeRepository(); vexedtEntities context = new vexedtEntities(); try { if (nx != null) { nx.Tennhaxe = Tennhaxe.Text; nx.Sodienthoai = Sodienthoai.Text; nx.Trusochinh = Trusochinh.Text; nx.Soluongxe = int.Parse(Soluongxe.Text); nx.Nguoidaidien = Nguoidaidien.Text; nx.Gioithieuchitiet = Gioithieuchitiet.Text; nx.Gioithieungan = Gioithieungan.Text; nx.Anh = txtImg.Text; nx.Tinh = int.Parse(Tinh.SelectedValue); } nhaxeRepo.Save(); Hashtable tb = new Hashtable(); tb.Add("Tennhaxe", Tennhaxe.Text); tb.Add("Trusochinh", Trusochinh.Text); tb.Add("Soluongxe", Soluongxe.Text); tb.Add("Nguoidaidien", Nguoidaidien.Text); tb.Add("Gioithieuchitiet", Gioithieuchitiet.Text); tb.Add("Anh", txtImg.Text); tb.Add("Tinh", Tinh.SelectedValue); tb.Add("Sodienthoai", Sodienthoai.Text); UpdateData.Update("Nhaxe", tb, "ID=" + ID); ltrScript.Text = ("<script>parent.showMsg('" + string.Format(ErrorMessage.Success, "Sửa nhà xe") + "'); parent.window.location.reload();</script>"); } catch (Exception) { throw; } }
public CodeRepository() { this.ChildDataContext = new vexedtEntities(); SetUp(ChildDataContext); }
public static string ExecuteScalar(int mid, string sp, string param, int fldcount) { var c = new JsonSerializer(); dynamic obj = c.Deserialize(new StringReader(param), typeof(object)); var context = new vexedtEntities(); FldRepository fldRepo = new FldRepository(); var fld = fldRepo.SearchFor(o => o.ModAdminId == mid).ToList(); List <string> lst = new List <string>(); List <SqlParameter> para = new List <SqlParameter>(); foreach (var item in fld) { if (obj[item.FldName] != null) { sp += " @" + item.FldName; if (fld.IndexOf(item) < fldcount) { sp += ","; } item.tbl_ModAdmin = null; lst.Add((string)item.FldName); SqlParameter parameter = new SqlParameter(); switch (item.FldType) { case "PK": case "CCB": case "NUM": parameter.SqlDbType = System.Data.SqlDbType.Int; if (obj[item.FldName] == null) { parameter.Value = 0; } else { parameter.Value = (int)(obj[item.FldName]); } break; case "TIME": parameter.SqlDbType = System.Data.SqlDbType.NVarChar; if (obj[item.FldName] == null) { parameter.Value = DBNull.Value; } else { parameter.Value = (string)(obj[item.FldName]); } break; case "DATE": parameter.SqlDbType = System.Data.SqlDbType.Date; if (obj[item.FldName] == null) { parameter.Value = DBNull.Value; } else { parameter.Value = (DateTime)(obj[item.FldName]); } break; case "FLOAT": parameter.SqlDbType = System.Data.SqlDbType.Float; if (obj[item.FldName] == null) { parameter.Value = 0; } else { parameter.Value = (double)(obj[item.FldName]); } break; case "TXT": case "HTML": parameter.SqlDbType = System.Data.SqlDbType.NVarChar; if (obj[item.FldName] == null) { parameter.Value = DBNull.Value; } else { parameter.Value = (string)(obj[item.FldName]); } break; case "CKB": parameter.SqlDbType = System.Data.SqlDbType.Bit; if (obj[item.FldName] == null) { parameter.Value = false; } else { parameter.Value = (bool)(obj[item.FldName]); } break; default: parameter.SqlDbType = System.Data.SqlDbType.NVarChar; if (obj[item.FldName] == null) { parameter.Value = DBNull.Value; } else { parameter.Value = (string)(obj[item.FldName]); } break; } parameter.ParameterName = item.FldName; para.Add(parameter); } } int res; try { res = context.Database.ExecuteSqlCommand(sp, para.ToArray()); } catch (Exception ex) { return(sp + "\n" + JsonConvert.SerializeObject(para) + "\n" + ex.ToString()); } return(JsonConvert.SerializeObject(res)); }
public TuyenduongRepository() { this.ChildDataContext = new vexedtEntities(); SetUp(ChildDataContext); }