private void btnAdd_Click(object sender, EventArgs e) { if (_mode == 0) { //validate if (validate()) { tblCompany company = new tblCompany(); company.CompanyCode = txtCompanyCode.Text.Trim(); company.CompanyName = txtCompanyName.Text.Trim(); company.Description = txtDescription.Text.Trim(); company.CreatedBy = _userInfo.UserID; company.ModifiedBy = _userInfo.UserID; if (CompanyFactory.Insert(company) > 0) { try { _frmListCompany.init(); } catch (Exception ex) { //do nothing } MessageBox.Show("Thêm mới doanh nghiệp thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reset(); } else { MessageBox.Show("Thêm mới doanh nghiệp không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void FrmReportImportToReExport_Load(object sender, EventArgs e) { this.Text = "Bao cao xuat/nhap chuyen cua khau" + ConstantInfo.MESSAGE_TITLE + GlobalInfo.CompanyName; //init cbCustoms List<tblCustom> listCustom = CustomsFacory.getAll(); foreach (tblCustom cb in listCustom) { cb.CustomsName = cb.CustomsCode + " - " + cb.CustomsName; } listCustom = listCustom.OrderBy(g => g.CustomsCode).ToList(); tblCustom allObj = new tblCustom(); allObj.CustomsCode = "0"; allObj.CustomsName = "Tất cả"; listCustom.Insert(0, allObj); cbCustoms.DataSource = listCustom; cbCustoms.ValueMember = "CustomsCode"; cbCustoms.DisplayMember = "CustomsName"; //init cbCompany List<tblCompany> listCompany = CompanyFactory.getAllCompany(); foreach (tblCompany cp in listCompany) { cp.CompanyName = cp.CompanyCode + " - " + cp.CompanyName; } listCompany = listCompany.OrderBy(g => g.CompanyCode).ToList(); tblCompany allCompanyObj = new tblCompany(); allCompanyObj.CompanyCode = "0"; allCompanyObj.CompanyName = "Tất cả"; listCompany.Insert(0, allCompanyObj); cbCompany.DataSource = listCompany; cbCompany.ValueMember = "CompanyCode"; cbCompany.DisplayMember = "CompanyName"; }
public static int Insert(tblCompany company) { dbEcustomEntities _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true)); _db.Connection.Open(); company.CreatedDate = CommonFactory.GetCurrentDate(); company.ModifiedDate = CommonFactory.GetCurrentDate(); _db.AddTotblCompanies(company); try { if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open(); return _db.SaveChanges(); } catch (Exception ex) { return -1; } finally { _db.Connection.Close(); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (_mode == 1) { if (validate()) { tblCompany company = new tblCompany(); company.CompanyCode = txtCompanyCode.Text; company.CompanyName = txtCompanyName.Text.Trim(); company.Description = txtDescription.Text.Trim(); company.ModifiedBy = _userInfo.UserID; if (CompanyFactory.Update(company) > 0) { try { _frmListCompany.search(); } catch (Exception ex) { //do nothing } MessageBox.Show("Cập doanh nghiệp hình thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Cập nhật doanh nghiệp không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public static int Update(tblCompany companyObj) { dbEcustomEntities _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true)); _db.Connection.Open(); tblCompany originCompany = _db.tblCompanies.Where(g => g.CompanyCode == companyObj.CompanyCode).FirstOrDefault(); if (originCompany == null) { return -1; } originCompany.CompanyName = companyObj.CompanyName; originCompany.Description = companyObj.Description; originCompany.ModifiedBy = companyObj.ModifiedBy; originCompany.ModifiedDate = CommonFactory.GetCurrentDate(); try { return _db.SaveChanges(); } catch (Exception ex) { return -1; } finally { _db.Connection.Close(); } }