//bill calculate with 7 Layer detail with Box Type(Flat or Block Type) private decimal getMeterFeesAmountwith7LayerCode(MBMS.DAL.MeterUnitCollect meterUnitCollect) { decimal result = 0; decimal sumUnits = 0; BillCode7Layer billCode7Layer = meterbillcalculateservice.GetBillCode7LayerByBillCode(Convert.ToInt64(meterUnitCollect.Customer.BillCode7Layer.BillCode7LayerNo)); List <BillCode7LayerDetail> billCode7LayerDetailList = meterbillcalculateservice.GetBillCode7LayerDetailByBillCode7LayerID(billCode7Layer.BillCode7LayerID).OrderBy(y => y.LowerLimit).ToList(); foreach (BillCode7LayerDetail item in billCode7LayerDetailList) { if (billCode7Layer.BillCodeLayerType.Equals("Block Type")) { //before calculate the value,multiply totol meter unit with multiplier value if ((meterUnitCollect.TotalMeterUnit * meterMultiplier) > (sumUnits + item.RateUnit)) { result += (decimal)(item.RateUnit * item.AmountPerUnit); sumUnits += (decimal)item.RateUnit; } else { decimal diffUnits = meterUnitCollect.TotalMeterUnit - sumUnits; result += (decimal)diffUnits * item.AmountPerUnit; if ((diffUnits + sumUnits) == meterUnitCollect.TotalMeterUnit) { return(result); } } //end of else } //end of Block Type condition else { result = meterUnitCollect.TotalMeterUnit * item.AmountPerUnit; } } //end of foreach loop return(result); } //end of method
private void dgvBillCode7LayerList_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (e.ColumnIndex == 6) { //DeleteForBillCode7Layer if (!CheckingRoleManagementFeature("BillCodeLayerEditOrDelete")) { MessageBox.Show("Access Deined for this function.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult result = MessageBox.Show(this, "Are you sure you want to delete?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result.Equals(DialogResult.OK)) { DataGridViewRow row = dgvBillCode7LayerList.Rows[e.RowIndex]; billCode7LayerID = Convert.ToString(row.Cells[0].Value); BillCode7Layer billCodeObj = (BillCode7Layer)row.DataBoundItem; billCodeObj = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerID == billCodeObj.BillCode7LayerID select b).FirstOrDefault(); var customerCount = (from c in billCodeObj.Customers where c.Active == true select c).Count(); if (customerCount > 0) { MessageBox.Show("This Bill Code is used in Customer !", "Cannot Delete", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } dgvBillCode7LayerList.DataSource = ""; BillCode7Layer billCode7Layer = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerID == billCode7LayerID select b).FirstOrDefault(); billCode7Layer.Active = false; billCode7Layer.DeletedUserID = UserID; billCode7Layer.DeletedDate = DateTime.Now; billCode7LayerController.DeleteBillCode7Layer(billCode7Layer); dgvBillCode7LayerList.DataSource = (from b in mbsEntities.BillCode7Layer where b.Active == true orderby b.BillCode7LayerNo descending select b).ToList(); MessageBox.Show(this, "Successfully Deleted!", "Delete Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); FormRefresh(); } } else if (e.ColumnIndex == 5) { //EditBillCode7Layer if (!CheckingRoleManagementFeature("BillCodeLayerEditOrDelete")) { MessageBox.Show("Access Deined for this function.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string _billCode7LayerID; BillCode7Layerfrm billcode7LayerForm = new BillCode7Layerfrm(); billcode7LayerForm.isEdit = true; billcode7LayerForm.Text = "Edit BillCode"; _billCode7LayerID = Convert.ToString(dgvBillCode7LayerList.Rows[e.RowIndex].Cells[0].Value); billcode7LayerForm.billCode7LayerID = _billCode7LayerID; billcode7LayerForm.billCode7LayerDetailList = mbsEntities.BillCode7LayerDetail.Where(x => x.BillCode7LayerID == _billCode7LayerID && x.BillCode7Layer.Active == true && x.Active == true).OrderBy(y => y.LowerLimit).ToList(); billcode7LayerForm.UserID = UserID; billcode7LayerForm.ShowDialog(); this.Close(); } } }
public void DeleteBillCode7Layer(BillCode7Layer bc) { BillCode7Layer billCode7Layer = mBMSEntities.BillCode7Layer.Where(x => x.BillCode7LayerID == bc.BillCode7LayerID).SingleOrDefault(); billCode7Layer.Active = bc.Active; billCode7Layer.DeletedDate = DateTime.Now; billCode7Layer.DeletedUserID = bc.DeletedUserID; mBMSEntities.SaveChanges(); }
public void UpdateBillCode7Layer(BillCode7Layer bc) { BillCode7Layer billCode7Layer = mBMSEntities.BillCode7Layer.Where(x => x.BillCode7LayerID == bc.BillCode7LayerID).SingleOrDefault(); billCode7Layer.BillCode7LayerNo = bc.BillCode7LayerNo; billCode7Layer.BillCodeLayerType = bc.BillCodeLayerType; billCode7Layer.UpdatedUserID = bc.UpdatedUserID; billCode7Layer.UpdatedDate = DateTime.Now; mBMSEntities.BillCode7Layer.AddOrUpdate(billCode7Layer); //requires using System.Data.Entity.Migrations; mBMSEntities.SaveChanges(); }
public void bindBillCode() { List <BillCode7Layer> billode7LayerList = new List <BillCode7Layer>(); BillCode7Layer billCode = new BillCode7Layer(); billCode.BillCode7LayerID = Convert.ToString(0); billCode.BillCode7LayerNo = 0; billode7LayerList.Add(billCode); billode7LayerList.AddRange(mbmsEntities.BillCode7Layer.Where(x => x.Active == true).OrderBy(x => x.BillCode7LayerNo).ToList()); cboBillCodeNo.DataSource = billode7LayerList; cboBillCodeNo.DisplayMember = "BillCode7LayerNo"; cboBillCodeNo.ValueMember = "BillCode7LayerID"; }
private void dgvBillCode7LayerList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { foreach (DataGridViewRow row in dgvBillCode7LayerList.Rows) { BillCode7Layer billCode7Layer = (BillCode7Layer)row.DataBoundItem; row.Cells[0].Value = billCode7Layer.BillCode7LayerID; row.Cells[1].Value = billCode7Layer.BillCode7LayerNo; row.Cells[2].Value = billCode7Layer.BillCodeLayerType; row.Cells[3].Value = billCode7Layer.CreatedDate; row.Cells[4].Value = mbsEntities.Users.Where(x => x.UserID == billCode7Layer.CreatedUserID).SingleOrDefault().UserName; //row.Cells[5].Value = billCode7Layer.AmountPerUnit; } }
private void BillCode7Layerfrm_Load(object sender, EventArgs e) { gv7layer.AutoGenerateColumns = false; cboBillCodeType.Items.Add("Flat Type"); cboBillCodeType.Items.Add("Block Type"); cboBillCodeType.SelectedIndex = 0; if (isEdit) { BillCode7Layer billCode7Layer = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerID == billCode7LayerID select b).FirstOrDefault(); txtBillCodeNo.Text = Convert.ToString(billCode7Layer.BillCode7LayerNo); cboBillCodeType.Text = billCode7Layer.BillCodeLayerType; //adding data to the list foreach (var item in billCode7LayerDetailList) { string[] row = new string[] { item.LowerLimit.ToString(), item.UpperLimit.ToString(), item.RateUnit.ToString(), item.AmountPerUnit.ToString() }; gv7layer.Rows.Add(row); } } }
private void btnSave_Click(object sender, EventArgs e) { if (dt.Rows.Count > 0) { DialogResult ok = MessageBox.Show("are you sure to save data?", "information", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ok == DialogResult.Yes) { List <Customer> customerList = new List <Customer>(); foreach (DataRow row in dt.Rows) { bool isdataexit = iCustomerServices.GetCustomerCustomerCode(row["CustomerCode"].ToString()); if (isdataexit) { MessageBox.Show("Customer data already exists in the system for>" + row["CustomerCode"].ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bool IsSMDSerialNoExist = iCustomerServices.GetCustomerBySMDNo(row["SMDNo"].ToString()); if (IsSMDSerialNoExist) { MessageBox.Show("Customer SMD Serial No already exists in the system for>" + row["CustomerCode"].ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Customer customerEntity = new Customer(); customerEntity.CustomerCode = row["CustomerCode"].ToString(); customerEntity.CustomerID = Guid.NewGuid().ToString(); customerEntity.SMDNo = row["SMDNo"].ToString(); customerEntity.CustomerNameInEng = row["CustomerNameInEng"].ToString(); customerEntity.CustomerNameInMM = row["CustomerNameInMM"].ToString(); customerEntity.NRC = row["NRC"].ToString(); customerEntity.PhoneNo = row["PhoneNo"].ToString(); customerEntity.Post = row["PostalCode"].ToString(); Township t = iCustomerServices.GetTownshipByTownshipCode(row["TownshipCode"].ToString()); if (t == null) { MessageBox.Show("Please define Township Code for>" + customerEntity.CustomerCode, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerEntity.TownshipID = t.TownshipID; customerEntity.Township = t; Quarter q = iCustomerServices.GetQuarterByQarterCode(row["QuarterCode"].ToString()); if (q == null) { MessageBox.Show("Please define Quarter Code for>" + customerEntity.CustomerCode, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerEntity.QuarterID = q.QuarterID; customerEntity.Quarter = q; customerEntity.CustomerAddressInEng = row["Address(English)"].ToString(); customerEntity.CustomerAddressInMM = row["Address(Myanmar)"].ToString(); Meter m = iCustomerServices.GetMeterByQarterNo(row["MeterNo"].ToString()); if (m == null) { MessageBox.Show("Please define MeterNo data for>" + customerEntity.CustomerCode, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bool IsMeterIDExitsin = iCustomerServices.GetCustomerByMeterID(m.MeterBoxID); if (IsMeterIDExitsin) { MessageBox.Show("Customer Meter No already exists in the system for>" + row["CustomerCode"].ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerEntity.MeterID = m.MeterBoxID; customerEntity.Meter = m; Ledger l = iCustomerServices.GetLedgerByLedgerCode(Convert.ToInt32(row["LedgerCode"].ToString())); if (l == null) { MessageBox.Show("Please define Ledger Code data for>" + customerEntity.CustomerCode, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerEntity.Ledger = l; customerEntity.LedgerID = l.LedgerID; customerEntity.PageNo = Convert.ToInt16(row["PageNo"].ToString()); customerEntity.LineNo = Convert.ToInt16(row["LineNo"].ToString()); BillCode7Layer b = iCustomerServices.GetBillCode7LayerByBillCodeNo(Convert.ToInt32(row["BillCodeNo"].ToString())); if (b == null) { MessageBox.Show("Please define Bill Code No data for>" + customerEntity.CustomerCode, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerEntity.BillCode7LayerID = b.BillCode7LayerID; customerEntity.BillCode7Layer = b; customerEntity.Active = true; customerEntity.CreatedDate = DateTime.Now; customerEntity.CreatedUserID = UserID; customerList.Add(customerEntity); } if (customerList.Count > 0) { try { iCustomerServices.SaveRange(customerList); MessageBox.Show("Importing Customer data is successfylly saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Error occur :(", "information", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //end of yes dialog } //end of dt.Rows.Count>0 }
private void btnSave_Click(object sender, EventArgs e) { if (checkValidation()) { if (isEdit) { int editBillCodeNoCount = 0; long editbillCodeNo = Convert.ToInt64(txtBillCodeNo.Text); BillCode7Layer updateBillCode7Layer = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerID == billCode7LayerID select b).FirstOrDefault(); if (txtBillCodeNo.Text != Convert.ToString(updateBillCode7Layer.BillCode7LayerNo)) { editBillCodeNoCount = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerNo == editbillCodeNo && b.Active == true select b).ToList().Count; } if (editBillCodeNoCount > 0) { tooltip.SetToolTip(txtBillCodeNo, "Error"); tooltip.Show("Bill Code No is already exist!", txtBillCodeNo); return; } updateBillCode7Layer.BillCode7LayerNo = Convert.ToInt64(txtBillCodeNo.Text); updateBillCode7Layer.BillCodeLayerType = cboBillCodeType.Text; updateBillCode7Layer.UpdatedUserID = UserID; updateBillCode7Layer.UpdatedDate = DateTime.Now; billCode7LayerController.UpdateBillCode7Layer(updateBillCode7Layer); mbsEntities.BillCode7LayerDetail_DeleteByBillCode7LayerID(billCode7LayerID); foreach (DataGridViewRow row in gv7layer.Rows) { BillCode7LayerDetail billCode7LayerDetail = new BillCode7LayerDetail(); billCode7LayerDetail.BillCode7LayerDetailID = Guid.NewGuid().ToString(); billCode7LayerDetail.BillCode7LayerID = billCode7LayerID; billCode7LayerDetail.LowerLimit = Convert.ToDecimal(row.Cells[0].Value); billCode7LayerDetail.UpperLimit = Convert.ToDecimal(row.Cells[1].Value); billCode7LayerDetail.RateUnit = Convert.ToDecimal(row.Cells[2].Value); billCode7LayerDetail.AmountPerUnit = Convert.ToDecimal(row.Cells[3].Value); billCode7LayerDetail.Active = true; billCode7LayerDetail.CreatedDate = DateTime.Now; billCode7LayerDetail.CreatedUserID = UserID; mbsEntities.BillCode7LayerDetail.Add(billCode7LayerDetail); } mbsEntities.SaveChanges(); MessageBox.Show("Successfully Update!", "Update"); Clear(); BillCode7LayerList billcode7LayerListForm = new BillCode7LayerList(); billcode7LayerListForm.Show(); this.Close(); } else { if (gv7layer.Rows.Count == 0) { MessageBox.Show("please define layers information firstly!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int billCodeNoCount = 0; long billCodeNo = Convert.ToInt64(txtBillCodeNo.Text); billCodeNoCount = (from b in mbsEntities.BillCode7Layer where b.BillCode7LayerNo == billCodeNo && b.Active == true select b).ToList().Count; if (billCodeNoCount > 0) { tooltip.SetToolTip(txtBillCodeNo, "Error"); tooltip.Show("Bill Code No is already exist!", txtBillCodeNo); MessageBox.Show("Bill Code No is already exist!", "Error"); return; } billCode7Layer.BillCode7LayerID = Guid.NewGuid().ToString(); billCode7Layer.BillCode7LayerNo = Convert.ToInt64(txtBillCodeNo.Text); billCode7Layer.BillCodeLayerType = cboBillCodeType.Text; billCode7Layer.Active = true; billCode7Layer.CreatedUserID = UserID; billCode7Layer.CreatedDate = DateTime.Now; billCode7LayerController.Save(billCode7Layer); foreach (DataGridViewRow row in gv7layer.Rows) { BillCode7LayerDetail billCode7LayerDetail = new BillCode7LayerDetail(); billCode7LayerDetail.BillCode7LayerDetailID = Guid.NewGuid().ToString(); billCode7LayerDetail.BillCode7LayerID = billCode7Layer.BillCode7LayerID; billCode7LayerDetail.LowerLimit = Convert.ToDecimal(row.Cells[0].Value); billCode7LayerDetail.UpperLimit = Convert.ToDecimal(row.Cells[1].Value); billCode7LayerDetail.RateUnit = Convert.ToDecimal(row.Cells[2].Value); billCode7LayerDetail.AmountPerUnit = Convert.ToDecimal(row.Cells[3].Value); billCode7LayerDetail.Active = true; billCode7LayerDetail.CreatedDate = DateTime.Now; billCode7LayerDetail.CreatedUserID = UserID; mbsEntities.BillCode7LayerDetail.Add(billCode7LayerDetail); } mbsEntities.SaveChanges(); MessageBox.Show("Success", "Save Success"); Clear(); BillCode7LayerList billcode7LayerListForm = new BillCode7LayerList(); billcode7LayerListForm.UserID = this.UserID; billcode7LayerListForm.Show(); this.Close(); } } }
public BillCode7Layer GetBillCode7LayerByBillCode(long billCodeNo) { BillCode7Layer _billCode7Layer = mBMSEntities.BillCode7Layer.Where(x => x.BillCode7LayerNo == billCodeNo && x.Active == true).SingleOrDefault(); return(_billCode7Layer); }
public void Save(BillCode7Layer bc) { mBMSEntities.BillCode7Layer.Add(bc); mBMSEntities.SaveChanges(); }