Example #1
0
        protected void btnShow4_Click(object sender, EventArgs e)
        {
            wizardData wData = readWizardSteps();

            using (var dbContext = new OTERTConnStr()) {
                try {
                    dbContext.Configuration.ProxyCreationEnabled = false;
                    OTERT_Entity.Invoices curInvoice;
                    curInvoice             = new OTERT_Entity.Invoices();
                    curInvoice.CustomerID  = wData.CustomerID;
                    curInvoice.DateFrom    = wData.DateFrom;
                    curInvoice.DateTo      = wData.DateTo;
                    curInvoice.RegNo       = wData.Code;
                    curInvoice.IsLocked    = wData.locked;
                    curInvoice.DatePaid    = wData.DatePayed;
                    curInvoice.DateCreated = wData.DateCreated;
                    TasksController tcont          = new TasksController();
                    List <TaskB>    invTasks       = tcont.GetTasksForInvoice(curInvoice.CustomerID, wData.DateFrom, wData.DateTo, wData.SelectedJobs, wData.SelectedTasks);
                    decimal         totalTasksCost = 0;
                    foreach (TaskB curTask in invTasks)
                    {
                        totalTasksCost += curTask.CostActual.GetValueOrDefault();
                    }
                    curInvoice.TasksLineAmount = totalTasksCost;

                    /*
                     * foreach (GridDataItem item in gridSales.MasterTableView.Items) {
                     *  CheckBox chk = (CheckBox)item.FindControl("chk");
                     *  decimal? tasksValue = decimal.Parse(item["TasksCost"].Text);
                     *  decimal? salesValue = decimal.Parse(item["SalesCost"].Text);
                     *  curInvoice.TasksLineAmount = tasksValue;
                     *  if (chk.Checked) {
                     *      curInvoice.DiscountLineAmount = salesValue;
                     *  }
                     *  dbContext.Invoices.Add(curInvoice);
                     * }
                     */
                    dbContext.Invoices.Add(curInvoice);
                    dbContext.SaveChanges();
                    foreach (TaskB curTask in invTasks)
                    {
                        TasksLine newTaskLine = new TasksLine();
                        newTaskLine.InvoiceID = curInvoice.ID;
                        newTaskLine.TaskID    = curTask.ID;
                        newTaskLine.JobID     = curTask.JobID.GetValueOrDefault();
                        dbContext.TasksLine.Add(newTaskLine);
                    }
                    dbContext.SaveChanges();
                }
                catch (Exception) { }
                Response.Redirect("/Pages/Invoices/InvoiceShow.aspx", false);
            }
            //Session["wizardStep"] = wData;
            //showWizardSteps(wData);
        }
Example #2
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            wizardData wData = readWData();

            using (var dbContext = new OTERTConnStr()) {
                try {
                    dbContext.Configuration.ProxyCreationEnabled = false;
                    OTERT_Entity.Invoices curInvoice = dbContext.Invoices.Where(o => o.ID == wData.CustomerID).FirstOrDefault();
                    curInvoice.RegNo    = txtAccountNo.Text.Trim();
                    curInvoice.IsLocked = (chkIsLocked.Checked != null ? (bool)chkIsLocked.Checked : false);
                    curInvoice.DatePaid = (dpDatePay.SelectedDate != null ? (DateTime)dpDatePay.SelectedDate : DateTime.Now);
                    dbContext.SaveChanges();
                }
                catch (Exception ex) { }
                Response.Redirect("/Pages/Invoices/InvoiceShow.aspx", false);
            }
        }
Example #3
0
        protected void btnShow3_Click(object sender, EventArgs e)
        {
            wizardData wData = readWizardSteps();

            wData.Step          = 4;
            wData.SelectedTasks = new List <string>();
            foreach (GridDataItem item in gridTasks.MasterTableView.Items)
            {
                CheckBox chk   = (CheckBox)item.FindControl("chk");
                string   value = item.GetDataKeyValue("ID").ToString();
                if (chk.Checked)
                {
                    wData.SelectedTasks.Add(value);
                }
            }
            //Session["wizardStep"] = wData;
            //showWizardSteps(wData);
            //gridSales.Rebind();
            //wizardData wData = readWizardSteps();
            using (var dbContext = new OTERTConnStr()) {
                try {
                    dbContext.Configuration.ProxyCreationEnabled = false;
                    OTERT_Entity.Invoices curInvoice;
                    curInvoice             = new OTERT_Entity.Invoices();
                    curInvoice.CustomerID  = wData.CustomerID;
                    curInvoice.DateFrom    = wData.DateFrom;
                    curInvoice.DateTo      = wData.DateTo;
                    curInvoice.RegNo       = wData.Code;
                    curInvoice.IsLocked    = wData.locked;
                    curInvoice.DatePaid    = wData.DatePayed;
                    curInvoice.DateCreated = wData.DateCreated;
                    TasksController tcont          = new TasksController();
                    List <TaskB>    invTasks       = tcont.GetTasksForInvoice(curInvoice.CustomerID, wData.DateFrom, wData.DateTo, wData.SelectedJobs, wData.SelectedTasks);
                    decimal         totalTasksCost = 0;
                    foreach (TaskB curTask in invTasks)
                    {
                        totalTasksCost += curTask.CostActual.GetValueOrDefault();
                    }
                    curInvoice.TasksLineAmount = totalTasksCost;
                    dbContext.Invoices.Add(curInvoice);
                    dbContext.SaveChanges();
                    foreach (TaskB curTask in invTasks)
                    {
                        TasksLine newTaskLine = new TasksLine();
                        newTaskLine.InvoiceID = curInvoice.ID;
                        newTaskLine.TaskID    = curTask.ID;
                        newTaskLine.JobID     = curTask.JobID.GetValueOrDefault();
                        Tasks curTaskEntity = dbContext.Tasks.Where(s => s.ID == curTask.ID).First();
                        curTaskEntity.IsLocked = true;
                        DateTime dnow = DateTime.Now;
                        //curTaskEntity.PaymentDateActual = dnow;
                        curTaskEntity.PaymentDateCalculated = wData.DatePayed;
                        curTaskEntity.PaymentDateOrder      = wData.DateCreated;
                        dbContext.TasksLine.Add(newTaskLine);
                    }
                    dbContext.SaveChanges();
                }
                catch (Exception) { }
                Response.Redirect("~/Pages/Invoices/InvoiceShow.aspx", false);
            }
        }