private void copyStock(string username1, string username2) { //copy Stock var ctx = gen.GetNewEntity(); // khai bao new entity Framework var query = ctx.UserJoinStocks .Where(c => c.UserName == username1 && c.CompanyCode == Globals.companycode); foreach (var data in query) { UserJoinStock obj = new UserJoinStock(); obj.StockCode = data.StockCode; obj.UserName = username2; obj.CompanyCode = data.CompanyCode; ctx.UserJoinStocks.Add(obj); //insert } try { ctx.SaveChanges(); XtraMessageBox.Show("Copy stocks successfully", "Copy", MessageBoxButtons.OK, MessageBoxIcon.Information); } //catch (DbUpdateException ex) // exception khac catch (DbUpdateConcurrencyException ex) // exception khac { XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void view_list_UserJoinStock(DataTable dt) { List <UserJoinStock> list = new List <UserJoinStock>(); for (int i = 0; i < dt.Rows.Count; i++) { UserJoinStock obj = new UserJoinStock(); obj.StockCode = dt.Rows[i]["StockCode"].ToString(); obj.UserName = dt.Rows[i]["UserName"].ToString(); obj.CompanyCode = dt.Rows[i]["CompanyCode"].ToString(); list.Add(obj); } dataGridView1.DataSource = list; }
private void Insert2(List <UserJoinStock> list) { var db = gen.GetNewEntity(); // khai bao new entity Framework //EntityHamaco DataTable dt = tables[cboSheet.SelectedItem.ToString()]; foreach (UserJoinStock item in list) { UserJoinStock obj = new UserJoinStock(); obj.StockCode = item.StockCode; obj.UserName = item.UserName; obj.CompanyCode = item.CompanyCode; // neu insert bi loi thi update (da ton tai roi thi update) try { db.UserJoinStocks.Add(obj); //insert db.SaveChanges(); } catch { db.Entry(obj).State = System.Data.Entity.EntityState.Modified; // update db.SaveChanges(); } } // insert try { db.SaveChanges(); XtraMessageBox.Show("Submit successfully", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information); } //catch (DbUpdateException ex) // exception khac catch (DbUpdateConcurrencyException ex) // exception khac { XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //txtSQL.Text = ex.Message + data + active; } }
private void sbok_Click(object sender, EventArgs e) // add stock (kho) { // insert in to UserJoinStock UserJoinStock data = new UserJoinStock(); // lop UserJoinStock data.UserName = txtuser.Text; data.CompanyCode = Globals.companycode; data.StockCode = txtStockCode.Text; var db = gen.GetNewEntity(); // khai bao new entity Framework try { db.UserJoinStocks.Add(data); //insert db.SaveChanges(); XtraMessageBox.Show("Insert successfully", "tsbtsave_Click", MessageBoxButtons.OK, MessageBoxIcon.Information); load_lai_grid_kho(); } catch (Exception ex) // exception khac { XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void simpleButton1_Click(object sender, EventArgs e) { // delete to UserJoinStock if (XtraMessageBox.Show("Do you want to delete this order?", "Confirmation", MessageBoxButtons.YesNo) != DialogResult.No) { UserJoinStock data = new UserJoinStock();// lop UserJoinStock data.UserName = txtuser.Text; data.CompanyCode = Globals.companycode; data.StockCode = txtStockCode.Text; var db = gen.GetNewEntity(); // khai bao new entity Framework try { db.Entry(data).State = System.Data.Entity.EntityState.Deleted; // delete db.SaveChanges(); XtraMessageBox.Show("Deleted successfully", "tsbtsave_Click", MessageBoxButtons.OK, MessageBoxIcon.Information); load_lai_grid_kho(); } catch (Exception ex) // exception khac { XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }