protected void grvTime_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var id = long.Parse(grvTime.DataKeys[e.RowIndex].Value.ToString());

            using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
            {
                var financialFileToDelete = mc.Petient_Visiting_Financials.Where(o => o.Id == id).First();
                mc.Petient_Visiting_Financials.Remove(financialFileToDelete);

                mc.SaveChanges();
            }
            bindGridView();
        }
        protected void grvTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
            {
                var row = grvTime.Rows[e.RowIndex];
                var financialId = (long)grvTime.DataKeys[e.RowIndex].Value;
                var financialFile = mc.Petient_Visiting_Financials.Where(o => o.Id == financialId).First();
                var petientId = financialFile.Connectors.First().Petient.Id;

                var calEdit = (JQControls.JQDatePicker)row.FindControl("calEdit");
                var ucTimePickerControlStart = (Controls.TimePickerControl)row.FindControl("ucTimePickerControlStart");
                var ucTimePickerControlEnd = (Controls.TimePickerControl)row.FindControl("ucTimePickerControlEnd");
                var ucServicesControl = (ServicesControl)row.FindControl("ucServicesControl");
                var ddlDoctorEdit = (DropDownList)row.FindControl("ddlDoctorEdit");
                var ddlTechEdit = (DropDownList)row.FindControl("ddlTechEdit");
                var chkIsPetientCanceled = (CheckBox)row.FindControl("chkIsPetientCanceled");

                //Change Timing
                var date = calEdit.Date.Value.Date;

                var startTime = ucTimePickerControlStart.Time;
                var timeVisitStarts = new DateTime(date.Year, date.Month, date.Day, startTime.Hour, startTime.Minute, 0);

                var endTime = ucTimePickerControlEnd.Time;
                var timeVisitEnds = new DateTime(date.Year, date.Month, date.Day, endTime.Hour, endTime.Minute, 0);

                financialFile.TimeVisitStarts = timeVisitStarts;
                financialFile.TimeVisitEnds = timeVisitEnds;

                //Change Doctor, Tech
                //Change Service
                string reason = null;
                int? selectedService = null;
                List<int> selectedParts = null;

                getServicesOfFile(out reason, out selectedService, out selectedParts, ref ucServicesControl);
                financialFile.Reason = reason;
                createRemoveConnections(mc, selectedService, financialFile.Connectors.First().Petient.Id, financialId, selectedParts, ref ucServicesControl, ref ddlDoctorEdit, ref ddlTechEdit);

                //Canceled
                financialFile.Is_Petient_Canceled = chkIsPetientCanceled.Checked;
                if (financialFile.Is_Petient_Canceled == false)
                {
                    //Recalculate Balance On Not Canceled
                    if (reason == null)
                    {
                        financialFile.Money_To_Pay = costOfService(ucServicesControl.SelectedService, ref ucServicesControl);
                    }
                    else
                    {
                        financialFile.Money_To_Pay = 0;
                    }

                    int lastBalance = 0;
                    var petientVisitingFiles = mc.Connectors.Where(o => o.PetientId == petientId && o.FinancialId != null
                        && o.Petient_Visiting_Financials.TimeVisitStarts < financialFile.TimeVisitStarts)
                        .OrderByDescending(o => o.Petient_Visiting_Financials.TimeVisitStarts).ToList();
                    if (petientVisitingFiles.Count() != 0)
                    {
                        lastBalance = petientVisitingFiles.ElementAt(petientVisitingFiles.IndexOf(petientVisitingFiles.First())).Petient_Visiting_Financials.Balance;
                    }
                    financialFile.Balance = lastBalance + (financialFile.Money_To_Pay - (financialFile.Money_Paid_Cash + financialFile.Money_Paid_Card));
                    if (financialFile.Money_Changed != null)
                    {
                        financialFile.Balance = financialFile.Balance + financialFile.Money_Changed.Value;
                    }
                }
                else
                {
                    //Recalculate Balance On Canceled
                    int lastBalance = 0;
                    var petientVisitingFiles = mc.Connectors.Where(o => o.PetientId == petientId && o.FinancialId != null
                        && o.Petient_Visiting_Financials.TimeVisitStarts < financialFile.TimeVisitStarts)
                        .OrderByDescending(o => o.Petient_Visiting_Financials.TimeVisitStarts).ToList();
                    if (petientVisitingFiles.Count() != 0)
                    {
                        lastBalance = petientVisitingFiles.ElementAt(petientVisitingFiles.IndexOf(petientVisitingFiles.First())).Petient_Visiting_Financials.Balance;
                    }
                    financialFile.Money_Changed = 0;
                    financialFile.Money_Paid_Cash = 0;
                    financialFile.Money_Paid_Card = 0;
                    financialFile.POS_Name = "";
                    financialFile.Balance = lastBalance;
                    financialFile.Is_Petient_Returned = false;
                    financialFile.Is_Money_Paid = false;
                    financialFile.Is_Petient_Visited = false;
                }

                //Save Changes
                mc.SaveChanges();
            }
            grvTime.EditIndex = -1;
            bindGridView();
        }
Esempio n. 3
0
        protected void grvState_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
            {
                var row = grvState.Rows[e.RowIndex];
                var id = grvState.DataKeys[e.RowIndex].Value;

                var visitingFile = mc.Petient_Visiting_Financials.Where(o => o.Id == (long)id).First();

                var petientId = Guid.Parse(((Label)row.FindControl("lblPetientId")).Text);

                if (visitingFile.Connectors.First().BSI__Employee_Service_Set == null)
                {
                    visitingFile.Money_To_Pay = int.Parse(((TextBox)row.FindControl("txtMoneyToPay")).Text);
                }
                var moneyChanged = ((TextBox)row.FindControl("txtMoneyChanged")).Text;
                visitingFile.Money_Changed = int.Parse(moneyChanged == "" ? "0" : moneyChanged);
                visitingFile.Money_Paid_Cash = int.Parse(((TextBox)row.FindControl("txtCashPaid")).Text);
                visitingFile.Money_Paid_Card = int.Parse(((TextBox)row.FindControl("txtCardPaid")).Text);
                visitingFile.POS_Name = ((DropDownList)row.FindControl("ddlPOS")).Text;
                visitingFile.Description = ((TextBox)row.FindControl("txtDescription")).Text;

                var txtOperatorUnitValue = (TextBox)row.FindControl("txtOperatorUnitValue");
                if (txtOperatorUnitValue.Visible == true)
                {
                    if(txtOperatorUnitValue.Text != "")
                    {
                        visitingFile.Operator_Unit_Value = short.Parse(txtOperatorUnitValue.Text);

                        if (visitingFile.Connectors.First().BSI__Employee_Service_Set != null && ModelClass.GetUnitName((long?)id) != SharedClass.GetUnit(SharedClass.UnitType.Shut))
                        {
                            var parentServiceStandardValue = ModelClass.GetParentServiceStandardValue((long?)id);
                            if (parentServiceStandardValue.HasValue == true && parentServiceStandardValue.Value != 0)
                            {
                                visitingFile.Money_To_Pay = visitingFile.Money_To_Pay * visitingFile.Operator_Unit_Value.Value / parentServiceStandardValue.Value;
                            }
                        }
                    }
                    else
                    {
                        visitingFile.Operator_Unit_Value = null;
                    }
                }
                else
                {
                    visitingFile.Operator_Unit_Value = null;
                }

                int lastBalance = 0;
                var petientVisitingFiles = mc.Connectors.Where(o => o.PetientId == petientId && o.FinancialId != null
                    && o.Petient_Visiting_Financials.TimeVisitStarts < visitingFile.TimeVisitStarts)
                    .OrderByDescending(o => o.Petient_Visiting_Financials.TimeVisitStarts).ToList();
                if (petientVisitingFiles.Count() != 0)
                {
                    lastBalance = petientVisitingFiles.ElementAt(petientVisitingFiles.IndexOf(petientVisitingFiles.First())).Petient_Visiting_Financials.Balance;
                }
                visitingFile.Balance = lastBalance + (visitingFile.Money_To_Pay - (visitingFile.Money_Paid_Cash + visitingFile.Money_Paid_Card));
                if (visitingFile.Money_Changed != null)
                {
                    visitingFile.Balance = visitingFile.Balance + visitingFile.Money_Changed.Value;
                }


                mc.SaveChanges();
            }
            grvState.EditIndex = -1;
            bindGridView();
        }