Пример #1
0
        public ActionResult QuotationLinkageSave(OrderQuotationLinkageModel model)
        {
            bool isSuccess = true;
            string errorType = string.Empty;
            try
            {
                if (model.quotationID.HasValue)
                {
                    bool isQuotationExist = (this._db.recsys_quotation.Where(q => q.id == model.quotationID).Count() > 0);
                    if (!isQuotationExist)
                    {
                        isSuccess = false;
                        errorType = "Not-Exist-Quotation";
                    }
                    else
                    {
                        bool isExist = (from r in this._db.recsys_relate
                                        where r.table1 == "quotation" && r.table2 == "order" && r.id1 == model.quotationID && r.id2 == model.orderID
                                        select r).Count() > 0;

                        if (isExist)
                        {
                            isSuccess = false;
                            errorType = "Linkage-Exist";
                        }
                        else
                        {
                            int quotationRawCustomerID = (from q in this._db.recsys_quotation
                                                          join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id
                                                          where q.id == model.quotationID
                                                          select rc.customer_id).FirstOrDefault();
                            int orderRawCustomerID = (from o in this._db.recsys_order
                                                      join rc in this._db.recsys_relate_customers on o.customer_id equals rc.id
                                                      where o.id == model.orderID
                                                      select rc.customer_id).FirstOrDefault();

                            if (quotationRawCustomerID != orderRawCustomerID)
                            {
                                isSuccess = false;
                                errorType = "Customer-Not-Match";
                            }
                            else
                            {
                                recsys_relate newRelation = new recsys_relate
                                {
                                    table1 = "quotation",
                                    table2 = "order",
                                    id1 = model.quotationID.Value,
                                    id2 = model.orderID
                                };
                                this._db.recsys_relate.AddObject(newRelation);
                                this._db.SaveChanges();
                            }
                        }
                    }
                }
                else
                {
                    isSuccess = false;
                    errorType = "Wrong-Quotation-ID";
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return Json(new { isSuccess = isSuccess, errorType = errorType });
        }
Пример #2
0
        public ActionResult AddSave_Quotation(OrderRecord data)
        {
            Member member;
            recsys_relate_customers masterCustomerData;
            recsys_relate_customers customerData;
            recsys_order order;
            recsys_relate relation;

            //# validation
            if (data.MasterRecordID < 0)
                throw new SystemException("Invalid Entity ID");

            //# get old master customer record
            var _masterCustomerData = from q in this._db.recsys_quotation
                                      join cd in this._db.recsys_relate_customers on q.customer_id equals cd.id into cds
                                      from cd in cds.DefaultIfEmpty()
                                      where q.id == data.MasterRecordID
                                      select new
                                      {
                                          cd
                                      };
            masterCustomerData = _masterCustomerData.Select(theRecord => theRecord.cd).FirstOrDefault();

            //# validation
            if (masterCustomerData == null)
                throw new RecordNotFoundException();

            member = new Member("users");

            //# mapping
            customerData = new recsys_relate_customers()
            {
                address1 = data.address1,
                address2 = data.address2,
                center = masterCustomerData.center,
                code = masterCustomerData.code,
                contact = data.contact,
                customer_code = masterCustomerData.customer_code,
                customer_id = masterCustomerData.customer_id,
                district1 = data.district1,
                district2 = data.district2,
                email = data.email,
                fax1 = data.fax1,
                fax2 = data.fax2,
                group_id = data.group_id,
                manual_input_code = masterCustomerData.manual_input_code,
                name = data.name,
                chi_name = data.chi_name,
                prefix = masterCustomerData.prefix,
                relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation,
                remark = data.remark,
                tel1 = data.tel1,
                tel2 = data.tel2,
                title = (byte)data.title,
                type = (byte)masterCustomerData.type
            };

            this._db.recsys_relate_customers.AddObject(customerData);

            TimeSpan? endTime = null;
            if (!(String.IsNullOrEmpty(data.EndTimeHour)) && !(String.IsNullOrEmpty(data.EndTimeMinute)))
                endTime = new TimeSpan(Convert.ToInt32(data.EndTimeHour), Convert.ToInt32(data.EndTimeMinute), 0);

            TimeSpan? startTime = null;
            if (!(String.IsNullOrEmpty(data.StartTimeHour)) && !(String.IsNullOrEmpty(data.StartTimeMinute)))
                startTime = new TimeSpan(Convert.ToInt32(data.StartTimeHour), Convert.ToInt32(data.StartTimeMinute), 0);

            order = new recsys_order()
            {
                by_system = 1,
                completion_date = DateChecking(data.CompleteDate),
                end_time = endTime,
                engineer_id_1 = data.engineer_id_1,
                engineer_id_2 = data.engineer_id_2,
                engineer_id_3 = data.engineer_id_3,
                engineer_id_4 = data.engineer_id_4,
                fault = data.fault,
                model = data.model,
                repair = data.repair,
                repair_date = DateChecking(data.repair_date),
                report = data.report,
                reviewer = data.reviewer,
                start_time = startTime,
                tc = (byte)(data.tc ? 1 : 0),
                create_date = DateTime.Now,
                last_update = DateTime.Now,
                remark = data.remark2,
                status = (byte)data.status,
                update_user_id = (int)member.infoBySession("id"),
                job_number = data.JobNumber,
                order_status = data.order_status
            };

            //alter 故障內容
            if (!string.IsNullOrEmpty(order.fault))
            {
                int index1 = order.fault.IndexOf("[");
                int index2 = order.fault.IndexOf("]");
                if (index1 > -1 && index2 > -1)
                    order.fault = order.fault.Substring(index2 + 1);
            }

            if (order.completion_date.HasValue)
            {
                order.order_status = OrderStatus.WarrantyCompleted.ID;
                order.fault = "[" + OrderStatus.WarrantyCompleted.Name + "] " + order.fault;
            }
            else if (order.order_status == OrderStatus.DoingWarranty.ID)
            {
                order.fault = "[" + OrderStatus.DoingWarranty.Name + "] " + order.fault;
                order.order_status = OrderStatus.DoingWarranty.ID;
            }
            else if (order.order_status == OrderStatus.AppointedWarranty.ID)
            {
                order.fault = "[" + OrderStatus.AppointedWarranty.Name + "] " + order.fault;
                order.order_status = OrderStatus.AppointedWarranty.ID;
            }

            this._db.recsys_order.AddObject(order);

            try
            {
                this._db.SaveChanges();

                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, customerData);
                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, order);

                order.customer_id = customerData.id;

                this._db.SaveChanges();

                data.id = order.id;

                relation = new recsys_relate()
                {
                    id1 = data.MasterRecordID,
                    id2 = order.id,
                    table1 = "quotation",
                    table2 = "order"
                };

                this._db.recsys_relate.AddObject(relation);

                this._db.SaveChanges();

                data.SaveResult.SavedSuccessfully = true;
            }
            catch (OptimisticConcurrencyException)
            {
                //# log down
            }

            return Json(data);
        }
Пример #3
0
        public ActionResult Edit(string id,
            DateTime? completion_date,
            int? enquery_id,
            TimeSpan? end_time,
            int? engineer_id_1,
            int? engineer_id_2,
            string fault,
            string model,
            string remark2,
            string repair,
            DateTime? repair_date,
            string report,
            string reviewer,
            TimeSpan? start_time,
            byte? status,
            byte? tc,
            int? relate_id,
            string relate_table)
        {
            Validator _val = new Validator();
            string customer_code = Common.doPost("customer_code");
            string mode = Common.doGet("mode");
            string type = Common.doPost("type");
            string prefix = Common.doPost("prefix");
            string code = Common.doPost("code");
            string name = Common.doPost("name");
            string address1 = Common.doPost("address1");
            string address2 = Common.doPost("address2");
            string district1 = Common.doPost("district1");
            string district2 = Common.doPost("district2");
            string title = Common.doPost("title");
            string contact = Common.doPost("contact");
            string tel1 = Common.doPost("tel1");
            string tel2 = Common.doPost("tel2");
            string fax1 = Common.doPost("fax1");
            string fax2 = Common.doPost("fax2");
            string email = Common.doPost("email");
            string remark = Common.doPost("remark");
            //string model = Common.doPost("model");
            //string fault = Common.doPost("fault");
            //string repair = Common.doPost("repair");
            //dynamic tc = Common.doPost("tc");
            //string report = Common.doPost("report");
            //string repair_date = Common.doPost("repair_date");
            //string start_time = Common.doPost("start_time");
            //string end_time = Common.doPost("end_time");
            //string remark2 = Common.doPost("remark2");
            //string status = Common.doPost("status");
            string group_id = Common.doPost("group_id");
            string last_update = Common.doPost("last_update");
            string oper = Common.doPost("oper");
            //string relate_id = Common.doPost("relate_id");
            //string relate_table = Common.doPost("relate_table");

            string sql;
            if(oper != "del")
            {
                if (oper == "edit")
                {
                    if (_val.val(id, new String[] { "req", "int" }))
                    {
                        int order_id = Convert.ToInt32(id);
                        string time = ((from o in this._db.recsys_order
                                        where o.id == order_id
                                        select o.last_update).FirstOrDefault()).ToString();
                        if (! _val.val(last_update, "equal=" + time))
                        {
                            return Content(Common.alert("資料已被其他使用者更新"));
                        }
                    }
                }
                else
                {
                    if (type == "3")
                    {
                        _val.val(code, new String[] { "req", "int", "minlen=8", "maxlen=8" });
                    }
                    _val.val(type, new String[] { "req", "int", "get=1", "let=3" });
                }
                //_val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                _val.val(status.ToString(), new String[] { "req", "int", "get=0", "let=1" });
                if(_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "type", type },
                        { "prefix", prefix },
                        { "code", code },
                        { "group_id", group_id },
                        { "name", name },
                        { "address1", address1 },
                        { "address2", address2 },
                        { "district1", district1 },
                        { "district2", district2 },
                        { "title", title },
                        { "contact", contact },
                        { "tel1", tel1 },
                        { "tel2", tel2 },
                        { "fax1", fax1 },
                        { "fax2", fax2 },
                        { "email", email },
                        { "remark", remark }
                    };
                    int count = (from c in this._db.recsys_customers
                                 where c.customer_code == customer_code
                                 select c.id).Count();
                    if (count == 0)
                    {
                        data["status"] = 1;
                        data["last_update"] = DateTime.Now.ToString("s");
                        data["update_user_id"] = _member.infoBySession("id");
                        data["create_date"] = DateTime.Now.ToString("s");
                        sql = Common.doInsert(data, "customers");
                        this._db.ExecuteStoreCommand(sql);
                        int cid = (from c in this._db.recsys_customers
                                   orderby c.id descending
                                   select c.id).FirstOrDefault();
                        Hashtable data2 = new Hashtable();
                        if (type != "3")
                        {
                            data2["auto_id"] = Convert.ToInt32((from c in this._db.recsys_customers
                                                               where c.type != 3 && c.auto_id != 0
                                                               orderby c.id descending
                                                               select c.auto_id).FirstOrDefault()) + 1;
                            code = data2["auto_id"].ToString().PadLeft(8, '0');
                        }
                        customer_code = this._type[type] + prefix + code;
                        data2["customer_code"] = customer_code;
                        sql = Common.doUpdate(data2, "customers", "id = '" + cid + "'");
                        this._db.ExecuteStoreCommand(sql);
                        data.Remove("status");
                        data.Remove("last_update");
                        data.Remove("update_user_id");
                        data.Remove("create_date");
                    }
                    int customer_id;
                    data["customer_code"] = customer_code;
                    customer_id = (from c in this._db.recsys_customers
                                   where c.customer_code == customer_code
                                   select c.id).FirstOrDefault();
                    data["customer_id"] = customer_id;
                    if (oper == "edit")
                    {
                        int order_id = Convert.ToInt32(id);
                        customer_id = (from o in this._db.recsys_order
                                       where o.id == order_id
                                       select o.customer_id).FirstOrDefault();
                        sql = Common.doUpdate(data, "relate_customers", "id = '" + customer_id + "'");
                        this._db.ExecuteStoreCommand(sql);
                    }
                    else
                    {
                        data["relate_type"] = 4;
                        sql = Common.doInsert(data, "relate_customers");
                        this._db.ExecuteStoreCommand(sql);
                        customer_id = (from c in this._db.recsys_relate_customers
                                       orderby c.id descending
                                       select c.id).FirstOrDefault();
                    }
                    recsys_order newOrder = new recsys_order()
                    {
                        by_system = 0,
                        completion_date = null,
                        create_date = DateTime.Now,
                        customer_id = customer_id,
                        enquery_id = enquery_id,
                        end_time = end_time,
                        engineer_id_1 = engineer_id_1,
                        engineer_id_2 = engineer_id_2,
                        fault = fault,
                        last_update = DateTime.Now,
                        model = model,
                        remark = remark2,
                        repair = repair,
                        repair_date = repair_date,
                        report = report,
                        reviewer = reviewer,
                        start_time = start_time,
                        status = status ?? 1,
                        tc = tc,
                        update_user_id = (int) _member.infoBySession("id")
                    };

                    if(oper == "edit")
                    {
                        ////
                        //sql = Common.doUpdate(data3, "order", "id = '" + id + "'");
                        this._db.ExecuteStoreCommand(sql);
                    }
                    else
                    {

                        try
                        {
                            this._db.recsys_order.AddObject(newOrder);

                            this._db.SaveChanges();

                            this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newOrder);

                            if (newOrder.id > 0 && relate_id > 0)
                            {
                                id = newOrder.id.ToString();        //# temp solution

                                recsys_relate newRelation = new recsys_relate()
                                {
                                    id1 = relate_id.Value,
                                    id2 = newOrder.id,
                                    table1 = relate_table,
                                    table2 = "order"
                                };

                                this._db.recsys_relate.AddObject(newRelation);

                                this._db.SaveChanges();

                                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newRelation);

                            }

                            //data3["customer_id"] = customer_id;
                            //data3["create_date"] = DateTime.Now.ToString("s");
                            //sql = Common.doInsert(data3, "order");
                            //this._db.ExecuteStoreCommand(sql);
                            //id = (from o in this._db.recsys_order
                            //      orderby o.id descending
                            //      select o.id).FirstOrDefault().ToString();
                            //if (!String.IsNullOrWhiteSpace(relate_id))
                            //{
                            //    Hashtable data4 = new Hashtable()
                            //{
                            //    { "id1", relate_id },
                            //    { "id2", id },
                            //    { "table1", relate_table },
                            //    { "table2", "order" }
                            //};
                            //    sql = Common.doInsert(data4, "relate");
                            //    this._db.ExecuteStoreCommand(sql);
                            //}

                        }
                        catch(OptimisticConcurrencyException)
                        {
                            //# log down
                        }

                    }
                    return RedirectToAction("edit", new { id = id, mode = mode, customer_id = customer_id, relate_id = relate_id, relate_table = relate_table });
                }
                else
                {
                    return Content(Common.alert("輸入錯誤"));
                }
            }
            else
            {
                int order_id = Convert.ToInt32(id);
                int customer_id = (from o in this._db.recsys_order
                                   where o.id == order_id
                                   select o.customer_id).FirstOrDefault();
                sql = Common.doDelete("relate_customers", "id = '" + customer_id + "'");
                this._db.ExecuteStoreCommand(sql);
                int[] parts_id = (from r in this._db.recsys_relate
                                  where r.id2 == order_id && r.table1 == "parts" && r.table2 == "order"
                                  select r.id1).ToArray();
                if (parts_id.Length > 0)
                {
                    sql = Common.doDelete("parts", "id IN ('" + String.Join("','", parts_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                int[] job_id = (from r in this._db.recsys_relate
                                where r.id1 == order_id && r.table1 == "order" && r.table2 == "job"
                                select r.id2).ToArray();
                if (job_id.Length > 0)
                {
                    sql = Common.doDelete("job", "id IN ('" + String.Join("','", job_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                int[] extra_cost_id = (from r in this._db.recsys_relate
                                       where r.id1 == order_id && r.table1 == "order" && r.table2 == "extra_cost"
                                       select r.id2).ToArray();
                if (extra_cost_id.Length > 0)
                {
                    sql = Common.doDelete("extra_cost", "id IN ('" + String.Join("','", extra_cost_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                sql = Common.doDelete("relate", "(id1 = '" + id + "' AND table1 = 'order') OR (id2 = '" + id + "' AND table2 = 'order')");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("order_report", "order_id = '" + id + "'");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("order", "id = '" + id + "'");
                this._db.ExecuteStoreCommand(sql);
                return Content(Common.json_encode(true));
            }
        }
Пример #4
0
        public ActionResult QuickCreateSave(QuotationQuickCreateModel model, List<QuotationQuickCreateQuotationItemModel> items)
        {
            bool isSuccess = true;
            string exceptionMessage = string.Empty;
            string errorType = string.Empty;
            Member member = new Member("users");
            int quotationID=0;
            recsys_quotation quotation = null;
            recsys_relate_customers relateCustomer = null;

            try
            {
                #region Validation
                if (!model.nCustomerID.HasValue || model.nCustomerID == 0)
                {
                    return Json(new
                    {
                        isSuccess = false,
                        errorType = "Invalidation",
                        exceptionMessage = "請選擇Customer"
                    });
                }
                if (!model.nWorkingDistrictID.HasValue || model.nWorkingDistrictID == 0)
                {
                    return Json(new
                    {
                        isSuccess = false,
                        errorType = "Invalidation",
                        exceptionMessage = "請選擇工作地址地區"
                    });
                }
                if (!string.IsNullOrEmpty(model.sInvoiceNumber) && model.bIsDummy)
                {
                     return Json(new
                    {
                         isSuccess = false,
                        errorType = "Invalidation",
                        exceptionMessage = "請刪除Invoice No或取消選取'Dummy'"
                    });
                }
                if (!string.IsNullOrEmpty(model.sMinorWorkExtension) && model.sMinorWorkExtension.Length > 3)
                {
                    return Json(new
                    {
                        isSuccess = false,
                        errorType = "Invalidation",
                        exceptionMessage = "請修改Minor Work至3字以內'"
                    });
                }
                if (items != null && items.Count() > 0)
                {
                    List<string> quotationItemCodes = items.Select(i => i.sCode).ToList();
                    for (int i = 0; i < quotationItemCodes.Count(); i++)
                    {
                        if (!string.IsNullOrWhiteSpace(quotationItemCodes[i]))
                        {
                            for (int j = i + 1; j < quotationItemCodes.Count(); j++)
                            {
                                if (!string.IsNullOrEmpty(quotationItemCodes[j]) && !string.IsNullOrEmpty(quotationItemCodes[j].Trim()) && quotationItemCodes[j].Trim().ToUpper() == quotationItemCodes[i].Trim().ToUpper())
                                {
                                    return Json(new
                                    {
                                        isSuccess = false,
                                        errorType = "Quotation-Item-Duplication",
                                        exceptionMessage = "重覆Quotation item (" + quotationItemCodes[j] + ")",
                                    });
                                }
                            }
                        }
                    }
                }
                #endregion Validation

                if (model.Mode == PageMode.Add)
                {
                    #region Create Relate Customer
                    recsys_customers rawCustomer = this._db.recsys_customers.Where(c => c.id == model.nCustomerID.Value).FirstOrDefault();
                    relateCustomer = new recsys_relate_customers()
                    {
                        address1 = rawCustomer.address1,
                        address2 = model.sWorkingAddress,
                        center = rawCustomer.center,
                        code = rawCustomer.code,
                        contact = rawCustomer.contact,
                        customer_code = rawCustomer.customer_code,
                        customer_id = rawCustomer.id,
                        district1 = rawCustomer.district1,
                        district2 = model.nWorkingDistrictID,
                        email = rawCustomer.email,
                        fax1 = rawCustomer.fax1,
                        fax2 = rawCustomer.fax2,
                        group_id = rawCustomer.group_id,
                        manual_input_code = rawCustomer.manual_input_code,
                        name = rawCustomer.name,
                        chi_name = rawCustomer.chi_name,
                        prefix = rawCustomer.prefix,
                        relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation,
                        reference_number = rawCustomer.reference_number,
                        remark = rawCustomer.remark,
                        tel1 = rawCustomer.tel1,
                        tel2 = rawCustomer.tel2,
                        title = rawCustomer.title,
                        type = rawCustomer.type
                    };
                    this._db.recsys_relate_customers.AddObject(relateCustomer);
                    this._db.SaveChanges();
                    #endregion Create Relate Customer

                    #region Create Quotation
                    quotation = new recsys_quotation()
                    {
                        customer_id = relateCustomer.id,
                        dummy = (byte)(model.bIsDummy ? 1 : 0),
                        dummy_date = this.ConvertDateStringFormat(model.dDummyDueDate, DATEPICKER_DATE_FORMAT),
                        initial = model.sInitial,
                        lang = 1,
                        order_number = model.sOrderNumber,
                        number = model.sACQNumber,
                        subcon_estimation = model.nSubConEstimation.HasValue ? model.nSubConEstimation : 0.00,
                        subcon_name = model.sSubConName,
                        subcon_estimation2 = model.nSubConEstimation2.HasValue ? model.nSubConEstimation2 : 0.00,
                        subcon_name2 = model.sSubConName2,
                        subcon_estimation3 = model.nSubConEstimation3.HasValue ? model.nSubConEstimation3 : 0.00,
                        subcon_name3 = model.sSubConName3,
                        supervision = model.nSupervision.HasValue ? model.nSupervision : 0.00,
                        supplier_id = model.nMaterialEstimation.HasValue ? model.nMaterialEstimation : 0.00,
                        material_estimation2 = model.nMaterialEstimation2.HasValue ? model.nMaterialEstimation2 : 0.00,
                        material_estimation3 = model.nMaterialEstimation3.HasValue ? model.nMaterialEstimation3 : 0.00,
                        supplier_estimation = model.nSupplierEstimation.HasValue ? model.nSupplierEstimation : 0.00,
                        supplier_name = model.sSupplierName,
                        supplier_estimation2 = model.nSupplierEstimation2.HasValue ? model.nSupplierEstimation2 : 0.00,
                        supplier_name2 = model.sSupplierName2,
                        supplier_estimation3 = model.nSupplierEstimation3.HasValue ? model.nSupplierEstimation3 : 0.00,
                        supplier_name3 = model.sSupplierName3,
                        payment_received_date = this.ConvertDateStringFormat(model.dPaymentRecdDate, DATEPICKER_DATE_FORMAT),
                        tender_number = model.sTenderNumber,
                        direct_labour = model.bIsDirectLabour,
                        direct_labour_cost = model.nDirectLabourCost.HasValue ? model.nDirectLabourCost : 0.00,
                        billing_date = this.ConvertDateStringFormat(model.dBillingDate, DATEPICKER_DATE_FORMAT),
                        confirm_date = this.ConvertDateStringFormat(model.dConfirmDate, DATEPICKER_DATE_FORMAT),
                        create_date = DateTime.Now,
                        invoice = model.sInvoiceNumber,
                        invoice_date = this.ConvertDateStringFormat(model.dInvoiceDate, DATEPICKER_DATE_FORMAT),
                        minor_work = model.sMinorWorkExtension,
                        minor_work_currency = model.nMinorWork.HasValue ? model.nMinorWork : 0.00,
                        gp = model.nGP.HasValue ? model.nGP : 0.00,
                        last_update = DateTime.Now,
                        remark = model.sRemark,
                        status = 1,
                        update_user_id = (int)member.infoBySession("id"),
                        issue_date = this.ConvertDateStringFormat(model.dIssueDate, DATEPICKER_DATE_FORMAT)
                    };
                    if (model.Mode==PageMode.Add)
                        this._db.recsys_quotation.AddObject(quotation);
                    this._db.SaveChanges();
                    #endregion Create Update Quotation
                }
                else
                {
                    #region Update Quotation
                    quotation = (from q in this._db.recsys_quotation
                                 where q.id == model.nQuotationID
                                 select q).FirstOrDefault();

                    quotation.dummy = (byte)(model.bIsDummy ? 1 : 0);
                    quotation.dummy_date = this.ConvertDateStringFormat(model.dDummyDueDate, DATEPICKER_DATE_FORMAT);
                    quotation.initial = model.sInitial;
                    quotation.order_number = model.sOrderNumber;
                    quotation.number = model.sACQNumber;
                    quotation.subcon_estimation = model.nSubConEstimation.HasValue ? model.nSubConEstimation : 0.00;
                    quotation.subcon_name = model.sSubConName;
                    quotation.subcon_estimation2 = model.nSubConEstimation2.HasValue ? model.nSubConEstimation2 : 0.00;
                    quotation.subcon_name2 = model.sSubConName2;
                    quotation.subcon_estimation3 = model.nSubConEstimation3.HasValue ? model.nSubConEstimation3 : 0.00;
                    quotation.subcon_name3 = model.sSubConName3;
                    quotation.supervision = model.nSupervision.HasValue ? model.nSupervision : 0.00;
                    quotation.supplier_id = model.nMaterialEstimation.HasValue ? model.nMaterialEstimation : 0.00;
                    quotation.material_estimation2 = model.nMaterialEstimation2.HasValue ? model.nMaterialEstimation2 : 0.00;
                    quotation.material_estimation3 = model.nMaterialEstimation3.HasValue ? model.nMaterialEstimation3 : 0.00;
                    quotation.supplier_estimation = model.nSupplierEstimation.HasValue ? model.nSupplierEstimation : 0.00;
                    quotation.supplier_name = model.sSupplierName;
                    quotation.supplier_estimation = model.nSupplierEstimation2.HasValue ? model.nSupplierEstimation2 : 0.00;
                    quotation.supplier_name2 = model.sSupplierName2;
                    quotation.supplier_estimation3 = model.nSupplierEstimation3.HasValue ? model.nSupplierEstimation3 : 0.00;
                    quotation.supplier_name3 = model.sSupplierName3;
                    quotation.payment_received_date = this.ConvertDateStringFormat(model.dPaymentRecdDate, DATEPICKER_DATE_FORMAT);
                    quotation.tender_number = model.sTenderNumber;
                    quotation.direct_labour = model.bIsDirectLabour;
                    quotation.direct_labour_cost = model.nDirectLabourCost.HasValue ? model.nDirectLabourCost : 0.00;
                    quotation.billing_date = this.ConvertDateStringFormat(model.dBillingDate, DATEPICKER_DATE_FORMAT);
                    quotation.confirm_date = this.ConvertDateStringFormat(model.dConfirmDate, DATEPICKER_DATE_FORMAT);
                    quotation.invoice = model.sInvoiceNumber;
                    quotation.invoice_date = this.ConvertDateStringFormat(model.dInvoiceDate, DATEPICKER_DATE_FORMAT);
                    quotation.minor_work = model.sMinorWorkExtension;
                    quotation.minor_work_currency = model.nMinorWork.HasValue ? model.nMinorWork : 0.00;
                    quotation.gp = model.nGP.HasValue ? model.nGP : 0.00;
                    quotation.last_update = DateTime.Now;
                    quotation.remark = model.sRemark;
                    quotation.update_user_id = (int)member.infoBySession("id");
                    quotation.issue_date = this.ConvertDateStringFormat(model.dIssueDate, DATEPICKER_DATE_FORMAT);

                    this._db.SaveChanges();
                    #endregion Update Quotation

                    #region Delete Original Quotation Items
                    var quotationItemsObject = (from qi in this._db.recsys_quotation_items
                                                  join r in this._db.recsys_relate on qi.id equals r.id2
                                                  where r.id1 == model.nQuotationID && r.table1 == "quotation" && r.table2 == "quotation_items"
                                                  select new { qi, r }).ToList();
                    foreach (var qio in quotationItemsObject)
                    {
                        this._db.recsys_quotation_items.DeleteObject(qio.qi);
                        this._db.recsys_relate.DeleteObject(qio.r);
                        this._db.SaveChanges();
                    }
                    #endregion Delete Original Quotation Items
                }

                quotationID = quotation.id;

                #region Create Quotation Items
                if (items != null && items.Count() > 0)
                {
                    int sequence = 1;
                    foreach (QuotationQuickCreateQuotationItemModel item in items)
                    {
                        #region Validation
                        if (string.IsNullOrWhiteSpace(item.sCode) && string.IsNullOrWhiteSpace(item.sDetail) && string.IsNullOrWhiteSpace(item.sDetailChi))
                            continue;
                        #endregion Validation

                        #region Create Quotation Item
                        recsys_quotation_items quotationItem = new recsys_quotation_items
                        {
                            nSequence = sequence,
                            code = string.IsNullOrEmpty(item.sCode) ? string.Empty : item.sCode.Trim(),
                            detail = string.IsNullOrEmpty(item.sDetailChi) ? null : item.sDetailChi.Trim(),
                            detail2 = string.IsNullOrEmpty(item.sDetail) ? null : item.sDetail.Trim(),
                            price = item.nPrice.HasValue ? item.nPrice.Value : 0.00,
                            last_update = DateTime.Now,
                            update_user_id = (int)member.infoBySession("id")
                        };
                        this._db.recsys_quotation_items.AddObject(quotationItem);
                        this._db.SaveChanges();
                        #endregion Create Quotation Item

                        #region Create Relate Record
                        recsys_relate relation = new recsys_relate
                        {
                            table1 = "quotation",
                            table2 = "quotation_items",
                            id1 = quotation.id,
                            id2 = quotationItem.id
                        };
                        this._db.recsys_relate.AddObject(relation);
                        this._db.SaveChanges();
                        #endregion Create Relate Record

                        sequence++;
                    }
                }
                #endregion Create Quotation Items
            }
            catch
            {
                isSuccess = false;
            }
            return Json(
                new
                {
                    isSuccess = isSuccess,
                    quotationID = quotationID
                });
        }
Пример #5
0
        public ActionResult AddSave_Quotation(ECallRecord data)
        {
            Member member;
            recsys_relate_customers masterCustomerData;
            recsys_relate_customers customerData;
            recsys_order ecall;
            recsys_relate relation;

            //# validation
            if (data.MasterRecordID < 0)
                throw new SystemException("Invalid Entity ID");

            //# get old master customer record
            var _masterCustomerData = from q in this._db.recsys_quotation
                                        join cd in this._db.recsys_relate_customers on q.customer_id equals cd.id into cds
                                        from cd in cds.DefaultIfEmpty()
                                        where q.id == data.MasterRecordID
                                        select new
                                        {
                                            cd
                                        };
            masterCustomerData = _masterCustomerData.Select(theRecord => theRecord.cd).FirstOrDefault();

            //# validation
            if (masterCustomerData == null)
                throw new RecordNotFoundException();

            member = new Member("users");

            //# mapping
            customerData = new recsys_relate_customers()
            {
                address1 = data.address1,
                address2 = data.address2,
                center = masterCustomerData.center,
                code = masterCustomerData.code,
                contact = data.contact,
                customer_code = masterCustomerData.customer_code,
                customer_id = masterCustomerData.customer_id,
                district1 = data.district1,
                district2 = data.district2,
                email = data.email,
                fax1 = data.fax1,
                fax2 = data.fax2,
                group_id = data.group_id,
                manual_input_code = masterCustomerData.manual_input_code,
                name = data.name,
                chi_name = data.chi_name,
                prefix = masterCustomerData.prefix,
                relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation,
                remark = data.remark,
                reference_number = masterCustomerData.reference_number,
                tel1 = data.tel1,
                tel2 = data.tel2,
                title = (byte)data.title,
                type = (byte)masterCustomerData.type
            };

            this._db.recsys_relate_customers.AddObject(customerData);

            ecall = new recsys_order()
            {
                by_system = 0,
                completion_date = DateChecking(data.CompleteDate),
                call_pickup_user_id = data.call_pickup_user_id,
                end_time = new TimeSpan(Convert.ToInt32(data.EndTimeHour), Convert.ToInt32(data.EndTimeMinute), 0),
                engineer_id_1 = data.engineer_id_1,
                engineer_id_2 = data.engineer_id_2,
                engineer_id_3 = data.engineer_id_3,
                engineer_id_4 = data.engineer_id_4,
                fault = data.fault,
                model = data.model,
                repair = data.repair,
                repair_date = DateChecking(data.repair_date),
                report = data.report,
                reviewer = data.reviewer,
                start_time = new TimeSpan(Convert.ToInt32(data.StartTimeHour), Convert.ToInt32(data.StartTimeMinute), 0),
                tc = (byte) (data.tc ? 1 : 0),
                create_date = DateTime.Now,
                last_update = DateTime.Now,
                remark = data.remark2,
                status = (byte)data.status,
                update_user_id = (int)member.infoBySession("id"),
                job_number = data.JobNumber,
                order_status = DateChecking(data.CompleteDate).HasValue ? 3 : (DateChecking(data.repair_date).HasValue ? 2 : 1)
            };

            this._db.recsys_order.AddObject(ecall);

            try
            {
                this._db.SaveChanges();

                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, customerData);
                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, ecall);

                ecall.customer_id = customerData.id;

                this._db.SaveChanges();

                data.id = ecall.id;

                relation = new recsys_relate()
                {
                    id1 = data.MasterRecordID,
                    id2 = ecall.id,
                    table1 = "quotation",
                    table2 = "order"
                };

                this._db.recsys_relate.AddObject(relation);

                this._db.SaveChanges();

                data.SaveResult.SavedSuccessfully = true;
            }
            catch (OptimisticConcurrencyException)
            {
                //# log down
            }

            return Json(data);
        }
Пример #6
0
        public JsonResult CostBatchInsertProcess(FormCollection elements)
        {
            bool isSuccess = false;
            Dictionary<int, recsys_costs> insertItems = new Dictionary<int, recsys_costs>();
            List<string> validationControlSelectors = new List<string>();

            string relateIDString = elements["hfRelateID"];
            string relateTableString = elements["hfRelateTable"];
            string relateCenter = "68";

            //get relateCenter with relateIDString and relateTableString
            int relateID1 = Convert.ToInt32(relateIDString);
            if (relateTableString == "quotation")
            {
                var records = from q in this._db.recsys_quotation
                              join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id into rcs
                              from rc in rcs.DefaultIfEmpty()
                              where q.id == relateID1
                              select
                              new
                              {
                                  relateCenter = rc.center
                              };
                var record = records.FirstOrDefault();
                relateCenter = record.relateCenter;
            }
            else
            {
                var records = from q in this._db.recsys_maintenance
                              join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id into rcs
                              from rc in rcs.DefaultIfEmpty()
                              where q.id == relateID1
                              select
                              new
                              {
                                  relateCenter = rc.center
                              };
                var record = records.FirstOrDefault();
                relateCenter = record.relateCenter;
            }

            int relateID;

            if (int.TryParse(relateIDString, out relateID))
            {
                string[] isValidRecords = elements.GetValues("hfValid");
                string[] supplierSubConIDs = elements.GetValues("hfSupplierSubContractorID");
                string[] supplierSubConRoles = elements.GetValues("hfSupplierSubContractorRole");
                string[] workerIDs = elements.GetValues("hfWorkerID");
                //string[] centerNames = elements.GetValues("cbCenter");
                string[] categoryIDs = elements.GetValues("hfCategoryID");
                string[] invoiceDates = elements.GetValues("tbBillingDate");
                string[] prices = elements.GetValues("tbPrice");
                string[] invoiceNumbers = elements.GetValues("tbInvoice");
                string[] remarks = elements.GetValues("tbRemark");

                int itemsCount = isValidRecords.Count();

                for (int i = 0; i < itemsCount; i++)
                {
                    recsys_costs cost = new recsys_costs()
                    {
                        account_date = null,
                        center = "",
                        cost_id = null,
                        invoice = "",
                        last_update = DateTime.Now,
                        remark = "",
                        status = 0,
                        supplier_id = null,
                        update_user_id = 0,
                        user_id = null,
                        price1 = null,
                        price2 = null
                    };
                    //DateTime invoiceDate;
                    int categoryID;
                    double price;
                    int supplierID;
                    int subConID;
                    int workerID;
                    bool isValid;
                    Member member = new Member("users");

                    if (!string.IsNullOrEmpty(invoiceDates[i]))
                        cost.account_date = DateTime.ParseExact(invoiceDates[i], "dd-MM-yyyy", null);
                    /*if (DateTime.TryParse(invoiceDates[i], out invoiceDate))
                        cost.account_date = invoiceDate;*/
                        cost.center = relateCenter;
                    if (int.TryParse(categoryIDs[i], out categoryID))
                        cost.cost_id = categoryID;
                    cost.invoice = invoiceNumbers[i];
                    if (double.TryParse(prices[i], out price))
                        cost.price1 = price;
                    cost.remark = remarks[i];
                    if (bool.TryParse(isValidRecords[i], out isValid))
                    {
                        if (isValid)
                            cost.status = (int)RecordStatus.Active;
                        else
                            cost.status = (int)RecordStatus.InActive;
                    }
                    if (supplierSubConRoles[i] == ((int)SupplierSubConType.Supplier).ToString())
                    {
                        if (int.TryParse(supplierSubConIDs[i], out supplierID))
                            cost.supplier_id = supplierID;
                    }
                    else if (supplierSubConRoles[i] == ((int)SupplierSubConType.SubContractor).ToString())
                    {
                        if (int.TryParse(supplierSubConIDs[i], out subConID))
                            cost.user_id = subConID;
                    }
                    if (int.TryParse(workerIDs[i], out workerID))
                        cost.user_id = workerID;
                    cost.update_user_id = (int)member.infoBySession("id");

                    if (cost.user_id > 0 || cost.supplier_id > 0 || cost.cost_id > 0)
                        insertItems.Add(i, cost);
                }

                //# Validation
                foreach (KeyValuePair<int, recsys_costs> kvp in insertItems)
                {
                    if (!kvp.Value.cost_id.HasValue)
                        validationControlSelectors.Add("#cost_custom_insert_form .tbCategory:eq(" + kvp.Key + ")");
                }
                if (validationControlSelectors.Count > 0)
                {
                    return Json(new
                    {
                        bIsSuccess = false,
                        exception = new ValidationException("無效的Category", validationControlSelectors.ToArray())
                    });
                }

                if (insertItems.Count > 0)
                {
                    List<recsys_costs> items = new List<recsys_costs>();

                    foreach (KeyValuePair<int, recsys_costs> kvp in insertItems)
                    {
                        items.Add(kvp.Value);
                        this._db.recsys_costs.AddObject(kvp.Value);
                    }

                    try
                    {
                        int number = this._db.SaveChanges();

                        this._db.Refresh(RefreshMode.StoreWins, items);

                        foreach (recsys_costs item in items)
                        {
                            recsys_relate relation = new recsys_relate();
                            relation.table1 = "costs";
                            relation.table2 = relateTableString;
                            relation.id1 = item.id;
                            relation.id2 = relateID;

                            this._db.recsys_relate.AddObject(relation);
                        }

                        this._db.SaveChanges();

                        isSuccess = true;

                    }
                    catch (OptimisticConcurrencyException)
                    {
                        //# log down
                    }
                }

            }

            return Json(new
            {
                bIsSuccess = isSuccess
            });
        }
        private bool TryGenerateOrdersForMaintenance(recsys_maintenance maintenance, recsys_routine routine, out IEnumerable<recsys_order> generatedOrders)
        {
            recsys_relate_customers masterCustomerData;
            Member member;
            List<recsys_relate_customers> customerDatas;
            List<recsys_order> orders;
            DateTime? startCalculationDate = null;
            DateTime? endCalculationDate = null;
            HolidaysController holidayController;
            List<DateTime> holidays;
            IEnumerable<DateTime> orderRepairDates;
            bool isSuccessful = false;

            generatedOrders = new List<recsys_order>();

            //# validation
            if (routine == null)
                return false;
            if (maintenance == null)
                return true;
            if (!routine.repair_date_frequency_in_month.HasValue)
                return true;
            if (!maintenance.start_date.HasValue && !maintenance.confirm_date.HasValue)
                return true;        //# start date of the calculation is counting on either the start date or confirm date; if null is given, just return true to indicate no order is generated
            if (!maintenance.end_date.HasValue)
                return true;        //# if maintenace does not have an end date, do not do anything

            //startCalculationDate = maintenance.confirm_date.HasValue ? maintenance.confirm_date.Value : maintenance.start_date;
            startCalculationDate = maintenance.start_date;
            endCalculationDate = maintenance.end_date;

            holidayController = new HolidaysController();
            holidays = holidayController.GetHolidays(startCalculationDate.Value, endCalculationDate.Value, true);

            orderRepairDates = maintenance.GetOrderRepairDatesByRoutine(routine, holidays);

            //# get old master customer record
            var _masterCustomerData = from m in this._db.recsys_maintenance
                                      join cd in this._db.recsys_relate_customers on m.customer_id equals cd.id into cds
                                      from cd in cds.DefaultIfEmpty()
                                      where m.id == maintenance.id
                                      select new
                                      {
                                          cd
                                      };
            masterCustomerData = _masterCustomerData.Select(theRecord => theRecord.cd).FirstOrDefault();

            //# validation
            if (masterCustomerData == null)
                throw new RecordNotFoundException();

            member = new Member("users");
            customerDatas = new List<recsys_relate_customers>();

            //# customer data
            for (int i = 0; i < orderRepairDates.Count(); i++)
            {
                //# mapping
                recsys_relate_customers customerData = new recsys_relate_customers()
                {
                    address1 = masterCustomerData.address1,
                    address2 = masterCustomerData.address2,
                    center = masterCustomerData.center,
                    code = masterCustomerData.code,
                    contact = masterCustomerData.contact,
                    customer_code = masterCustomerData.customer_code,
                    customer_id = masterCustomerData.customer_id,
                    district1 = masterCustomerData.district1,
                    district2 = masterCustomerData.district2,
                    email = masterCustomerData.email,
                    fax1 = masterCustomerData.fax1,
                    fax2 = masterCustomerData.fax2,
                    group_id = masterCustomerData.group_id,
                    manual_input_code = masterCustomerData.manual_input_code,
                    name = masterCustomerData.name,
                    chi_name = masterCustomerData.chi_name,
                    prefix = masterCustomerData.prefix,
                    relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation,
                    reference_number = masterCustomerData.reference_number,
                    remark = masterCustomerData.remark,
                    tel1 = masterCustomerData.tel1,
                    tel2 = masterCustomerData.tel2,
                    title = (byte)masterCustomerData.title,
                    type = (byte)masterCustomerData.type
                };

                customerDatas.Add(customerData);

                this._db.recsys_relate_customers.AddObject(customerData);
            }

            try
            {
                this._db.SaveChanges();

                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, customerDatas);

                orders = new List<recsys_order>();

                for (int j = 0; j < customerDatas.Count; j++)
                {
                    recsys_relate_customers theCustomerData = customerDatas[j];

                    recsys_order order = new recsys_order()
                    {
                        by_system = 1,
                        create_date = DateTime.Now,
                        model = maintenance.model,
                        repair_date = orderRepairDates.ElementAt(j),
                        customer_id = theCustomerData.id,
                        fault = "[" + OrderStatus.AppointedWarranty.Name + "]",            //# logic
                        last_update = DateTime.Now,
                        status = (byte) RecordStatus.Active,
                        update_user_id = (int)member.infoBySession("id"),
                        start_time = null,
                        end_time = null,
                        order_status = OrderStatus.AppointedWarranty.ID,
                        call_pickup_user_id = (int) member.infoBySession("id")
                    };

                    orders.Add(order);

                    this._db.recsys_order.AddObject(order);
                }

                this._db.SaveChanges();

                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, orders);

                foreach (recsys_order theOrder in orders)
                {
                    recsys_relate relation = new recsys_relate()
                    {
                        id1 = maintenance.id,
                        id2 = theOrder.id,
                        table1 = "maintenance",
                        table2 = "order"
                    };

                    this._db.recsys_relate.AddObject(relation);
                }

                this._db.SaveChanges();

                generatedOrders = orders;

                isSuccessful = true;

            }
            catch(OptimisticConcurrencyException)
            {
                //# log down
            }

            return isSuccessful;
        }
        public JsonResult BatchInsertProcess(FormCollection elements)
        {
            List<recsys_quotation_items> items = new List<recsys_quotation_items>();

            string quotationIDString = elements["hfQuotationID"];
            int quotationID;
            int maxItemSequence = 0;

            if (int.TryParse(quotationIDString, out quotationID))
            {

                try
                {
                    IEnumerable<int?> itemsSequences = from i in this._db.recsys_quotation_items
                                                       join r in this._db.recsys_relate on i.id equals r.id2
                                                       where r.id1 == quotationID && r.table1 == "quotation" && r.table2 == "quotation_items"
                                                       select i.nSequence;
                    maxItemSequence = itemsSequences.Where(theSequence => theSequence.HasValue).Max().Value;
                }
                catch
                {
                    //# log down
                }

                try
                {
                    IEnumerable<string> itemsCodes = from i in this._db.recsys_quotation_items
                                                     join r in this._db.recsys_relate on i.id equals r.id2
                                                     where r.id1 == quotationID && r.table1 == "quotation" && r.table2 == "quotation_items"
                                                     select i.code;

                    if (maxItemSequence >= 0)
                    {
                        string[] codes = elements.GetValues("tbCode");
                        foreach (string code in itemsCodes)
                        {
                            for (int i = 0; i < codes.Length; i++)
                            {
                                if (!string.IsNullOrEmpty(codes[i]) && !string.IsNullOrEmpty(codes[i].Trim()) && codes[i].Trim().ToUpper() == code.Trim().ToUpper())
                                {
                                    string message = "已有Quotation item (" + codes[i] + ")";
                                    return Json(new
                                    {
                                        bIsSuccess = false,
                                        warningMessage = message
                                    });
                                }
                            }
                        }
                        string[] details = elements.GetValues("tbDetails");
                        string[] details2 = elements.GetValues("tbDetails2");
                        string[] prices = elements.GetValues("tbPrice");

                        int itemsCount = codes.Count();
                        int sequenceCumulation = maxItemSequence;

                        for (int i = 0; i < itemsCount; i++)
                        {
                            recsys_quotation_items item = new recsys_quotation_items();
                            double price = 0;
                            Member _member = new Member("users");
                            if (!string.IsNullOrEmpty(codes[i]))
                                item.code = codes[i].Trim();
                            else
                                item.code = "";
                            item.detail = details[i];
                            item.detail2 = details2[i];
                            if (string.IsNullOrEmpty(prices[i]))
                            {
                                item.price = 0.00;
                            }
                            else
                            {
                                double.TryParse(prices[i], out price);
                                item.price = price;
                            }
                            item.last_update = DateTime.Now;
                            item.update_user_id = (int)_member.infoBySession("id");

                            if (!string.IsNullOrEmpty(item.detail) ||
                                !string.IsNullOrEmpty(item.detail2) ||
                                !string.IsNullOrEmpty(item.code))
                            {
                                item.nSequence = ++sequenceCumulation;
                                items.Add(item);
                                this._db.recsys_quotation_items.AddObject(item);
                            }

                        }

                        try
                        {
                            int number = this._db.SaveChanges();

                            this._db.Refresh(RefreshMode.StoreWins, items);

                            foreach (recsys_quotation_items item in items)
                            {
                                recsys_relate relation = new recsys_relate();
                                relation.table1 = "quotation";
                                relation.table2 = "quotation_items";
                                relation.id1 = quotationID;
                                relation.id2 = item.id;

                                this._db.recsys_relate.AddObject(relation);

                            }

                            this._db.SaveChanges();

                        }
                        catch (OptimisticConcurrencyException)
                        {
                            //# log down
                        }

                    }
                }
                catch
                {
                    //# log down
                }

            }

            return Json(new
            {
                bIsSuccess = true
            });
        }
        public ActionResult CopyFromPackageSave(CopyFromPackageModel model)
        {
            bool isSuccess = true;
            string errorType = string.Empty;
            try
            {
                if (model.quotationPackageID.HasValue)
                {
                    IEnumerable<recsys_quotation_package_items> quotationPackageItems = (from qpi in this._db.recsys_quotation_package_items
                                                                                         where qpi.quotation_package_id == model.quotationPackageID && qpi.status == 1
                                                                                         orderby qpi.nSequence
                                                                                         select qpi).ToList();
                    if (quotationPackageItems != null && quotationPackageItems.Count() > 0)
                    {
                        int? lastSequence = (from r in this._db.recsys_relate
                                            join qi in this._db.recsys_quotation_items on r.id2 equals qi.id
                                            where r.table1 == "quotation" && r.table2 == "quotation_items" && r.id1 == model.quotationID
                                            orderby qi.nSequence descending
                                            select qi.nSequence).FirstOrDefault();

                        int currentSequence = lastSequence.HasValue ? lastSequence.Value + 1 : 1;
                        Member _member = new Member("users");
                        int? userID = (int?)_member.infoBySession("id");
                        foreach (recsys_quotation_package_items quotationPackageItem in quotationPackageItems)
                        {
                            #region Create Quotation Item
                            recsys_quotation_items quotationItem = new recsys_quotation_items
                            {
                                code = quotationPackageItem.code,
                                detail = quotationPackageItem.detail_chi,
                                detail2 = quotationPackageItem.detail_eng,
                                nSequence = currentSequence,
                                price = quotationPackageItem.price,
                                last_update = DateTime.Now,
                                update_user_id = userID
                            };

                            this._db.recsys_quotation_items.AddObject(quotationItem);
                            this._db.SaveChanges(); //for getting quotation item id
                            #endregion Create Quotation Item

                            #region Create Relate Record
                            recsys_relate relate = new recsys_relate
                            {
                                table1 = "quotation",
                                table2 = "quotation_items",
                                id1 = model.quotationID,
                                id2 = quotationItem.id
                            };

                            this._db.recsys_relate.AddObject(relate);
                            this._db.SaveChanges();
                            #endregion Create Relate Record

                            currentSequence++;
                        }
                    }
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return Json(new { isSuccess = isSuccess, errorType = errorType });
        }
Пример #10
0
 /// <summary>
 /// Create a new recsys_relate object.
 /// </summary>
 /// <param name="id1">Initial value of the id1 property.</param>
 /// <param name="id2">Initial value of the id2 property.</param>
 /// <param name="table1">Initial value of the table1 property.</param>
 /// <param name="table2">Initial value of the table2 property.</param>
 public static recsys_relate Createrecsys_relate(global::System.Int32 id1, global::System.Int32 id2, global::System.String table1, global::System.String table2)
 {
     recsys_relate recsys_relate = new recsys_relate();
     recsys_relate.id1 = id1;
     recsys_relate.id2 = id2;
     recsys_relate.table1 = table1;
     recsys_relate.table2 = table2;
     return recsys_relate;
 }
Пример #11
0
 /// <summary>
 /// Deprecated Method for adding a new object to the recsys_relate EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTorecsys_relate(recsys_relate recsys_relate)
 {
     base.AddObject("recsys_relate", recsys_relate);
 }