public static recsys_quotation_package_items CopyQuotationPackageItem(recsys_quotation_package_items target)
        {
            recsys_quotation_package_items result = new recsys_quotation_package_items();
            Member _member = new Member("users");

            if (target != null)
            {
                result.code = target.code;
                result.detail_chi = target.detail_chi;
                result.detail_eng = target.detail_eng;
                result.id = 0;
                result.update_date = System.DateTime.Now;
                result.nSequence = target.nSequence;
                result.price = target.price;
                result.update_by = (int)_member.infoBySession("id");
                result.create_date = System.DateTime.Now;
                result.create_by = (int)_member.infoBySession("id");
                result.status = 1;
            }
            return result;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new recsys_quotation_package_items object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="quotation_package_id">Initial value of the quotation_package_id property.</param>
 /// <param name="code">Initial value of the code property.</param>
 /// <param name="create_date">Initial value of the create_date property.</param>
 /// <param name="create_by">Initial value of the create_by property.</param>
 /// <param name="status">Initial value of the status property.</param>
 public static recsys_quotation_package_items Createrecsys_quotation_package_items(global::System.Int32 id, global::System.Int32 quotation_package_id, global::System.String code, global::System.DateTime create_date, global::System.Int32 create_by, global::System.Byte status)
 {
     recsys_quotation_package_items recsys_quotation_package_items = new recsys_quotation_package_items();
     recsys_quotation_package_items.id = id;
     recsys_quotation_package_items.quotation_package_id = quotation_package_id;
     recsys_quotation_package_items.code = code;
     recsys_quotation_package_items.create_date = create_date;
     recsys_quotation_package_items.create_by = create_by;
     recsys_quotation_package_items.status = status;
     return recsys_quotation_package_items;
 }
        public JsonResult BatchInsertProcess(FormCollection elements)
        {
            bool isSuccess = false;
            double? total = 0.0;
            List<recsys_quotation_package_items> items = new List<recsys_quotation_package_items>();

            string quotationPackageIDString = elements["hfQuotationPackageID"];
            int quotationPackageID;
            int maxItemSequence = 0;

            if (int.TryParse(quotationPackageIDString, out quotationPackageID))
            {

                try
                {
                    IEnumerable<int?> itemsSequences = from qpi in this._db.recsys_quotation_package_items
                                                       where qpi.quotation_package_id == quotationPackageID && qpi.status == 1
                                                       select qpi.nSequence;
                    maxItemSequence = itemsSequences.Where(theSequence => theSequence.HasValue).Max().Value;
                }
                catch
                {
                    //# log down
                }

                try
                {
                    IEnumerable<string> itemsCodes = from qpi in this._db.recsys_quotation_package_items
                                                     where qpi.quotation_package_id == quotationPackageID && qpi.status == 1
                                                     select qpi.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 Package item (" + codes[i] + ")";
                                    return Json(new
                                    {
                                        bIsSuccess = false,
                                        warningMessage = message
                                    });
                                }
                            }
                        }
                        string[] details_chi = elements.GetValues("tbDetails_chi");
                        string[] details_eng = elements.GetValues("tbDetails_eng");
                        string[] prices = elements.GetValues("tbPrice");

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

                        for (int i = 0; i < itemsCount; i++)
                        {
                            recsys_quotation_package_items item = new recsys_quotation_package_items();
                            double price = 0;
                            Member _member = new Member("users");
                            if (!string.IsNullOrEmpty(codes[i]))
                                item.code = codes[i].Trim();
                            else
                                item.code = "";
                            item.detail_chi = details_chi[i];
                            item.detail_eng = details_eng[i];
                            if (string.IsNullOrEmpty(prices[i]))
                            {
                                item.price = 0.00;
                            }
                            else
                            {
                                double.TryParse(prices[i], out price);
                                item.price = price;
                            }
                            item.status = 1;
                            item.create_date = DateTime.Now;
                            item.create_by = (int)_member.infoBySession("id");
                            item.update_date = DateTime.Now;
                            item.update_by = (int)_member.infoBySession("id");

                            if (!string.IsNullOrEmpty(item.detail_chi) ||
                                !string.IsNullOrEmpty(item.detail_eng) ||
                                !string.IsNullOrEmpty(item.code))
                            {
                                item.nSequence = ++sequenceCumulation;

                                item.quotation_package_id = quotationPackageID;
                                this._db.recsys_quotation_package_items.AddObject(item);

                                try
                                {
                                    this._db.SaveChanges();
                                    isSuccess = true;
                                }
                                catch (OptimisticConcurrencyException)
                                {
                                    //# log down
                                }
                            }
                        }
                        //update quotation package total price
                        total = (from qpi in this._db.recsys_quotation_package_items
                                         where qpi.quotation_package_id == quotationPackageID && qpi.status == 1
                                         select qpi.price).Sum();

                        recsys_quotation_packages quotationPackage = this._db.recsys_quotation_packages.FirstOrDefault(qp => qp.id == quotationPackageID);
                        quotationPackage.price = total!=null?total:0.0;

                        try
                        {
                            this._db.SaveChanges();
                            isSuccess = true;
                        }
                        catch (OptimisticConcurrencyException)
                        {
                            //# log down
                        }
                    }
                }
                catch
                {
                    //# log down
                }

            }

            return Json(new
            {
                total = total,
                isSuccess = isSuccess
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the recsys_quotation_package_items EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTorecsys_quotation_package_items(recsys_quotation_package_items recsys_quotation_package_items)
 {
     base.AddObject("recsys_quotation_package_items", recsys_quotation_package_items);
 }