Пример #1
0
        public static void Add(OperationRecord model)
        {
            OperationRecordManager.CreateOperationRecord(model);
            //using (SqlConnection connection = new SqlConnection(appString))
            //{
            //    try
            //    {
            //        // Create the Command and Parameter objects.
            //        SqlCommand cmd = new SqlCommand("", connection);
            //        connection.Open();
            //        if (!model.IsCredit)
            //        {
            //            model.Payment = -model.Payment;
            //        }
            //        int i = (model.IsCredit == true) ? 1 : 0;
            //        cmd.CommandText = "insert into tblUnitOperation(StatusID, CategoryID, IsCredit, ContractorID, UnitID, DueDate, DueAmount, Notes,FinancialAccountID, Amount, FinishDate, InvoiceLink) values (";
            //        cmd.CommandText += model.StatusID + ", " + model.CategoryID + ", " + i + "," + model.ContractorID + ", " + model.UnitID + ",'" + model.DueDate + "', " + model.DueAmount + ", '" + model.Memo;
            //        cmd.CommandText += "'," + model.FinancialBankAccountID + ", " + model.Payment + ", '" + model.CompleteDate + "'," + model.InvoiceLink + "' )";
            //        cmd.ExecuteNonQuery();
            //    }
            //    catch (Exception ex)
            //    {
            //        throw new Exception(ex.Message);
            //    }
            //    finally
            //    {
            //        connection.Close();
            //    }

            //}
        }
Пример #2
0
        public static void EditTask(AddTaskVM model)
        {
            using (SqlConnection connection = new SqlConnection(Helpers.Helpers.GetAppConnectionString()))
            {
                try
                {
                    int linkedExpenseID = GetTaskByID(model.TaskID).LinkedExpenseID;
                    //for closed task, system will auto generated expense
                    if (model.StatusID == (int)Helpers.Helpers.StatusType.Close)
                    {
                        if (model.LinkedExpenseID == 0)
                        {
                            //add expense
                            OperationRecord op = new OperationRecord();
                            op.ContractorID = model.ContractorID;
                            op.CategoryID   = (int)Helpers.Helpers.ExpenseCategory.Repair;
                            op.DueAmount    = model.TotalPayment;
                            op.DueDate      = DateTime.Now;
                            op.CompleteDate = DateTime.Now;
                            op.UnitID       = model.UnitID;
                            //op.UploadBy = Int32.Parse(Session["UserID"].ToString());
                            op.FinancialBankAccountID = model.BankAccountID.ToString();
                            op.Payment            = model.TotalPayment;
                            op.Memo               = "Labor: " + model.Hours + " Milage: " + model.Milage + " Material: " + model.Material;
                            op.StatusID           = (short)Helpers.Helpers.StatusType.Close;
                            model.LinkedExpenseID = OperationRecordManager.CreateOperationRecord(op);
                        }
                        else
                        {
                            //update expense
                            OperationRecord op = OperationRecordManager.GetExpenseByID(model.LinkedExpenseID);
                            op.ContractorID = model.ContractorID;
                            op.CategoryID   = (int)Helpers.Helpers.ExpenseCategory.Repair;
                            op.DueAmount    = model.TotalPayment;
                            op.DueDate      = DateTime.Now;
                            op.CompleteDate = DateTime.Now;
                            op.UnitID       = model.UnitID;
                            //op.UploadBy = Int32.Parse(Session["UserID"].ToString());
                            op.FinancialBankAccountID = model.BankAccountID.ToString();
                            op.Payment = model.TotalPayment;
                            op.Memo    = "Labor: " + model.Hours + " Milage: " + model.Milage + " Material: " + model.Material;
                            OperationRecordManager.UpdateOperationRecord(op);
                        }
                    }
                    // Create the Command and Parameter objects.
                    SqlCommand cmd = new SqlCommand("", connection);
                    connection.Open();
                    model.TotalPayment = model.Hours * 15 + model.Milage * 0.53 + model.Material;
                    cmd.CommandText    = "Update tblTasks set TaskDetail = '" + model.TaskDetail.Replace("'", "") + "', UpdateDate='" + DateTime.Now
                                         + "', ContractorID=" + model.ContractorID
                                         + ", StatusID=" + model.StatusID
                                         + ", WorkHours =" + model.Hours
                                         + ", Milage =" + model.Milage
                                         + ", Labor =" + model.Labor
                                         + ", MaterialCost =" + model.Material
                                         + ", TotalCost =" + model.TotalPayment
                                         + ", PaymentBankAccountID =" + model.BankAccountID
                                         + ", LinkedExpenseID =" + model.LinkedExpenseID
                                         + ", UnitID =" + model.UnitID
                                         + "  where TaskID=" + model.TaskID;
                    cmd.ExecuteNonQuery();

                    connection.Close();
                }
                catch (Exception ex)
                {
                    string exms = ex.Message;
                }
            }
        }