コード例 #1
0
        public static recsys_quotation_items CopyQuotationItem(recsys_quotation_items target)
        {
            recsys_quotation_items result = new recsys_quotation_items();

            if (target != null)
            {
                result.code = target.code;
                result.detail = target.detail;
                result.detail2 = target.detail2;
                result.id = 0;
                result.last_update = target.last_update;
                result.nSequence = target.nSequence;
                result.price = target.price;
                result.update_user_id = target.update_user_id;

            }

            return result;
        }
コード例 #2
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
                });
        }
コード例 #3
0
        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
            });
        }
コード例 #4
0
        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 });
        }
コード例 #5
0
ファイル: db.Designer.cs プロジェクト: ferrywlto/Rec-System
 /// <summary>
 /// Create a new recsys_quotation_items object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="code">Initial value of the code property.</param>
 public static recsys_quotation_items Createrecsys_quotation_items(global::System.Int32 id, global::System.String code)
 {
     recsys_quotation_items recsys_quotation_items = new recsys_quotation_items();
     recsys_quotation_items.id = id;
     recsys_quotation_items.code = code;
     return recsys_quotation_items;
 }
コード例 #6
0
ファイル: db.Designer.cs プロジェクト: ferrywlto/Rec-System
 /// <summary>
 /// Deprecated Method for adding a new object to the recsys_quotation_items EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTorecsys_quotation_items(recsys_quotation_items recsys_quotation_items)
 {
     base.AddObject("recsys_quotation_items", recsys_quotation_items);
 }