public ActionResult Insert(MPacket viewModel, FormCollection formCollection) { UpdateNumericData(viewModel, formCollection); MPacket mPacketToInsert = new MPacket(); TransferFormValuesTo(mPacketToInsert, viewModel); mPacketToInsert.SetAssignedIdTo(viewModel.Id); mPacketToInsert.CreatedDate = DateTime.Now; mPacketToInsert.CreatedBy = User.Identity.Name; mPacketToInsert.DataStatus = EnumDataStatus.New.ToString(); _mPacketRepository.Save(mPacketToInsert); try { _mPacketRepository.DbContext.CommitChanges(); } catch (Exception e) { _mPacketRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public IEnumerable <MPacketItemCat> GetPagedItemList(string orderCol, string orderBy, int pageIndex, int maxRows, ref int totalRows, string packetId) { MPacket mPacket = null; if (!string.IsNullOrEmpty(packetId)) { mPacket = new MPacketRepository().Get(packetId); } ICriteria criteria = Session.CreateCriteria(typeof(MPacketItemCat)); //calculate total rows if (mPacket != null) { criteria.Add(Expression.Eq("PacketId", mPacket)); } totalRows = criteria .SetProjection(Projections.RowCount()) .FutureValue <int>().Value; //get list results criteria = Session.CreateCriteria(typeof(MPacketItemCat)); if (mPacket != null) { criteria.Add(Expression.Eq("PacketId", mPacket)); } criteria.SetMaxResults(maxRows) .SetFirstResult((pageIndex - 1) * maxRows) .AddOrder(new Order(orderCol, orderBy.Equals("asc") ? true : false)) ; IEnumerable <MPacketItemCat> list = criteria.List <MPacketItemCat>(); return(list); }
public virtual ActionResult Get(string id) { if (!string.IsNullOrEmpty(id)) { MPacket mPacket = _mPacketRepository.Get(id); } return(Content("0")); }
private void TransferFormValuesTo(MPacket mPacketToUpdate, MPacket mPacketFromForm) { mPacketToUpdate.PacketName = mPacketFromForm.PacketName; mPacketToUpdate.PacketPrice = mPacketFromForm.PacketPrice; mPacketToUpdate.PacketPriceVip = mPacketFromForm.PacketPriceVip; mPacketToUpdate.PacketStatus = mPacketFromForm.PacketStatus; mPacketToUpdate.PacketDesc = mPacketFromForm.PacketDesc; }
private void bindingNavigatorSaveItem_Click(object sender, EventArgs e) { if (!ValidateForm()) { return; } if (packetIdTextBox.Enabled == true) { paket = new MPacket(); } else { paket = (MPacket)DataMaster.GetObjectByProperty(typeof(MPacket), MPacket.ColumnNames.PacketId, packetIdTextBox.Text); } paket.PacketId = packetIdTextBox.Text; paket.PacketName = packetNameTextBox.Text; paket.PacketDiscount = packetDiscountNumericUpDown.Value; paket.PacketPrice = packetPriceNumericUpDown.Value; paket.PacketPriceAvg = packetPriceAvgNumericUpDown.Value; paket.PacketDesc = packetDescTextBox.Text; paket.ModifiedBy = lbl_UserName.Text; paket.ModifiedDate = DateTime.Now; if (packetIdTextBox.Enabled == true) { try { DataMaster.SavePersistence(paket); } catch (NHibernate.NonUniqueObjectException) { RecreateBalloon(); balloonHelp.Caption = "Validasi data kurang"; balloonHelp.Content = "Obat puyer dengan kode " + packetIdTextBox.Text + " sudah pernah diinput, silahkan input dengan kode yang lain"; balloonHelp.ShowBalloon(packetIdTextBox); packetIdTextBox.Focus(); return; } ModuleControlSettings.SaveLog(ListOfAction.Insert, packetIdTextBox.Text, ListOfTable.MPacket, lbl_UserName.Text); } else { DataMaster.UpdatePersistence(paket); ModuleControlSettings.SaveLog(ListOfAction.Update, packetIdTextBox.Text, ListOfTable.MPacket, lbl_UserName.Text); } DeleteItemPacket(); SaveItemPacket(); BindData(); }
public ActionResult InsertBill(TTransDet viewModel, FormCollection formCollection, string transId) { //_tTransDetRepository.DbContext.BeginTransaction(); TTrans trans = _tTransRepository.Get(transId); UpdateNumericData(viewModel, formCollection); TTransDet transDetToInsert = new TTransDet(trans); MEmployee emp = _mEmployeeRepository.Get(formCollection["EmployeeId"]); MPacket packet = _mPacketRepository.Get(formCollection["PacketId"]); TransferFormValuesTo(transDetToInsert, viewModel); transDetToInsert.SetAssignedIdTo(Guid.NewGuid().ToString()); transDetToInsert.PacketId = packet; transDetToInsert.EmployeeId = emp; decimal?TotalToCalculate = transDetToInsert.TransDetTotal - (transDetToInsert.TransDetTotal * trans.TransDiscount / 100); transDetToInsert.TransDetCommissionService = CalculateCommission(emp, packet, TotalToCalculate); transDetToInsert.CreatedDate = DateTime.Now; transDetToInsert.CreatedBy = User.Identity.Name; transDetToInsert.DataStatus = EnumDataStatus.New.ToString(); //_tTransDetRepository.Save(transDetToInsert); //try //{ // _tTransDetRepository.DbContext.CommitTransaction(); // TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; // return Content("success"); //} //catch (Exception ex) //{ // _tTransDetRepository.DbContext.RollbackTransaction(); // TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; // return Content(ex.Message); //} //save temporary to session, then display transdetitem form Session[CONST_TRANSDET] = transDetToInsert; var e = new { transDetToInsert.Id, PacketId = transDetToInsert.PacketId.Id, transDetToInsert.TransDetQty }; return(Json(e, JsonRequestBehavior.AllowGet)); }
public MPacketComm GetByEmployeeAndPacket(MEmployee emp, MPacket packet) { StringBuilder sql = new StringBuilder(); sql.AppendLine(@" select p from MPacketComm as p"); sql.AppendLine(@" where p.EmployeeId = :emp"); sql.AppendLine(@" and p.PacketId = :packet"); IQuery q = Session.CreateQuery(sql.ToString()); q.SetEntity("emp", emp); q.SetEntity("packet", packet); return(q.UniqueResult <MPacketComm>()); }
public virtual ActionResult GetList() { var packets = _mPacketRepository.GetAll(); StringBuilder sb = new StringBuilder(); MPacket mPacket = new MPacket(); sb.AppendFormat("{0}:{1};", string.Empty, "-Pilih Paket-"); for (int i = 0; i < packets.Count; i++) { mPacket = packets[i]; sb.AppendFormat("{0}:{1}", mPacket.Id, mPacket.PacketName); if (i < packets.Count - 1) { sb.Append(";"); } } return(Content(sb.ToString())); }
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(packetIdTextBox.Text.Trim())) { if (MessageBox.Show("Anda yakin menghapus data?", "Konfirmasi Hapus Data", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //delete paket paket = (MPacket)DataMaster.GetObjectByProperty(typeof(MPacket), MPacket.ColumnNames.PacketId, packetIdTextBox.Text); DataMaster.Delete(paket); //delete item paket DeleteItemPacket(); ModuleControlSettings.SaveLog(ListOfAction.Delete, packetIdTextBox.Text, ListOfTable.MPacket, lbl_UserName.Text); BindData(); } } }
private static void UpdateNumericData(MPacket viewModel, FormCollection formCollection) { if (!string.IsNullOrEmpty(formCollection["PacketPrice"])) { string PacketPrice = formCollection["PacketPrice"].Replace(",", ""); viewModel.PacketPrice = Convert.ToDecimal(PacketPrice); } else { viewModel.PacketPrice = null; } if (!string.IsNullOrEmpty(formCollection["PacketPriceVip"])) { string PacketPriceVip = formCollection["PacketPriceVip"].Replace(",", ""); viewModel.PacketPriceVip = Convert.ToDecimal(PacketPriceVip); } else { viewModel.PacketPriceVip = null; } }
/// <summary> /// calculate commission, /// if packet commission available, use it, /// else use global commission /// </summary> /// <param name="emp"></param> /// <param name="packet"></param> /// <param name="totalTrans"></param> /// <returns></returns> private decimal?CalculateCommission(MEmployee emp, MPacket packet, decimal?totalTrans) { decimal? commission = 0; string typeCommission = emp.EmployeeCommissionServiceType; decimal? commissionVal = emp.EmployeeCommissionServiceVal; MPacketComm packetComm = _mPacketCommRepository.GetByEmployeeAndPacket(emp, packet); if (packetComm != null) { typeCommission = packetComm.PacketCommType; commissionVal = packetComm.PacketCommVal; } if (typeCommission == EnumCommissionType.Percent.ToString()) { commission = totalTrans * (commissionVal / 100); } else { commission = commissionVal; } return(commission); }
public ActionResult Delete(MItem viewModel, FormCollection formCollection) { MPacket mPacketToDelete = _mPacketRepository.Get(viewModel.Id); if (mPacketToDelete != null) { _mPacketRepository.Delete(mPacketToDelete); } try { _mPacketRepository.DbContext.CommitChanges(); } catch (Exception e) { _mPacketRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Update(MPacket viewModel, FormCollection formCollection) { UpdateNumericData(viewModel, formCollection); MPacket mPacketToUpdate = _mPacketRepository.Get(viewModel.Id); TransferFormValuesTo(mPacketToUpdate, viewModel); mPacketToUpdate.ModifiedDate = DateTime.Now; mPacketToUpdate.ModifiedBy = User.Identity.Name; mPacketToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); try { _mPacketRepository.DbContext.CommitChanges(); } catch (Exception e) { _mPacketRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }