public IEnumerable <string> GetSerialNames(IEnumerable <Guid> guids, bool deleted) { using (LinqDataContext l = new LinqDataContext()) { return(l.СерийныйНомерs.Where(w => guids.Contains(w.Oid) && (!deleted ? w.GCRecord == null : w.GCRecord != null)).Select(s => s.Номер).ToList()); } }
public IEnumerable <string> GetConsignmentNames(IEnumerable <Guid> guids, bool deleted) { using (LinqDataContext l = new LinqDataContext()) { return(l.СпецификацияПартияs.Where(w => guids.Contains(w.Oid) && (!deleted ? w.GCRecord == null : w.GCRecord != null)).Select(s => s.Партия).ToList()); } }
public IEnumerable <string> GetNomenclatureNames(IEnumerable <Guid> guids, bool deleted) { using (LinqDataContext l = new LinqDataContext()) { return(l.НоменклатурнаяПозицияs.Where(w => guids.Contains(w.Oid) && (!deleted ? w.GCRecord == null : w.GCRecord != null)).Select(s => s.СтроковоеПредставление).ToList()); } }
public MyObservableCollection <Inmueble> GetInmuebles() { hasError = false; MyObservableCollection <Inmueble> inmueble = new MyObservableCollection <Inmueble>(); try { LinqDataContext dc = new LinqDataContext(); var query = from q in dc.LinqProducts select new SqlInmueble { InmuebleId = q.ProductID, Direccion = q.ModelNumber, Vendedor = q.ModelName, Precio = (decimal)q.UnitCost, Descripcion = q.Description, Categoria = q.LinqCategory.CategoryName }; foreach (SqlInmueble sp in query) { inmueble.Add(sp.SqlProduct2Product()); } } catch (Exception ex) { errorMessage = "GetInmuebles() error, " + ex.Message; hasError = true; } return(inmueble); }
static void Main() { string columnToGroupBy = "Size"; // generate the dynamic Expression<Func<Product, string>> ParameterExpression p = Expression.Parameter(typeof(Product), "p"); var selector = Expression.Lambda <Func <Product, string> >( Expression.Property(p, columnToGroupBy), p ); using (LinqDataContext dataContext = new LinqDataContext()) { /* using "selector" caluclated above which is automatically * compiled when the query runs */ var results = dataContext .Products .GroupBy(selector) .Select((group) => new { Key = group.Key, Count = group.Count() }); foreach (var result in results) { Console.WriteLine("{0}: {1}", result.Key, result.Count); } } Console.ReadKey(); }
public static void EndMissionDate() { var bank = new LinqDataContext(); var query = from p in bank.sarbazs where p.مدت_ماموریت_ماه_ != null select p; foreach (var items in query) { PersianCalendar pcalender = new PersianCalendar(); DateTime date = pcalender.ToDateTime(Convert.ToDateTime(items.تاریخ_اعزام).Year, Convert.ToDateTime(items.تاریخ_اعزام).Month, Convert.ToDateTime(items.تاریخ_اعزام).Day, 0, 0, 0, 0, 0 ); var x = items.مدت_ماموریت_ماه_; if (x == "" || x == null) { x = "0"; } DateTime date_EndMission = date.AddMonths(Convert.ToInt32(x)); items.تاریخ_اتمام_ماموریت = pcalender.GetYear(date_EndMission) + "/" + pcalender.GetMonth(date_EndMission) + "/" + pcalender.GetDayOfMonth(date_EndMission); } // return date_EndMission; bank.SubmitChanges(); }
public IEnumerable <string> GetDocumentNames(IEnumerable <Guid> guids, bool deleted) { using (LinqDataContext l = new LinqDataContext()) { return(l.Документs.Where(w => guids.Contains(w.Oid) && (!deleted ? w.GCRecord == null : w.GCRecord != null)).Select(s => s.СтроковоеПредставление).ToList()); } }
public ProductObservableCollection <Product> GetProducts() { hasError = false; ProductObservableCollection <Product> products = new ProductObservableCollection <Product>(); try { LinqDataContext dc = new LinqDataContext(); var query = from q in dc.LinqProducts select new ProductModel { ProductId = q.ProductID, ModelNumber = q.ModelNumber, ModelName = q.ModelName, UnitCost = (decimal)q.UnitCost, Description = q.Description, CategoryName = q.LinqCategory.CategoryName }; foreach (ProductModel sp in query) { products.Add(sp.ProductModel2Product()); } } //try catch (Exception ex) { errorMessage = "GetProducts() error, " + ex.Message; hasError = true; } return(products); } //GetProducts()
public static LinqDataContext getLinqContext() { if (Linq == null) { Linq = new LinqDataContext(); } return(Linq); }
public static bool checkEmailDoanvien(int ID, string email) { LinqDataContext db = new LinqDataContext(); var dt = (from a in db.DoanViens where a.ID != ID && a.Email.Trim() == email select a).Count(); return(dt == 0); }
public string[] getStaffList(string prefixText, int count) { LinqDataContext db = new LinqDataContext(); var result = from u in db.TBDS_STAFFINFOs where u.ST_CODE.StartsWith(prefixText) select u.ST_CODE + " " + u.ST_NAME; result = result.Take <string>(count); string[] stufflist = result.ToArray <string>(); return(stufflist); }
public string[] getWarehouseList(string prefixText, int count) { LinqDataContext db = new LinqDataContext(); var result = from u in db.TBWS_WAREHOUSEINFOs where u.WS_ID.StartsWith(prefixText) select u.WS_ID + " " + u.WS_NAME; result = result.Take <string>(count); string[] warehouselist = result.ToArray <string>(); return(warehouselist); }
public string[] getSupplierList(string prefixText, int count) { LinqDataContext db = new LinqDataContext(); var result = from u in db.TBCS_CUSUPINFOs where u.CS_HRCODE.StartsWith(prefixText) select u.CS_CODE + " " + u.CS_NAME; result = result.Take <string>(count); string[] supplierlist = result.ToArray <string>(); return(supplierlist); }
private void FrmApply_M_Load(object sender, EventArgs e) { var bank = new LinqDataContext(); var query = (from p in bank.Gradetbls orderby p.Id_Grade select new { p.Id_Grade, p.Grade }).Distinct(); comboBox_Grade.DataSource = query; comboBox_Grade.DisplayMember = "Grade"; comboBox_Grade.ValueMember = "Id_Grade"; }
public Controller() { memLinq = new LinqDataContext(); swLog = MemLinq.Log as StreamWriter; string sICol3Max = global::VNTSellGold.Properties.Resources.ICol3Max; if (!string.IsNullOrEmpty(sICol3Max)) { iCol3Tbl5Max = Convert.ToInt32(sICol3Max); } }
public string[] getDepList(string prefixText, int count) { LinqDataContext db = new LinqDataContext(); var result = from u in db.TBDS_DEPINFOs where u.DEP_CODE.StartsWith(prefixText) select u.DEP_CODE + " " + u.DEP_NAME; result = result.Take <string>(count); string[] deplist = result.ToArray <string>(); return(deplist); }
public static void FreeDate() { var bank = new LinqDataContext(); var query = from p in bank.sarbazs // where p.Id_Sarbaz == Id_sarbaz select p; foreach (var items in query) { var x = items.مدت_كسر_خدمت_به_روز; var y = items.خدمت_قبلی_روز; var z = items.مدت_اضافه_خدمت_روز; if (x == "" || x == null) { x = "0"; } if (y == "" || y == null) { y = "0"; } if (z == "" || z == null) { z = "0"; } int Day_variable = -Convert.ToInt32(x) - Convert.ToInt32(y) + Convert.ToInt32(z); PersianCalendar pcalender = new PersianCalendar(); PersianDate pDateObj = new PersianDate(); int year = Convert.ToDateTime(items.تاریخ_اعزام).Year; int month = Convert.ToDateTime(items.تاریخ_اعزام).Month; int day = Convert.ToDateTime(items.تاریخ_اعزام).Day; pDateObj.increasePersianMonth(ref year, ref month, 21); DateTime date = pcalender.ToDateTime(year, month, day, 0, 0, 0, 0, 0 ); // DateTime date_FreeDate = date.AddMonths(21); DateTime date_FreeDate1 = date.AddDays(Day_variable); items.تاریخ_ترخیص = pcalender.GetYear(date_FreeDate1) + "/" + pcalender.GetMonth(date_FreeDate1) + "/" + pcalender.GetDayOfMonth(date_FreeDate1); } //return date_FreeDate; bank.SubmitChanges(); }
public bool UpdateInmueble(Inmueble mostrarInmueble) { try { SqlInmueble inmueble = new SqlInmueble(mostrarInmueble); LinqDataContext dc = new LinqDataContext(); dc.UpdateInmueble(inmueble.InmuebleId, inmueble.Categoria, inmueble.Direccion, inmueble.Vendedor, inmueble.Precio, inmueble.Descripcion); } catch (Exception ex) { errorMessage = "Update error, " + ex.Message; hasError = true; } return(!hasError); }
} //GetProducts() /* * private string GetStringOrNull(SqlDataReader reader, string columnName) * { * return reader.IsDBNull(reader.GetOrdinal(columnName)) ? "" : (string)reader[columnName]; * } */ /* * private const int prodStringLen = 50; * public bool UpdateProduct(Product displayP) * { * SqlProduct p = new SqlProduct( displayP); * hasError = false; * SqlConnection con = new SqlConnection(conString); * SqlCommand cmd = new SqlCommand("UpdateProduct", con); * cmd.CommandType = CommandType.StoredProcedure; * cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); * cmd.Parameters["@ProductId"].Value = p.ProductId; * cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@ModelNumber"].Value = p.ModelNumber; * cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@ModelName"].Value = p.ModelName; * cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal); * cmd.Parameters["@UnitCost"].Value = p.UnitCost; * cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200); * cmd.Parameters["@Description"].Value = p.Description; * cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@CategoryName"].Value = p.CategoryName; * int rows = 0; * try * { * con.Open(); * rows = cmd.ExecuteNonQuery(); * } * catch (SqlException ex) * { * errorMessage = "Update SQL error, " + ex.Message; * hasError = true; * } * catch (Exception ex) * { * errorMessage = "Update error, " + ex.Message; * hasError = true; * } * finally * { * con.Close(); * } * return (!hasError); * } //UpdateProduct() */ public bool UpdateProduct(Product displayP) { try { SqlProduct p = new SqlProduct(displayP); LinqDataContext dc = new LinqDataContext(); dc.UpdateProduct(p.ProductId, p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description); } catch (Exception ex) { errorMessage = "Update error, " + ex.Message; hasError = true; } return(!hasError); } //UpdateProduct()
public bool DeleteInmueble(int inmuebleId) { hasError = false; try { LinqDataContext dc = new LinqDataContext(); dc.DeleteInmueble(inmuebleId); } catch (Exception ex) { errorMessage = "Delete error, " + ex.Message; hasError = true; } return(!hasError); }
} //UpdateProduct() /* * public bool DeleteProduct(int productId) * { * hasError = false; * SqlConnection con = new SqlConnection(conString); * SqlCommand cmd = new SqlCommand("DeleteProduct", con); * cmd.CommandType = CommandType.StoredProcedure; * cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); * cmd.Parameters["@ProductId"].Value = productId; * try * { * con.Open(); * int rows = cmd.ExecuteNonQuery(); * } * catch (SqlException ex) * { * errorMessage = "DELETE SQL error, " + ex.Message; * hasError = true; * } * catch (Exception ex) * { * errorMessage = "DELETE error, " + ex.Message; * hasError = true; * } * finally * { * con.Close(); * } * return !hasError; * }// DeleteProduct() */ public bool DeleteProduct(int productId) { hasError = false; try { LinqDataContext dc = new LinqDataContext(); dc.DeleteProduct(productId); } catch (Exception ex) { errorMessage = "Delete error, " + ex.Message; hasError = true; } return(!hasError); }// DeleteProduct()
private void btn_Save_Click(object sender, EventArgs e) { LinqDataContext linq = new LinqDataContext(Properties.Settings.Default.ConnectionString); Voucher.Tb_HrEmp emp = new Voucher.Tb_HrEmp(); emp.EmpNo = EmpNoTextEdit.Text; emp.FullNameArab = FullNameArabTextEdit.Text; emp.FullNameEng = FullNameArabTextEdit.Text; emp.IqamaNo = FullNameArabTextEdit.Text; emp.Is_deleted = false; linq.Tb_HrEmps.InsertOnSubmit(emp); linq.SubmitChanges(); MessageBox.Show("New Employee Added Successfully"); Loadagain(); }
public static void Estehghaghi() { var bank = new LinqDataContext(); var query = from p in bank.sarbazs // where p.Id_Sarbaz==Id_sarbaz select p; foreach (var items in query) { var x = items.مدت_كسر_خدمت_به_روز; var y = items.خدمت_قبلی_روز; var z = items.مدت_اضافه_خدمت_روز; if (x == "" || x == null) { x = "0"; } if (y == "" || y == null) { y = "0"; } if (z == "" || z == null) { z = "0"; } int Day_variable = -Convert.ToInt32(x) - Convert.ToInt32(y) + Convert.ToInt32(z); double Mounth_Variable = Convert.ToInt32(Day_variable / 30); var Khedmat_Mounth = 21 + Mounth_Variable; int E; if (items.تاهل == true) { E = Convert.ToInt32(Khedmat_Mounth * 2.5); } else { E = Convert.ToInt32(Khedmat_Mounth * 1); } items.استحقاقی = Convert.ToString(E); } bank.SubmitChanges(); // return E; }
private void FrmEdit_M_Load(object sender, EventArgs e) { var LinqObj = new LinqDataContext(); var query = (from tempTbl in LinqObj.Mashmoolins where tempTbl.Id_Mashmoolin == int.Parse(txtID_M.Text) select tempTbl).Single(); this.txtID.Text = query.شماره_ملی; this.txtName.Text = query.نام; this.txtLastName.Text = query.نام_خانوادگی; this.txtFatherName.Text = query.نام_پدر; this.txt_BirthYear.Text = query.تاریخ_تولد; var bank = new LinqDataContext(); var query1 = (from p in bank.Gradetbls orderby p.Id_Grade select new { p.Id_Grade, p.Grade }).Distinct(); comboBox_Grade.DataSource = query1; comboBox_Grade.DisplayMember = "Grade"; comboBox_Grade.ValueMember = "Id_Grade"; comboBox_Grade.Text = query.تحصیلات; txt_Address.Text = query.آدرس; txt_mobile.Text = query.تلفن; txt_Explain.Text = query.توضیحات; txt_Reshteh.Text = query.رشته; txt_Moaref.Text = query.معرف; txt_Basij.Text = query.سابقه_بسیج_فعال; txt_HozehJazb.Text = query.حوزه_جذب; txt_Ezaf.Text = query.اضاف; chBox_Takmili.Checked = Convert.ToBoolean(query.تکمیلی); chBox_ThirthDay.Checked = Convert.ToBoolean(query.سی_روزه); chBox_Moaf.Checked = Convert.ToBoolean(query.معاف_از_رزم); chBox_Komiteh.Checked = Convert.ToBoolean(query.کمیته_امداد); chBox_Behzisti.Checked = Convert.ToBoolean(query.سازمان_بهزیستی); chBox_Taahol.Checked = Convert.ToBoolean(query.تاهل); txt_EzamDate.Text = query.تاریخ_اعزام; }
public string[] getMaterialIDList(string prefixText, int count) { LinqDataContext db = new LinqDataContext(); var result1 = from u in db.TBMA_BZJINFOs where u.BZJ_HMCODE.StartsWith(prefixText) select u.BZJ_ID + " " + u.BZJ_NAME; var result2 = from v in db.TBMA_RAWMAINFOs where v.RM_HMCODE.StartsWith(prefixText) select v.RM_ID + " " + v.RM_NAME; var result3 = from w in db.TBMA_LVCGMAINFOs where w.LVCG_HMCODE.StartsWith(prefixText) select w.LVCG_ID + " " + w.LVCG_NAME; result1 = result1.Union <string>(result2); result1 = result1.Union <string>(result3); result1 = result1.Take <string>(count); string[] materialidlist = result1.ToArray <string>(); return(materialidlist); }
/* public bool AddProduct(Product displayP) { SqlProduct p = new SqlProduct(displayP); hasError = false; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("AddProduct", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@ModelNumber"].Value = p.ModelNumber; cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@ModelName"].Value = p.ModelName; cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal); cmd.Parameters["@UnitCost"].Value = p.UnitCost; cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200); cmd.Parameters["@Description"].Value = p.Description; if (p.Description==null) cmd.Parameters["@Description"].Value = DBNull.Value; cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@CategoryName"].Value = p.CategoryName; cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); cmd.Parameters["@ProductId"].Value = p.ProductId; cmd.Parameters["@ProductId"].Direction = ParameterDirection.Output; try { con.Open(); int rows = cmd.ExecuteNonQuery(); //create the new product in DB p.ProductId = (int)cmd.Parameters["@ProductId"].Value; //set the returned ProductId in the SqlProduct object displayP.ProductAdded2DB(p); //update corresponding Product ProductId using SqlProduct } catch (SqlException ex) { errorMessage = "Add SQL error, " + ex.Message; hasError = true; } catch (Exception ex) { errorMessage = "ADD error, " + ex.Message; hasError = true; } finally { con.Close(); } return !hasError; } //AddProduct() */ public bool AddProduct(Product displayP) { hasError = false; try { SqlProduct p = new SqlProduct(displayP); LinqDataContext dc = new LinqDataContext(); int? newProductId = 0; dc.AddProduct(p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description, ref newProductId); p.ProductId = (int)newProductId; displayP.ProductAdded2DB(p); //update corresponding Product ProductId using SqlProduct } catch (Exception ex) { errorMessage = "Add error, " + ex.Message; hasError = true; } return !hasError; }
public List <Employee> GetEmployees() { List <Employee> list = new List <Employee>(); using (LinqDataContext linq = new LinqDataContext()) { list = linq.SecuritySystemUsers .Where(w => w.GCRecord == null && (w.Примечание != null || w.Компьютер != null)) .OrderBy(o => o.ФИО) .Select(s => new Employee { Name = s.ФИО, Phone = s.Примечание, Machine = s.Компьютер }) .ToList(); } return(list); }
}// DeleteProduct() /* * public bool AddProduct(Product displayP) * { * SqlProduct p = new SqlProduct(displayP); * hasError = false; * SqlConnection con = new SqlConnection(conString); * SqlCommand cmd = new SqlCommand("AddProduct", con); * cmd.CommandType = CommandType.StoredProcedure; * cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@ModelNumber"].Value = p.ModelNumber; * cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@ModelName"].Value = p.ModelName; * cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal); * cmd.Parameters["@UnitCost"].Value = p.UnitCost; * cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200); * cmd.Parameters["@Description"].Value = p.Description; * if (p.Description==null) cmd.Parameters["@Description"].Value = DBNull.Value; * cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen); * cmd.Parameters["@CategoryName"].Value = p.CategoryName; * cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); * cmd.Parameters["@ProductId"].Value = p.ProductId; * cmd.Parameters["@ProductId"].Direction = ParameterDirection.Output; * try * { * con.Open(); * int rows = cmd.ExecuteNonQuery(); //create the new product in DB * p.ProductId = (int)cmd.Parameters["@ProductId"].Value; //set the returned ProductId in the SqlProduct object * displayP.ProductAdded2DB(p); //update corresponding Product ProductId using SqlProduct * } * catch (SqlException ex) * { * errorMessage = "Add SQL error, " + ex.Message; * hasError = true; * } * catch (Exception ex) * { * errorMessage = "ADD error, " + ex.Message; * hasError = true; * } * finally * { * con.Close(); * } * return !hasError; * } //AddProduct() */ public bool AddProduct(Product displayP) { hasError = false; try { SqlProduct p = new SqlProduct(displayP); LinqDataContext dc = new LinqDataContext(); int? newProductId = 0; dc.AddProduct(p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description, ref newProductId); p.ProductId = (int)newProductId; displayP.ProductAdded2DB(p); //update corresponding Product ProductId using SqlProduct } catch (Exception ex) { errorMessage = "Add error, " + ex.Message; hasError = true; } return(!hasError); } //AddProduct()
public bool AddInmueble(Inmueble mostrarInmueble) { hasError = false; try { SqlInmueble inmueble = new SqlInmueble(mostrarInmueble); LinqDataContext dc = new LinqDataContext(); int? nuevoInmuebleId = 0; dc.AddInmueble(inmueble.Categoria, inmueble.Direccion, inmueble.Vendedor, inmueble.Precio, inmueble.Descripcion, ref nuevoInmuebleId); inmueble.InmuebleId = (int)nuevoInmuebleId; mostrarInmueble.ProductAdded2DB(inmueble); } catch (Exception ex) { errorMessage = "Add error, " + ex.Message; hasError = true; } return(!hasError); }
private void btnApply_Click(object sender, EventArgs e) { var LinqObj = new LinqDataContext(); var query = (from tempTbl in LinqObj.Mashmoolins where tempTbl.Id_Mashmoolin == int.Parse(txtID_M.Text) select tempTbl).Single(); query.شماره_ملی = this.txtID.Text; query.نام = this.txtName.Text; query.نام_خانوادگی = this.txtLastName.Text; query.نام_پدر = this.txtFatherName.Text; query.تاریخ_تولد = txt_BirthYear.Text; query.آدرس = txt_Address.Text; query.تلفن = txt_mobile.Text; query.تحصیلات = comboBox_Grade.Text.ToString(); query.کد_تحصیلات = Convert.ToInt32(comboBox_Grade.SelectedValue); query.رشته = txt_Reshteh.Text; query.معرف = txt_Moaref.Text; query.سابقه_بسیج_فعال = txt_Basij.Text; query.حوزه_جذب = txt_HozehJazb.Text; query.اضاف = txt_Ezaf.Text; query.تکمیلی = chBox_Takmili.Checked; query.سی_روزه = chBox_ThirthDay.Checked; query.معاف_از_رزم = chBox_Moaf.Checked; query.کمیته_امداد = chBox_Komiteh.Checked; query.سازمان_بهزیستی = chBox_Behzisti.Checked; query.تاهل = chBox_Taahol.Checked; query.توضیحات = txt_Explain.Text; query.تاریخ_اعزام = txt_EzamDate.Text; LinqObj.SubmitChanges(); this.Close(); }
private void btnApply_Click(object sender, EventArgs e) { try { var LinqObj = new LinqDataContext(); var GradeReshtehObj = new Grade_Reshteh(); var c = LinqObj.Grade_Reshtehs.Count(); if (GVFeildCapacity.RowCount >= 1) { for (int i = 1; i <= c; i++) { if (GVFeildCapacity.Rows[i].Cells[4].Value.ToString() == "") { GradeReshtehObj.Capacity = int.Parse(GVFeildCapacity.Rows[i].Cells[4].Value.ToString()); } LinqObj.Grade_Reshtehs.InsertOnSubmit(GradeReshtehObj); } LinqObj.SubmitChanges(); ///////////////// referesh GVtable ///////////// var bank = new LinqDataContext(); var query = from temp in bank.Grade_Reshtehs join tempjoin in bank.Reshtehas on temp.Id_CodeReshteh equals tempjoin.Id join tempjoin2 in bank.Gradetbls on temp.Id_Grade equals tempjoin2.Id_Grade select new { temp.Id_Grade_Reshteh, tempjoin2.Grade, tempjoin.Reshteh, tempjoin.CodeReshteh, temp.Capacity }; GVFeildCapacity.DataSource = query; ////////////////////////////////////////////////// } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
public void Dispose() { linqDc = null; errorLogDal = null; }
public DatabaseAccessObject() { linqDc = new LinqDataContext(); }
/* private string GetStringOrNull(SqlDataReader reader, string columnName) { return reader.IsDBNull(reader.GetOrdinal(columnName)) ? "" : (string)reader[columnName]; } */ /* private const int prodStringLen = 50; public bool UpdateProduct(Product displayP) { SqlProduct p = new SqlProduct( displayP); hasError = false; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("UpdateProduct", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); cmd.Parameters["@ProductId"].Value = p.ProductId; cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@ModelNumber"].Value = p.ModelNumber; cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@ModelName"].Value = p.ModelName; cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal); cmd.Parameters["@UnitCost"].Value = p.UnitCost; cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200); cmd.Parameters["@Description"].Value = p.Description; cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen); cmd.Parameters["@CategoryName"].Value = p.CategoryName; int rows = 0; try { con.Open(); rows = cmd.ExecuteNonQuery(); } catch (SqlException ex) { errorMessage = "Update SQL error, " + ex.Message; hasError = true; } catch (Exception ex) { errorMessage = "Update error, " + ex.Message; hasError = true; } finally { con.Close(); } return (!hasError); } //UpdateProduct() */ public bool UpdateProduct(Product displayP) { try { SqlProduct p = new SqlProduct(displayP); LinqDataContext dc = new LinqDataContext(); dc.UpdateProduct(p.ProductId, p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description); } catch (Exception ex) { errorMessage = "Update error, " + ex.Message; hasError = true; } return (!hasError); }
/* private string conString = Properties.Settings.Default.StoreDBConnString; public MyObservableCollection<Product> GetProducts() { hasError = false; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("GetProducts", con); cmd.CommandType = CommandType.StoredProcedure; MyObservableCollection<Product> products = new MyObservableCollection<Product>(); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //create a Product object for the row SqlProduct sqlProduct = new SqlProduct( (int) reader["ProductId"], (string)reader["ModelNumber"], (string)reader["ModelName"], (decimal)reader["UnitCost"], GetStringOrNull(reader, "Description"), (String)reader["CategoryName"]); products.Add(sqlProduct.SqlProduct2Product()); } //while } //try catch (SqlException ex) { errorMessage = "GetProducts SQL error, " + ex.Message; hasError = true; } catch (Exception ex) { errorMessage = "GetProducts error, " + ex.Message; hasError = true; } finally { con.Close(); } return products; } //GetProducts() */ public MyObservableCollection<Product> GetProducts() { hasError = false; MyObservableCollection<Product> products = new MyObservableCollection<Product>(); try { LinqDataContext dc = new LinqDataContext(); var query = from q in dc.LinqProducts select new SqlProduct{ ProductId = q.ProductID, ModelNumber = q.ModelNumber, ModelName=q.ModelName, UnitCost = (decimal)q.UnitCost, Description = q.Description, CategoryName = q.LinqCategory.CategoryName }; foreach (SqlProduct sp in query) products.Add(sp.SqlProduct2Product()); } //try catch(Exception ex) { errorMessage = "GetProducts() error, " + ex.Message; hasError = true; } return products; }
/* public bool DeleteProduct(int productId) { hasError = false; SqlConnection con = new SqlConnection(conString); SqlCommand cmd = new SqlCommand("DeleteProduct", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4); cmd.Parameters["@ProductId"].Value = productId; try { con.Open(); int rows = cmd.ExecuteNonQuery(); } catch (SqlException ex) { errorMessage = "DELETE SQL error, " + ex.Message; hasError = true; } catch (Exception ex) { errorMessage = "DELETE error, " + ex.Message; hasError = true; } finally { con.Close(); } return !hasError; }// DeleteProduct() */ public bool DeleteProduct(int productId) { hasError = false; try { LinqDataContext dc = new LinqDataContext(); dc.DeleteProduct(productId); } catch (Exception ex) { errorMessage = "Delete error, " + ex.Message; hasError = true; } return !hasError; }