private void ManageSubCategory(Digital_AppEntities posContext, short categoryID) { SubCategory subCategory; if (subCategoryID == 0) { subCategory = new SubCategory(); subCategory.Code = txtCode.Text; subCategory.Name = txtName.Text; subCategory.Description = txtDescription.Text; subCategory.CategoryID = categoryID; subCategory.Active = chkActive.Checked; // subCategory.CreatedBy = Global.LoggedInUser.ID; subCategory.CreatedDate = DateTime.Now; posContext.SubCategories.Add(subCategory); } else { subCategory = posContext.SubCategories.Single(id => id.ID == subCategoryID); subCategory.Name = txtName.Text; subCategory.Description = txtDescription.Text; subCategory.CategoryID = categoryID; subCategory.Active = chkActive.Checked; // subCategory.ModifiedBy = Global.LoggedInUser.ID; subCategory.ModifiedDate = DateTime.Now; } posContext.SaveChanges(); isRecordSaved = true; ClearControls(); this.LoadSubCategoriesByCategoryID(categoryID); }
private void btnSave_Click(object sender, EventArgs e) { try { var posContext = new Digital_AppEntities(); { Category category; if (categoryID == 0) { if (CheckInput()) { return; } category = new Category(); category.Code = txtCode.Text; category.Name = txtName.Text; category.Description = txtDescription.Text.Trim(); category.Active = chkActive.Checked; // category.CreatedBy = (short)Global.LoggedInUser.ID; category.CreatedDate = DateTime.Now; posContext.Categories.Add(category); } else { category = posContext.Categories.Single(id => id.ID == categoryID); category.Name = txtName.Text; category.Description = txtDescription.Text.Trim(); category.Active = chkActive.Checked; // category.ModifiedBy = Global.LoggedInUser.ID; category.ModifiedDate = DateTime.Now; } posContext.SaveChanges(); // dgvCategory.DataSource = posContext.Categories.OrderByDescending(id => id.ID); } this.ClearControls(); } catch (Exception ex) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void dgPurchaseInformation_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 8) { ItemPurchaseMst aItemPurchaseMst; using (var posContext = new Digital_AppEntities()) { int ids = (int)dgPurchaseInformation.Rows[e.RowIndex].Cells[0].Value; aItemPurchaseMst = posContext.ItemPurchaseMsts.SingleOrDefault(s => s.ID == ids); if (aItemPurchaseMst.Satatus == "" || aItemPurchaseMst.Satatus == null) { aItemPurchaseMst.Satatus = "P"; posContext.SaveChanges(); } else { MessageBox.Show("Already Request Sent", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } PurchaseHistory aPurchaseHistory; aPurchaseHistory = new PurchaseHistory(); aPurchaseHistory.PurchaseID = aItemPurchaseMst.ID; aPurchaseHistory.StatusType = "P"; aPurchaseHistory.AddDate = DateTime.Now; aPurchaseHistory.AddBy = Global.UserLoginID; aPurchaseHistory.StatusDescription = "Purchase Sent Request"; aPurchaseHistory.ChallanNo = aItemPurchaseMst.ChallanNo; aPurchaseHistory.PoDate = aItemPurchaseMst.PODate; aPurchaseHistory.PurchaseCode = aItemPurchaseMst.PO; aPurchaseHistory.Total = aItemPurchaseMst.Total; posContext.PurchaseHistories.Add(aPurchaseHistory); posContext.SaveChanges(); MessageBox.Show("Request Sent Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); Cleardata(); } } }
private void btnDelete_Click(object sender, EventArgs e) { using (var posContext = new Digital_AppEntities()) { FarmerInfo aFarmerInfo; aFarmerInfo = posContext.FarmerInfoes.Single(c => c.ID == supplierID); posContext.FarmerInfoes.Remove(aFarmerInfo); posContext.SaveChanges(); MessageBox.Show("Delete Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } ClearControls(); this.GenerateCode(); txtName.Focus(); btnDelete.Enabled = false; btnSave.Enabled = false; }
private void btnSave_Click(object sender, EventArgs e) { try { using (var posContext = new Digital_AppEntities()) { CompanyInfo company; if (CompanyID == 0) { company = new CompanyInfo(); if (cmbParentName.SelectedValue == null) { company.ParentID = 0; } else { company.ParentID = Convert.ToInt32(cmbParentName.SelectedValue); } company.Name = txtName.Text; company.Mobile = txtMobile.Text; company.Phone = txtPhone.Text; company.Fax = txtFax.Text; company.Email = txtEmail.Text; company.Website = txtWebsite.Text; company.VATRegistration = txtVATNo.Text; MemoryStream stream = new MemoryStream(); if (pbLogo.Image != null) { pbLogo.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); } company.Logo = stream.ToArray(); company.Address1 = txtAddress1.Text; company.Address2 = txtAddress2.Text; company.City = txtCity.Text; company.State = txtState.Text; company.PostalCode = txtPosatalCode.Text; company.Country = cmbCountry.SelectedItem.ToString(); posContext.CompanyInfoes.Add(company); MessageBox.Show(MessageManager.CompanySaved, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { company = posContext.CompanyInfoes.Single(id => id.ID == CompanyID); if (cmbParentName.SelectedValue == null) { company.ParentID = 0; } else { company.ParentID = Convert.ToInt32(cmbParentName.SelectedValue); } company.Name = txtName.Text; company.Mobile = txtMobile.Text; company.Phone = txtPhone.Text; company.Fax = txtFax.Text; company.Email = txtEmail.Text; company.Website = txtWebsite.Text; company.VATRegistration = txtVATNo.Text; MemoryStream stream = new MemoryStream(); if (pbLogo.Image != null) { pbLogo.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); } company.Logo = stream.ToArray(); company.Address1 = txtAddress1.Text; company.Address2 = txtAddress2.Text; company.City = txtCity.Text; company.State = txtState.Text; company.PostalCode = txtPosatalCode.Text; company.Country = cmbCountry.SelectedItem.ToString(); } posContext.SaveChanges(); this.ClearForm(); cmbParentName.DataSource = posContext.CompanyInfoes.OrderBy(id => id.Name); cmbParentName.SelectedIndex = -1; //dgvCompany.DataSource = posContext.CompanyInfoes.OrderByDescending(id => id.ID); int ComId = Convert.ToInt32(Global.LoggedInUser.CompanyId); Global.Company = posContext.CompanyInfoes.SingleOrDefault(c => c.ID == ComId); } //isApplicationClosed = true; //Application.Restart(); } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i <= dgPurchaseInformation.Rows.Count - 1; i++) { ItemPurchaseMst aItemPurchaseMst; using (var posContext = new Digital_AppEntities()) { try { string Cmb = dgPurchaseInformation.Rows[i].Cells["Recommended"].Value.ToString(); DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dgPurchaseInformation.Rows[i].Cells["Recommended"]; string SIndex = comboCell.Items.IndexOf(comboCell.Value).ToString(); int ids = (int)dgPurchaseInformation.Rows[i].Cells[0].Value; aItemPurchaseMst = posContext.ItemPurchaseMsts.SingleOrDefault(s => s.ID == ids); if (SIndex == "0") { aItemPurchaseMst.Satatus = "A"; } else if (SIndex == "1") { aItemPurchaseMst.Satatus = "C"; } else if (SIndex == "2") { aItemPurchaseMst.Satatus = "S"; ProductReceivedMst aProductReceivedMst; { aProductReceivedMst = new ProductReceivedMst(); aProductReceivedMst.ReceivedAmount = 0; aProductReceivedMst.LaberCost = 0; aProductReceivedMst.ShippingCost = 0; aProductReceivedMst.CollectedMstID = aItemPurchaseMst.ID; aProductReceivedMst.CollectedCode = aItemPurchaseMst.PO; aProductReceivedMst.AddBy = Global.UserLoginID; aProductReceivedMst.AddDate = DateTime.Now; aProductReceivedMst.AgentID = aItemPurchaseMst.CreatedBy; posContext.ProductReceivedMsts.Add(aProductReceivedMst); posContext.SaveChanges(); foreach (DataGridViewRow dr in dgvItemPurchaseDetail.Rows) { ProductReceivedDtl aProductCollectedDtl; aProductCollectedDtl = new ProductReceivedDtl(); aProductCollectedDtl.MstID = aProductReceivedMst.ID; aProductCollectedDtl.ProductID = Convert.ToInt32(dr.Cells["colItemID"].Value); aProductCollectedDtl.PurchasePrice = Convert.ToDecimal(dr.Cells["colUnitPrice"].Value); aProductCollectedDtl.Quantity = Convert.ToDecimal(dr.Cells["colQuantity"].Value); aProductCollectedDtl.Total = Convert.ToDecimal(dr.Cells["colTotal"].Value); aProductCollectedDtl.SalePrice = Convert.ToDecimal(dr.Cells["ColSalesPrice"].Value); aProductCollectedDtl.ProductCode = dr.Cells["colItemCode"].Value.ToString(); posContext.ProductReceivedDtls.Add(aProductCollectedDtl); posContext.SaveChanges(); } } } if (SIndex != "3") { PurchaseHistory aPurchaseHistory; aPurchaseHistory = new PurchaseHistory(); aPurchaseHistory.PurchaseID = aItemPurchaseMst.ID; aPurchaseHistory.StatusType = aItemPurchaseMst.Satatus; aPurchaseHistory.AddDate = DateTime.Now; aPurchaseHistory.AddBy = Global.UserLoginID; aPurchaseHistory.StatusDescription = Cmb; posContext.PurchaseHistories.Add(aPurchaseHistory); posContext.SaveChanges(); } } catch { } } } MessageBox.Show("Record are Save Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); Cleardata(); }
private void btnSave_Click(object sender, EventArgs e) { if (dgvItemPurchaseDetail.Rows.Count <= 0) { MessageBox.Show("Please Iput Purchase Item..!!", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ItemPurchaseMst itemPurchaseMst; using (var posContext = new Digital_AppEntities()) { if (itemPurchaseMstID == 0) { itemPurchaseMst = new ItemPurchaseMst(); itemPurchaseMst.GRN = txtGRNO.Text; itemPurchaseMst.ReceivedDate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); itemPurchaseMst.PO = txtPO.Text; itemPurchaseMst.PODate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); itemPurchaseMst.ChallanNo = txtChallanNo.Text; itemPurchaseMst.ChallanDate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); if (cmbSupplier.SelectedValue != null) { itemPurchaseMst.SupplierID = Convert.ToInt16(cmbSupplier.SelectedValue); } itemPurchaseMst.Currency = "BD"; itemPurchaseMst.Total = Convert.ToDecimal(lblTotalData.Text); itemPurchaseMst.Remarks = txtRemarks.Text; itemPurchaseMst.CreatedBy = Global.LoggedInUser.ID; itemPurchaseMst.CreatedDate = DateTime.Now; itemPurchaseMst.discount = Convert.ToDecimal(txtDiscount.Text); itemPurchaseMst.carriage_charge = Convert.ToDecimal(txtCarriageCharg.Text); itemPurchaseMst.labure_charge = Convert.ToDecimal(txtLabureCharge.Text); itemPurchaseMst.SupplierMobileNo = txtMobileNo.Text; posContext.ItemPurchaseMsts.Add(itemPurchaseMst); posContext.SaveChanges(); int id = itemPurchaseMst.ID; itemPurchaseMstID = Convert.ToInt16(itemPurchaseMst.ID); SupplierID = Convert.ToInt16(cmbSupplier.SelectedValue); TotalAmount = Convert.ToDecimal(lblTotalData.Text); Discount = Convert.ToDecimal(txtDiscount.Text); ItemPurchaseDtl itemPurchaseDtl; decimal totqty = 0; foreach (DataGridViewRow row in dgvItemPurchaseDetail.Rows) { itemPurchaseDtl = new ItemPurchaseDtl(); itemPurchaseDtl.ItemPurchaseMstID = id; itemPurchaseDtl.ItemID = Convert.ToInt32(row.Cells["colItemID"].Value); //itemPurchaseDtl.BatchNo = (row.Cells["BatchNo"].Value).ToString(); itemPurchaseDtl.BatchNo = "0"; itemPurchaseDtl.ExpireDate = Convert.ToDateTime(row.Cells["ColExpireDate"].Value); itemPurchaseDtl.UnitPrice = Convert.ToDecimal(row.Cells["colUnitPrice"].Value); itemPurchaseDtl.Quantity = Convert.ToDecimal(row.Cells["colQuantity"].Value); itemPurchaseDtl.ReturnQuantity = Convert.ToDecimal(row.Cells["colQuantity"].Value); itemPurchaseDtl.Total = Convert.ToDecimal(row.Cells["colTotal"].Value); totqty += Convert.ToDecimal(itemPurchaseDtl.Quantity); posContext.ItemPurchaseDtls.Add(itemPurchaseDtl); } posContext.SaveChanges(); try { if (chkSentSMS.Checked) { if (!string.IsNullOrEmpty(txtMobileNo.Text) && txtMobileNo.Text.Length > 10) { string Year = DateTime.Now.Year.ToString(""); string TotalAmount2 = (itemPurchaseMst.Total * 1 + 0).ToString().Replace(" ", "").Replace(",", ""); string Invoice = "Dear Sir/Madam " + cmbSupplier.Text + ", Your Receipt No:" + itemPurchaseMst.PO + " Quantity :" + totqty.ToString() + " Amount :" + TotalAmount2 + " Thank's you for with us. For any query:01996513255"; // string Text = "Dear Sir/Madam,Thanks for shopping with Dorjibari.Invoice:" + invoiceNumber.Replace("INV-" + Year + "-", "") + ", Qty:" + totalSaleQuantity.ToString() + ",Amt:" + TotalAmount + ", Visit our online shop www.dorjibari.com.bd, For any query:01708449690"; int ln = (int)Text.Length; DialogResult values1 = MessageBox.Show("Are you want To Sent SMS!!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); SMSGEtwayCode aSMSGEtwayCode = new SMSGEtwayCode(); if (values1.ToString() == "Yes") { aSMSGEtwayCode.SampleTestHttpApi(txtMobileNo.Text, Invoice, "userName", "Password"); } } } } catch { } MessageBox.Show("Save SuccessFully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); //var categoryid = (from cats in posContext.ItemPurchaseMsts.LastOrDefaul() select cats.id).SingleOrDefault(); } else { itemPurchaseMst = posContext.ItemPurchaseMsts.Single(s => s.ID == itemPurchaseMstID); itemPurchaseMst.GRN = txtGRNO.Text; itemPurchaseMst.ReceivedDate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); itemPurchaseMst.PO = txtPO.Text; itemPurchaseMst.PODate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); itemPurchaseMst.ChallanNo = txtChallanNo.Text; itemPurchaseMst.ChallanDate = Convert.ToDateTime(dtpGRNODate.Value.ToShortDateString() + " " + DateTime.Now.TimeOfDay.ToString()); if (cmbSupplier.SelectedValue != null) { itemPurchaseMst.SupplierID = Convert.ToInt16(cmbSupplier.SelectedValue); } itemPurchaseMst.Currency = "BD"; itemPurchaseMst.Total = Convert.ToDecimal(lblTotalData.Text); itemPurchaseMst.Remarks = txtRemarks.Text; itemPurchaseMst.ModifiedBy = Global.LoggedInUser.ID; itemPurchaseMst.ModifiedDate = DateTime.Now; itemPurchaseMst.discount = Convert.ToDecimal(txtDiscount.Text); itemPurchaseMst.carriage_charge = Convert.ToDecimal(txtCarriageCharg.Text); itemPurchaseMst.labure_charge = Convert.ToDecimal(txtLabureCharge.Text); itemPurchaseMst.SupplierMobileNo = txtMobileNo.Text; posContext.SaveChanges(); int id = itemPurchaseMst.ID; foreach (ItemPurchaseDtl item in posContext.ItemPurchaseMsts.Single(s => s.ID == itemPurchaseMstID).ItemPurchaseDtls.ToList()) { posContext.ItemPurchaseDtls.Remove(item); } posContext.SaveChanges(); ItemPurchaseDtl itemPurchaseDtl; foreach (DataGridViewRow row in dgvItemPurchaseDetail.Rows) { itemPurchaseDtl = new ItemPurchaseDtl(); itemPurchaseDtl.ItemPurchaseMstID = id; itemPurchaseDtl.ItemID = Convert.ToInt32(row.Cells["colItemID"].Value); itemPurchaseDtl.BatchNo = "0"; //(row.Cells["BatchNo"].Value).ToString(); itemPurchaseDtl.ExpireDate = Convert.ToDateTime(row.Cells["ColExpireDate"].Value); itemPurchaseDtl.UnitPrice = Convert.ToDecimal(row.Cells["colUnitPrice"].Value); itemPurchaseDtl.Quantity = Convert.ToDecimal(row.Cells["colQuantity"].Value); itemPurchaseDtl.ReturnQuantity = Convert.ToDecimal(row.Cells["colQuantity"].Value); itemPurchaseDtl.Total = Convert.ToDecimal(row.Cells["colTotal"].Value); posContext.ItemPurchaseDtls.Add(itemPurchaseDtl); } posContext.SaveChanges(); MessageBox.Show("Update Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } // this.ClearForm(); this.btnSave.Enabled = false; } }
private void btnSave_Click(object sender, EventArgs e) { try { var posContext = new Digital_AppEntities(); { UOM auom; if (uomID == 0) { if (CheckInput()) { return; } auom = new UOM(); auom.Name = txtName.Text; auom.Active = chkActive.Checked; auom.CreatedBy = (short)Global.LoggedInUser.ID; auom.CreatedDate = DateTime.Now; posContext.UOMs.Add(auom); posContext.SaveChanges();; } else { auom = posContext.UOMs.SingleOrDefault(c => c.ID == uomID); auom.Name = txtName.Text; auom.Active = chkActive.Checked; //uom.ModifiedBy = Global.LoggedInUser.ID; auom.ModifiedDate = DateTime.Now; } posContext.SaveChanges(); //dgvUOM.DataSource = posContext.UOMs; isRecordSaved = true; this.ClearControls(); } } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnSave_Click(object sender, EventArgs e) { using (var posContext = new Digital_AppEntities()) { ProductReceivedMst aProductReceivedMst; ItemPurchaseMst aItemPurchaseMst; if (dgvItemPurchaseDetail.Rows.Count > 0) { int mstID = Convert.ToInt32(dgvItemPurchaseDetail.Rows[0].Cells["colItemPurchaseMstID"].Value); aProductReceivedMst = posContext.ProductReceivedMsts.SingleOrDefault(a => a.ID == mstID); if (aProductReceivedMst != null) { aItemPurchaseMst = posContext.ItemPurchaseMsts.SingleOrDefault(s => s.PO == txtPoCode.Text); aItemPurchaseMst.Satatus = "R"; aProductReceivedMst.ReceivedAmount = Convert.ToDecimal(lblTotalData.Text); aProductReceivedMst.LaberCost = Convert.ToDecimal(txtLabureCharge.Text); aProductReceivedMst.ShippingCost = Convert.ToDecimal(txtCarriageCharg.Text); aProductReceivedMst.ReguestStatus = "R"; aProductReceivedMst.CollectDate = dtpReceivedDate.Value; aProductReceivedMst.UpdateBy = Global.UserLoginID; aProductReceivedMst.UpdateDate = DateTime.Now; posContext.SaveChanges(); foreach (ProductReceivedDtl aProductReceivedDtl in posContext.ProductReceivedDtls.Where(a => a.MstID == aProductReceivedMst.ID).ToList()) { aProductReceivedDtl.DeleteBy = Global.UserLoginID; aProductReceivedMst.DeleteDate = DateTime.Now; posContext.SaveChanges(); } foreach (DataGridViewRow dr in dgvItemPurchaseDetail.Rows) { ProductReceivedDtl aProductCollectedDtl; int IDdt = Convert.ToInt32(dr.Cells["colID"].Value); aProductCollectedDtl = posContext.ProductReceivedDtls.SingleOrDefault(a => a.ID == IDdt); aProductCollectedDtl.ReceivedQuantity = Convert.ToDecimal(dr.Cells["colQuantity"].Value); aProductCollectedDtl.Total = Convert.ToDecimal(dr.Cells["colTotal"].Value); aProductCollectedDtl.SalePrice = Convert.ToDecimal(dr.Cells["ColSalePrice"].Value); aProductCollectedDtl.DeleteBy = null; aProductCollectedDtl.DeleteDate = null; posContext.SaveChanges(); } PurchaseHistory aPurchaseHistory; aPurchaseHistory = new PurchaseHistory(); aPurchaseHistory.PurchaseID = aItemPurchaseMst.ID; aPurchaseHistory.StatusType = aItemPurchaseMst.Satatus; aPurchaseHistory.AddDate = DateTime.Now; aPurchaseHistory.AddBy = Global.UserLoginID; aPurchaseHistory.StatusDescription = "Pdoduct Received"; posContext.PurchaseHistories.Add(aPurchaseHistory); posContext.SaveChanges(); MessageBox.Show("Update successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } Cleardata(); } else { MessageBox.Show("Please Select Item First", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } }
private void btnSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtMobile.Text)) { MessageBox.Show("Please Input Mobile NO", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(txtMobile.Text)) { MessageBox.Show("Please Input Customer Name", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtMobile.Text.Replace(".", "").Length < 11) { MessageBox.Show("Invalid Mobile No", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var posContext = new Digital_AppEntities()) { Customer customer; if (customerID == 0) { try { customer = posContext.Customers.Single(id => id.Mobile == txtMobile.Text); if (customer != null) { MessageBox.Show("This MobileNo Already Added..", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { } customer = new Customer(); customer.Code = txtCode.Text; // customer.ContactTitle = cmbContactTitle.SelectedItem.ToString(); customer.ContactName = txtContactName.Text; customer.Mobile = txtMobile.Text; customer.Phone = txtPhone.Text; customer.Fax = txtFax.Text; customer.Email = txtEmail.Text; customer.Address1 = txtAddress1.Text; customer.Address2 = txtAddress2.Text; customer.City = txtCity.Text; customer.State = txtState.Text; customer.DateOfBirth = dtpDateofbirth.Value; customer.Maragedate = dtpMarriagedate.Value; customer.PostalCode = txtPostalCode.Text; if (cmbCountry.SelectedValue != null) { customer.Country = cmbCountry.SelectedItem.ToString(); } customer.Active = chkActive.Checked; posContext.Customers.Add(customer); posContext.SaveChanges(); } else { try { customer = posContext.Customers.Single(id => id.Mobile == txtMobile.Text && id.ID != customerID); if (customer != null) { MessageBox.Show("This MobileNo Already Added..", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch { } customer = posContext.Customers.Single(id => id.ID == customerID); // customer.ContactTitle = cmbContactTitle.SelectedItem.ToString(); customer.ContactName = txtContactName.Text; customer.Mobile = txtMobile.Text; customer.Phone = txtPhone.Text; customer.Fax = txtFax.Text; customer.Email = txtEmail.Text; customer.Address1 = txtAddress1.Text; customer.Address2 = txtAddress2.Text; customer.City = txtCity.Text; customer.State = txtState.Text; customer.DateOfBirth = dtpDateofbirth.Value; customer.Maragedate = dtpMarriagedate.Value; customer.PostalCode = txtPostalCode.Text; if (cmbCountry.SelectedValue != null) { customer.Country = cmbCountry.SelectedItem.ToString(); } customer.Active = chkActive.Checked; posContext.SaveChanges(); } this.LoadCustomers(posContext); isRecordSaved = true; this.ClearControls(); this.GenerateCode(posContext); txtContactName.Focus(); } } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnSave_Click(object sender, EventArgs e) { using (var ADbContext = new Digital_AppEntities()) { ItemInfo aItemInfo = ADbContext.ItemInfoes.SingleOrDefault(c => c.ID == itemid); if (aItemInfo == null) { aItemInfo = new ItemInfo(); aItemInfo.Name = txtName.Text; if (cmbCategory.SelectedValue != null) { aItemInfo.CategoryId = (int)cmbCategory.SelectedValue; } if (cmbSubcategory.SelectedValue != null) { aItemInfo.SubcategoryID = (int)cmbSubcategory.SelectedValue; } if (cmbUom.SelectedValue != null) { aItemInfo.UOMID = (int)cmbUom.SelectedValue; } try { var Code = ADbContext.ItemInfoes.OrderByDescending(id => id.ID).Take(1).Single(); if (Code != null) { aItemInfo.StyleNo = Code.ID + 1.ToString().PadLeft(4, '0'); } else { aItemInfo.StyleNo = "1".PadLeft(4, '0'); } } catch { aItemInfo.StyleNo = "1".PadLeft(4, '0'); } aItemInfo.Code = aItemInfo.StyleNo; aItemInfo.Active = chkActive.Checked; aItemInfo.SalePrice = Convert.ToDecimal(txtsalesPrice.Text); ADbContext.ItemInfoes.Add(aItemInfo); ADbContext.SaveChanges(); MessageBox.Show("Save Succesfully", "Success", MessageBoxButtons.OK); this.ClearControls(); } else { aItemInfo.Name = txtName.Text; if (cmbCategory.SelectedValue != null) { aItemInfo.CategoryId = (int)cmbCategory.SelectedValue; } if (cmbSubcategory.SelectedValue != null) { aItemInfo.SubcategoryID = (int)cmbSubcategory.SelectedValue; } if (cmbUom.SelectedValue != null) { aItemInfo.UOMID = (int)cmbUom.SelectedValue; } aItemInfo.Active = chkActive.Checked; ADbContext.SaveChanges(); MessageBox.Show("Update Succesfully", "Success", MessageBoxButtons.OK); this.ClearControls(); } } }
private void btnSave_Click(object sender, EventArgs e) { try { using (var posContext = new Digital_AppEntities()) { FarmerInfo aFarmerInfo; if (supplierID == 0) { int Count = posContext.FarmerInfoes.Count(a => a.MobileNo == txtMobileNo.Text); if (Count > 0) { MessageBox.Show("This MobileNo Already Exist..!!", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } aFarmerInfo = new FarmerInfo(); aFarmerInfo.Code = txtcode.Text; aFarmerInfo.FarmerName = txtName.Text; aFarmerInfo.FatherName = txtfathername.Text; aFarmerInfo.MotherName = txtMotherName.Text; aFarmerInfo.MobileNo = txtMobileNo.Text; aFarmerInfo.Email = txtEmail.Text; aFarmerInfo.Address = txtAddress.Text; aFarmerInfo.PostalCode = txtPostalCode.Text; if (cmbCountry.SelectedValue != null) { aFarmerInfo.CountryID = (int)cmbCountry.SelectedValue; } if (cmbDistrict.SelectedValue != null) { aFarmerInfo.DistricID = (int)cmbDistrict.SelectedValue; } if (cmbThana.SelectedValue != null) { aFarmerInfo.ThanaID = (int)cmbThana.SelectedValue; } aFarmerInfo.Active = chkActive.Checked; posContext.FarmerInfoes.Add(aFarmerInfo); MessageBox.Show("Save Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int Count = posContext.FarmerInfoes.Count(a => a.MobileNo == txtMobileNo.Text && a.ID != supplierID); if (Count > 0) { MessageBox.Show("This MobileNo Already Exist..!!", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } aFarmerInfo = posContext.FarmerInfoes.Single(id => id.ID == supplierID); aFarmerInfo.Code = txtcode.Text; aFarmerInfo.FarmerName = txtName.Text; aFarmerInfo.FatherName = txtfathername.Text; aFarmerInfo.MotherName = txtMotherName.Text; aFarmerInfo.MobileNo = txtMobileNo.Text; aFarmerInfo.Email = txtEmail.Text; aFarmerInfo.Address = txtAddress.Text; aFarmerInfo.PostalCode = txtPostalCode.Text; if (cmbCountry.SelectedValue != null) { aFarmerInfo.CountryID = (int)cmbCountry.SelectedValue; } if (cmbDistrict.SelectedValue != null) { aFarmerInfo.DistricID = (int)cmbDistrict.SelectedValue; } if (cmbThana.SelectedValue != null) { aFarmerInfo.ThanaID = (int)cmbThana.SelectedValue; } MessageBox.Show("Update Successfully", Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Information); } aFarmerInfo.Active = chkActive.Checked; posContext.SaveChanges(); //this.LoadSuppliers(posContext); isRecordSaved = true; this.ClearControls(); this.GenerateCode(); txtName.Focus(); } } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnSave_Click(object sender, EventArgs e) { try { var posContext = new Digital_AppEntities(); { UserGroup userGroup; if (userGroupID == 0) { userGroup = new UserGroup(); userGroup.Name = txtName.Text; userGroup.Description = txtDescription.Text.Trim(); userGroup.Active = chkActive.Checked; userGroup.CreatedBy = (short)Global.LoggedInUser.ID; posContext.UserGroups.Add(userGroup); } else { userGroup = posContext.UserGroups.Single(id => id.ID == userGroupID); userGroup.Name = txtName.Text; userGroup.Description = txtDescription.Text.Trim(); userGroup.Active = chkActive.Checked; userGroup.ModifiedBy = (short)Global.LoggedInUser.ID; userGroup.ModifiedDate = DateTime.Now; } posContext.SaveChanges(); isRecordSaved = true; this.ClearControls(); } } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (ex.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnSave_Click(object sender, EventArgs e) { try { using (var posContext = new Digital_AppEntities()) { User user; PasswordManager passwordManager = new PasswordManager(); if (userID == 0) { user = new User(); user.FullName = txtFullName.Text; user.UserName = txtUserName.Text; user.UserPassword = passwordManager.Encrypt(txtPassword.Text); user.Mobile = txtMobile.Text; user.NationalID = txtNationalID.Text; user.Mobile = txtMobile.Text; user.Phone = txtPhone.Text; user.Fax = txtFax.Text; user.Email = txtEmail.Text; user.Address1 = txtAddress1.Text; user.Address2 = txtAddress2.Text; user.City = txtCity.Text; user.State = txtState.Text; user.PostalCode = txtPosatalCode.Text; // user.Country = cmbCountry.SelectedItem.ToString(); user.UserGroupID = Convert.ToInt16(cmbUserGroup.SelectedValue); user.Active = chkActive.Checked; user.CreatedBy = Global.LoggedInUser.ID; user.CreatedDate = DateTime.Now; user.CompanyId = 1; posContext.Users.Add(user); } else { user = posContext.Users.Single(id => id.ID == userID); user.FullName = txtFullName.Text; user.UserName = txtUserName.Text; user.UserPassword = passwordManager.Encrypt(txtPassword.Text); user.Mobile = txtMobile.Text; user.NationalID = txtNationalID.Text; user.Mobile = txtMobile.Text; user.Phone = txtPhone.Text; user.Fax = txtFax.Text; user.Email = txtEmail.Text; user.Address1 = txtAddress1.Text; user.Address2 = txtAddress2.Text; user.City = txtCity.Text; user.State = txtState.Text; user.PostalCode = txtPosatalCode.Text; // user.Country = cmbCountry.SelectedItem.ToString(); user.UserGroupID = Convert.ToInt16(cmbUserGroup.SelectedValue); user.Active = chkActive.Checked; user.ModifiedBy = Global.LoggedInUser.ID; user.ModifiedDate = DateTime.Now; user.CompanyId = 1; } posContext.SaveChanges(); dgvUserInformation.Rows.Clear(); foreach (var a in posContext.Users.OrderByDescending(id => id.ID)) { dgvUserInformation.Rows.Add(a.ID, a.FullName, a.UserName, a.UserPassword, a.Mobile, a.Phone, a.Fax, a.Email, a.UserGroupID, "", a.NationalID, a.Address1, a.Address2, a.City, a.State, a.PostalCode, a.Active); } isRecordSaved = true; ClearControls(); } } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex.InnerException)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(ex.InnerException.Message, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (ex.GetType().Name == "SqlException") { int errorNumber = ((System.Data.SqlClient.SqlException)(ex)).Number; switch (errorNumber) { case 2601: MessageBox.Show(MessageManager.GetDuplicateErrorMsg(this.Text.ToLower()), Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show(MessageManager.CommonExceptionMsg, Global.ApplicationNameWithVersion, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }