private void AddItemsToStock() { using (var context = new MegaEntities()) { foreach (var p in addedList) { var itemInStock = context.Stocks.Find(p.ItemCode); if (itemInStock == null) { itemInStock = new Stock() { ItemCode = p.ItemCode, Quantity = p.AddedQuantity }; context.Stocks.Add(itemInStock); } else { itemInStock.Quantity += p.AddedQuantity; } context.SaveChanges(); } var purchasing = context.Purchases.Find(purchaseId); purchasing.IsLock = true; context.SaveChanges(); } }
private void UpdateItem() { using (var context = new MegaEntities()) { var item = context.Items.Find(itemCode); item.Description = txtDescription.Text; item.EnglishName = txtEnglishName.Text; item.CategoryId = Convert.ToInt32(cboCategory.SelectedValue); item.CurrentPrice = newPrice; context.SaveChanges(); } }
private void btnSave_Click(object sender, EventArgs e) { var purchase = new Purchase() { PurchaseDate = dtpPurchaseDate.Value, PurchaserCode = cboPurchaser.SelectedValue.ToString(), SupplierId = Convert.ToInt32(cboSupplier.SelectedValue), InvoiceNo = txtInvoiceNo.Text, PRNO = txtPRNO.Text, BuyFrom = cboBuyFrom.SelectedItem.ToString(), IsLock = false, ComputerCode = MegaService.GetComputerCode(), ComputeTime = MegaService.GetComputeTime() }; using (var context = new MegaEntities()) { purchase = context.Purchases.Add(purchase); context.SaveChanges(); purchaseId = purchase.Id; } for (int i = 0; i < dgvList.Rows.Count; i++) { decimal up = Convert.ToDecimal(dgvList.Rows[i].Cells[3].Value); int qty = Convert.ToInt32(dgvList.Rows[i].Cells[4].Value); string itemCode = dgvList.Rows[i].Cells[1].Value.ToString(); var purchaseDetail = new PurchaseDetail() { MasterCode = purchase.Id, ItemCode = itemCode, UnitPrice = up, Quantity = qty, AddedQuantity = 0, RemainQuantity = qty, Amount = up * qty }; using (var context = new MegaEntities()) { context.PurchaseDetails.Add(purchaseDetail); context.SaveChanges(); } } this.btnSave.Enabled = false; this.btnAddItemToStock.Enabled = true; }
private void btnAdd_Click(object sender, EventArgs e) { var position = new Position() { Description = txtPositionName.Text, Remark = txtRemark.Text, IsActive = true }; using (var context = new MegaEntities()) { position = context.Positions.Add(position); context.SaveChanges(); } dgvList.Rows.Add((dgvList.Rows.Count + 1), position.Id, position.Description); }
private void AddNewItem() { var item = new Item() { Code = txtCode.Text, EnglishName = txtEnglishName.Text, Description = txtDescription.Text, CategoryId = Convert.ToInt32(cboCategory.SelectedValue), CurrentPrice = newPrice, IsActive = true }; using (var context = new MegaEntities()) { context.Items.Add(item); context.SaveChanges(); } }
private void btnAdd_Click(object sender, EventArgs e) { var project = new Project() { Description = txtProjectName.Text, Location = txtLocation.Text, Remark = txtRemark.Text, IsActive = true }; using (var context = new MegaEntities()) { project = context.Projects.Add(project); context.SaveChanges(); } this.Clear(); this.dgvList.Rows.Add((dgvList.Rows.Count + 1), project.Id, project.Description, project.Location); }
private void btnAdd_Click(object sender, EventArgs e) { var supplier = new Supplier() { Description = txtSupplierName.Text, Phone = txtPhone.Text, Remark = txtRemark.Text, IsActive = true }; using (var context = new MegaEntities()) { supplier = context.Suppliers.Add(supplier); context.SaveChanges(); } this.Clear(); this.dgvList.Rows.Add((dgvList.Rows.Count + 1), supplier.Id, supplier.Description, supplier.Phone); }
private void btnDelete_Click(object sender, EventArgs e) { if (empId != null) { try { var emp = mega.Employees.Where(x => x.Code == empId).FirstOrDefault(); emp.IsActive = false; mega.Entry(emp).State = System.Data.Entity.EntityState.Modified; mega.SaveChanges(); lblDelete.Show(); loadEmployee(); empId = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvList.SelectedRows.Count > 0) { var itemCode = dgvList.CurrentRow.Cells[1].Value.ToString(); DialogResult action = MessageBox.Show("Delete item \"" + itemCode + "\" ?", "Items", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (action == DialogResult.Yes) { using (var context = new MegaEntities()) { var item = context.Items.Find(itemCode); item.IsActive = false; context.SaveChanges(); } this.LoadData(); } } }
private void btnSave_Click(object sender, EventArgs e) { using (var context = new MegaEntities()) { foreach (var pd in addedList) { var p = context.PurchaseDetails.Find(pd.MasterCode, pd.ItemCode); p.AddedQuantity = pd.AddedQuantity; p.RemainQuantity = pd.RemainQuantity; } context.SaveChanges(); } AddItemsToStock(); lblSaved.Visible = true; btnSave.Enabled = false; lblQty.Visible = txtQty.Visible = false; btnSingleBackward.Visible = btnSingleForward.Visible = false; btnMultiBackward.Visible = btnMultiForward.Visible = false; }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvList.SelectedRows.Count > 0) { DialogResult action = MessageBox.Show("Delete selected row?", "Supplier", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (action != DialogResult.Yes) { return; } int id = Convert.ToInt32(dgvList.CurrentRow.Cells[1].Value); using (var context = new MegaEntities()) { var supplier = context.Suppliers.Find(id); supplier.IsActive = false; context.SaveChanges(); } this.dgvList.Rows.RemoveAt(dgvList.CurrentRow.Index); } }
private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e) { int colInd = dgvList.CurrentCell.ColumnIndex; if (dgvList.Columns[colInd].HeaderText == "Delete") { DialogResult action = MessageBox.Show("Delete selected row?", "Position", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (action == DialogResult.Yes) { var positionCode = Convert.ToInt32(dgvList.CurrentRow.Cells[1].Value); using (var context = new MegaEntities()) { var position = context.Positions.Find(positionCode); position.IsActive = false; context.SaveChanges(); } dgvList.Rows.RemoveAt(dgvList.CurrentRow.Index); } } }
private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e) { int colInd = dgvList.CurrentCell.ColumnIndex; if (dgvList.Columns[colInd].HeaderText == "Delete") { DialogResult action = MessageBox.Show("Delete selected row?", "Category", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (action == DialogResult.Yes) { int id = int.Parse(dgvList.CurrentRow.Cells[1].Value.ToString()); using (var context = new MegaEntities()) { var category = context.Categories.Find(id); category.IsActive = false; context.SaveChanges(); } this.dgvList.Rows.RemoveAt(dgvList.CurrentRow.Index); } } }
private void btnAdd_Click(object sender, EventArgs e) { var category = new Category() { Description = txtCategoryName.Text, Remark = txtRemark.Text, IsActive = true }; using (var context = new MegaEntities()) { category = context.Categories.Add(category); context.SaveChanges(); } dgvList.Rows.Add(dgvList.Rows.Count + 1, category.Id, category.Description); txtCategoryName.Clear(); txtRemark.Clear(); txtCategoryName.Focus(); }
private void btnSave_Click(object sender, EventArgs e) { if (Edit_Flage) { return; } int qty_from_stock; //get quantity from table stock int qty_from_dgvlist; //get quantity from datagridview string itm; //get item code from datagridview #region condition if if (string.IsNullOrEmpty(txtRefer1.Text.Trim())) { errorMS.SetError(txtRefer1, "Please input reference 1"); txtRefer1.Focus(); return; } else { errorMS.Clear(); } if (cboApplicant.SelectedIndex < 0) { errorMS.SetError(cboApplicant, "Please select applicant"); cboApplicant.Focus(); return; } else { errorMS.Clear(); } if (cboApprover.SelectedIndex < 0) { errorMS.SetError(cboApprover, "Please select approver"); cboApprover.Focus(); return; } else { errorMS.Clear(); } #endregion if (dgvList.Rows.Count > 0) { #region insert into table ReturnToWH var ReturnToWh = new ReturnToWH() { ReturnDate = dtpIssuedDate.Value, Reference = txtRefer1.Text, ApplicantCode = cboApplicant.SelectedValue.ToString(), ApproverCode = cboApprover.SelectedValue.ToString(), ProjectId = int.Parse(cboProject.SelectedValue.ToString()), Remark = txtPurpose.Text, ComputerCode = Services.MegaService.GetComputerCode(), ComputeTime = Services.MegaService.GetComputeTime() }; mega.ReturnToWHs.Add(ReturnToWh); #endregion #region isert into table ReturnToWHDetail and update stock for (int i = 0; i < dgvList.Rows.Count; i++) { var ReturnToWHView = new ReturnToWHDetail() { MasterCode = ReturnToWh.Id, ItemCode = dgvList.Rows[i].Cells[1].Value.ToString(), Quantity = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()), UnitPrice = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()), Amount = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()) * int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()) }; mega.ReturnToWHDetails.Add(ReturnToWHView); itm = dgvList.Rows[i].Cells[1].Value.ToString(); qty_from_dgvlist = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()); var stock = mega.Stocks.Where(x => x.ItemCode == itm).FirstOrDefault(); qty_from_stock = stock.Quantity; stock.Quantity = (qty_from_stock + qty_from_dgvlist); mega.Entry(stock).State = EntityState.Modified; } #endregion mega.SaveChanges(); dgvList.Rows.Clear(); txtGrandTotal.Text = txtRefer1.Text = txtPurpose.Text = ""; cboItem.SelectedIndex = cboApplicant.SelectedIndex = cboApprover.SelectedIndex = cboProject.SelectedIndex = -1; lblSaved.Show(); } }
private void btnSave_Click(object sender, EventArgs e) { if (Edit_Flage) { return; } if (string.IsNullOrEmpty(txtReference.Text.Trim())) { errorMS.SetError(txtReference, "Please input reference"); txtReference.Focus(); return; } else { errorMS.Clear(); } if (string.IsNullOrEmpty(txtItemCode.Text.Trim())) { errorMS.SetError(txtItemCode, "Please inpute item code"); txtItemCode.Focus(); return; } else { errorMS.Clear(); } if (string.IsNullOrEmpty(txtQuantity.Text.Trim())) { errorMS.SetError(txtQuantity, "Please inpute quantity"); txtQuantity.Focus(); return; } else { errorMS.Clear(); } try { decimal amount = int.Parse(txtQuantity.Text) * decimal.Parse(txtUnitPrice.Text); var adjin = new AdjustIn() { AdjustInDate = dtpAddustDate.Value, Reference = txtReference.Text, ItemCode = cboDescription.SelectedValue.ToString(), UnitPrice = decimal.Parse(txtUnitPrice.Text), Quantity = int.Parse(txtQuantity.Text), Amount = amount, ProjectId = int.Parse(cboProject.SelectedValue.ToString()), Remark = txtRemark.Text, ComputerCode = Services.MegaService.GetComputerCode(), ComputeTime = Services.MegaService.GetComputeTime() }; using (var mega = new MegaEntities()) { mega.AdjustIns.Add(adjin); mega.SaveChanges(); lblSaved.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { if (Edit_Flage) { return; } if (string.IsNullOrEmpty(txtEmployeeCode.Text.Trim())) { errorMS.SetError(txtEmployeeCode, "Please input employee code"); txtEmployeeCode.Focus(); return; } else { errorMS.Clear(); } if (string.IsNullOrEmpty(txtNameKh.Text.Trim())) { errorMS.SetError(txtNameKh, "Please input khmer name"); txtNameKh.Focus(); return; } else { errorMS.Clear(); } if (string.IsNullOrEmpty(txtNameEnglish.Text.Trim())) { errorMS.SetError(txtNameEnglish, "Please input english name"); txtNameEnglish.Focus(); return; } else { errorMS.Clear(); } try { var employee = new Employee() { Code = txtEmployeeCode.Text, EmployeeNameKh = txtNameKh.Text, EmployeeNameEn = txtNameEnglish.Text, GenderId = int.Parse(cboGender.SelectedValue.ToString()), DateOfBirth = dtpBirthDate.Value, PlaceOfBirth = txtBirthPlace.Text, CurrentAddress = txtCurrentAddress.Text, NationalId = txtNatioalId.Text, PositionId = int.Parse(cboPosition.SelectedValue.ToString()), Phone = txtPhone.Text, Email = txtEmail.Text, Photo = imageToByte(pcbPhoto.Image), StartWorkDate = dtpStartWork.Value, IsActive = true }; mega.Employees.Add(employee); mega.SaveChanges(); lblSaved.Show(); btnSave.Enabled = false; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { if (Edit_Flage) { return; } int qty_from_stock; //get quantity from table stock int qty_from_dgvlist; //get quantity from datagridview string itm; //get item code from datagridview #region condition_if if (string.IsNullOrEmpty(txtRefer1.Text.Trim())) { errorMS.SetError(txtRefer1, "Please input reference 1"); txtRefer1.Focus(); return; } else { errorMS.Clear(); } if (string.IsNullOrEmpty(txtRefer2.Text.Trim())) { errorMS.SetError(txtRefer2, "Please input reference 2"); txtRefer2.Focus(); return; } else { errorMS.Clear(); } if (cboApplicant.SelectedIndex < 0) { errorMS.SetError(cboApplicant, "Please select applicant"); cboApplicant.Focus(); SendKeys.Send("{DOWN}"); return; } else { errorMS.Clear(); } #endregion if (dgvList.Rows.Count > 0) { try { #region insert_into_issued var issued = new Issued() { IssuedDate = dtpIssuedDate.Value, Reference1 = txtRefer1.Text, Reference2 = txtRefer2.Text, ApplicantCode = cboApplicant.SelectedValue.ToString(), ProjectId = int.Parse(cboProject.SelectedValue.ToString()), Purpose = txtPurpose.Text, Car = txtCar.Text, ComputerCode = Services.MegaService.GetComputerCode(), ComputeTime = Services.MegaService.GetComputeTime() }; mega.Issueds.Add(issued); #endregion for (int i = 0; i < dgvList.Rows.Count; i++) { #region insert_into_issuedDetail_and_update_stock var issuedDetail = new IssuedDetail() { MasterCode = issued.Id, ItemCode = dgvList.Rows[i].Cells[1].Value.ToString(), UnitPrice = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()), Quantity = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()), Amount = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()) * int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()) }; mega.IssuedDetails.Add(issuedDetail); itm = dgvList.Rows[i].Cells[1].Value.ToString(); qty_from_dgvlist = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()); var stock = mega.Stocks.Where(x => x.ItemCode == itm).FirstOrDefault(); qty_from_stock = stock.Quantity; stock.Quantity = (qty_from_stock - qty_from_dgvlist); mega.Entry(stock).State = EntityState.Modified; #endregion } mega.SaveChanges(); lblSaved.Show(); txtRefer1.Text = txtRefer2.Text = txtCar.Text = txtPurpose.Text = txtGrandTotal.Text = ""; cboApplicant.SelectedIndex = cboProject.SelectedIndex = -1; dgvList.Rows.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }