protected void uiGridViewPayments_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditPayment")
            {
                IStock.BLL.Payments objData = new IStock.BLL.Payments();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));

                uiTextBoxCode.Text = objData.PaymentNo.ToString();
                uiTextBoxDate.Text = objData.PaymentDate.ToString("dd/MM/yyy");
                uiDropDownListClients.SelectedValue = objData.ClientID.ToString();
                if (!objData.IsColumnNull("PaymentTypeID"))
                    uiRadioButtonListPaymentType.SelectedValue = objData.PaymentTypeID.ToString();
                else
                    uiRadioButtonListPaymentType.SelectedValue = "1";

                uiDropDownListEmployee.SelectedValue = objData.EmployeeID.ToString();
                uiTextBoxAmount.Text = objData.Amount.ToString();

                uiPanelAllPayments.Visible = false;
                uiPanelEditPayment.Visible = true;

                CurrentPayment = objData;

                EnableDisableControls();
            }
            else if (e.CommandName == "DeletePayment")
            {
                try
                {
                    IStock.BLL.Payments objData = new IStock.BLL.Payments();
                    objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));

                    IStock.BLL.Clients client = new IStock.BLL.Clients();
                    client.LoadByPrimaryKey(objData.ClientID);
                    client.StartCredit += objData.Amount;
                    client.Save();

                    objData.MarkAsDeleted();
                    objData.Save();
                    BindPayments();
                }
                catch (Exception ex)
                {
                    uipanelError.Visible = true;
                }
            }
        }
 private void BindPayments()
 {
     IStock.BLL.Payments payments = new IStock.BLL.Payments();
     payments.GetAllPayments();
     uiGridViewPayments.DataSource = payments.DefaultView;
     uiGridViewPayments.DataBind();
 }
        protected void uiLinkButtonOK_Click(object sender, EventArgs e)
        {
            IStock.BLL.Payments Payment = new IStock.BLL.Payments();
            if (CurrentPayment == null)
            {
                Payment.AddNew();
                Payment.Confirmed = false;
            }
            else
                Payment = CurrentPayment;

            Payment.PaymentNo = uiTextBoxCode.Text;
            Payment.ClientID = Convert.ToInt32(uiDropDownListClients.SelectedValue);
            Payment.EmployeeID = Convert.ToInt32(uiDropDownListEmployee.SelectedValue);
            Payment.PaymentDate = DateTime.ParseExact(uiTextBoxDate.Text, "dd/MM/yyyy", null);

            if (!string.IsNullOrEmpty(uiTextBoxAmount.Text))
                Payment.Amount = decimal.Parse(uiTextBoxAmount.Text);
            else
                Payment.Amount = 0;

            Payment.PaymentTypeID = Convert.ToInt32(uiRadioButtonListPaymentType.SelectedValue);

            Payment.Save();

            ClearFields();
            CurrentPayment = null;
            uiPanelEditPayment.Visible = false;
            uiPanelAllPayments.Visible = true;
            BindPayments();
        }
 protected void uiLinkButtonCancel_Click(object sender, EventArgs e)
 {
     ClearFields();
     CurrentPayment = null;
     uiPanelEditPayment.Visible = false;
     uiPanelAllPayments.Visible = true;
 }
        protected void uiLinkButtonAdd_Click(object sender, EventArgs e)
        {
            ClearFields();
            CurrentPayment = null;
            uipanelError.Visible = false;
            uiPanelEditPayment.Visible = true;
            IStock.BLL.Payments d = new IStock.BLL.Payments();
            uiTextBoxCode.Text = d.getNewSerial();
            uiPanelAllPayments.Visible = false;

            uiLinkButtonConfirm.Enabled = true;
            uiDropDownListClients.Enabled = true;
            uiTextBoxDate.Enabled = true;
            uiTextBoxAmount.Enabled = true;
            uiRadioButtonListPaymentType.Enabled = true;
            uiTextBoxCode.Enabled = true;
            uiDropDownListEmployee.Enabled = true;
            uiLinkButtonOK.Enabled = true;
            uiLinkButtonOK.Attributes.Remove("disabled");
        }
        protected void uiLinkButtonPaymentPeriod_Click(object sender, EventArgs e)
        {
            uiReportViewerMain.Reset();
            uiReportViewerMain.LocalReport.ReportPath = BaseReportPath + "Report_PaymentsWithinPeriod.rdlc";
            IStock.BLL.Payments payments = new IStock.BLL.Payments();
            DateTime? From = null, To = null;
            if (!string.IsNullOrEmpty(uiTextBoxFrom.Text))
                From = DateTime.ParseExact(uiTextBoxFrom.Text, "dd/MM/yyyy", null);
            if (!string.IsNullOrEmpty(uiTextBoxTo.Text))
                To = DateTime.ParseExact(uiTextBoxTo.Text, "dd/MM/yyyy", null);

            payments.Report_PaymentsWithinPeriod( From, To);

            uiReportViewerMain.LocalReport.DataSources.Clear();
            uiReportViewerMain.LocalReport.DataSources.Add(new ReportDataSource("Report_PaymentsWithinPeriodDataSet", payments.DefaultView));
            uiReportViewerMain.LocalReport.SetParameters(new ReportParameter("From", uiTextBoxFrom.Text));
            uiReportViewerMain.LocalReport.SetParameters(new ReportParameter("To", uiTextBoxTo.Text));
            uiReportViewerMain.LocalReport.Refresh();
        }