public ResultDatabase_Model InsertDatabase(string text, int indicator, string fileName)
        {
            ResultDatabase_Model result = new ResultDatabase_Model();
            Response_ReadFile    error  = new Response_ReadFile();
            bool check = false;

            if (indicator == 1)
            {
                MM_PO_Header poHeader = new MM_PO_Header();
                try
                {
                    poHeader.Table_Indicator    = DAL.IntReturn(text.Substring(0, 1));
                    poHeader.Lsp_Identification = text.Substring(1, 4);

                    string orderNumber = text.Substring(5, 20);
                    poHeader.Order_Number = orderNumber.Substring(3, 17);

                    poHeader.Order_Type = text.Substring(25, 4);

                    string supplier = text.Substring(29, 10);
                    poHeader.Supplier_Number = supplier.Substring(4, 6);

                    string deliveryDate = text.Substring(39, 8);
                    int    year         = DAL.IntReturn(deliveryDate.Substring(0, 4));
                    int    month        = DAL.IntReturn(deliveryDate.Substring(4, 2));
                    int    day          = DAL.IntReturn(deliveryDate.Substring(6, 2));
                    poHeader.Plan_Delivery_Date = new DateTime(year, month, day);

                    string warehouse = text.Substring(47, 20);
                    poHeader.Warehouse_Number = warehouse.Substring(15, 5);

                    string email = text.Substring(67, 20);
                    poHeader.MM_Email_Number = email.Substring(0, 5);

                    poHeader.Memo_Field = text.Substring(87, 255);

                    string dateRecord = text.Substring(342, 8);
                    int    year1      = DAL.IntReturn(dateRecord.Substring(0, 4));
                    int    month1     = DAL.IntReturn(dateRecord.Substring(4, 2));
                    int    day1       = DAL.IntReturn(dateRecord.Substring(6, 2));
                    poHeader.Date_Record = new DateTime(year1, month1, day1);

                    poHeader.Action_Type = text.Substring(350, 1);

                    string commercialSupplier = text.Substring(351, 10);
                    poHeader.Commercial_Supplier_Number = commercialSupplier.Substring(4, 6);

                    string orderDate = text.Substring(361, 8);
                    int    year3     = DAL.IntReturn(orderDate.Substring(0, 4));
                    int    month3    = DAL.IntReturn(orderDate.Substring(4, 2));
                    int    day3      = DAL.IntReturn(orderDate.Substring(6, 2));
                    poHeader.Order_Date = new DateTime(year3, month3, day3);

                    poHeader.Free_Text1 = text.Substring(369, 20);
                    poHeader.Free_Text2 = text.Substring(389, 20);
                    poHeader.FILENAME   = fileName;

                    string    sql   = string.Format("select * from MM_PO_HEADER where Order_Number = '{0}'", poHeader.Order_Number);
                    DataTable dt    = DAL.SELECT_SQL(sql);
                    int       count = DAL.IntReturn(dt.Rows.Count);

                    if (count == 0)
                    {
                        poHeader.ADDDATE  = DateTime.Now;
                        poHeader.EDITDATE = DateTime.Now;
                        check             = poHeader.Add(fileName, text);
                        result.result(check, poHeader.Action_Type, poHeader.Order_Number);
                    }
                    else
                    {
                        poHeader.EDITDATE = DateTime.Now;
                        check             = poHeader.Update(fileName, text);
                        result.result(check, poHeader.Action_Type, poHeader.Order_Number);
                    }
                }
                catch (Exception e)
                {
                    string Category = "poHeader";
                    error.HandleError(fileName, text, e.Message.ToString(), Category);
                    check = false;
                    result.result(check, poHeader.Action_Type, poHeader.Order_Number);
                }
            }
            else if (indicator == 2)
            {
                MM_PO_Detail poDetail = new MM_PO_Detail();
                try
                {
                    poDetail.Table_Indicator    = DAL.IntReturn(text.Substring(0, 1));
                    poDetail.Lsp_Identification = text.Substring(1, 4);

                    string orderNumber = text.Substring(5, 20);
                    poDetail.Order_Number = orderNumber.Substring(3, 17);

                    string sku = text.Substring(81, 10);
                    poDetail.Article_Number = sku.Substring(2, 8);

                    int qty = DAL.IntReturn(text.Substring(91, 10));
                    poDetail.Order_Quantity = DAL.DecimalReturn(DAL.ChangeValue(3, qty));

                    string dateRecord = text.Substring(101, 8);
                    int    year       = DAL.IntReturn(dateRecord.Substring(0, 4));
                    int    month      = DAL.IntReturn(dateRecord.Substring(4, 2));
                    int    day        = DAL.IntReturn(dateRecord.Substring(6, 2));
                    poDetail.Date_Record = new DateTime(year, month, day);

                    poDetail.Action_Type = text.Substring(109, 1);
                    string warehouse = text.Substring(110, 20);
                    poDetail.Warehouse_Number = warehouse.Substring(15, 5);
                    poDetail.Orderline        = text.Substring(130, 20);
                    string email = text.Substring(150, 20);
                    poDetail.MM_Email_Number = email.Substring(0, 5);

                    poDetail.FILENAME = fileName;
                    string    sql = string.Format("select * from MM_PO_DETAIL where Order_Number = '{0}' and Article_Number= '{1}'", poDetail.Order_Number, poDetail.Article_Number);
                    DataTable supplierHeaderTable = DAL.SELECT_SQL(sql);
                    int       count = DAL.IntReturn(supplierHeaderTable.Rows.Count);

                    if (count == 0)
                    {
                        poDetail.ADDDATE  = DateTime.Now;
                        poDetail.EDITDATE = DateTime.Now;
                        check             = poDetail.Add(fileName, text);
                        result.result(check, poDetail.Action_Type, poDetail.Order_Number);
                    }
                    else
                    {
                        poDetail.EDITDATE = DateTime.Now;
                        check             = poDetail.Update(fileName, text);
                        result.result(check, poDetail.Action_Type, poDetail.Order_Number);
                    }
                }
                catch (Exception e)
                {
                    string Category = "poDetail";
                    error.HandleError(fileName, text, e.Message.ToString(), Category);
                    check = false;
                    result.result(check, poDetail.Action_Type, poDetail.Order_Number);
                }
            }
            else if (indicator == 3)
            {
                MM_PO_Detail_XD poDetailXd = new MM_PO_Detail_XD();
                try
                {
                    poDetailXd.Table_Indicator    = DAL.IntReturn(text.Substring(0, 1));
                    poDetailXd.Lsp_Identification = text.Substring(1, 4);

                    string orderNumber = text.Substring(5, 20);
                    poDetailXd.Order_Number = orderNumber.Substring(3, 17);

                    string sku = text.Substring(63, 10);
                    poDetailXd.Article_Number = sku.Substring(2, 8);

                    string storeNumber = text.Substring(73, 10);
                    poDetailXd.Store_Number = storeNumber.Substring(5, 5);

                    int qty = DAL.IntReturn(text.Substring(83, 10));
                    poDetailXd.Order_Quantity = DAL.DecimalReturn(DAL.ChangeValue(3, qty));

                    string warehouse = text.Substring(93, 20);
                    poDetailXd.Warehouse_Number = warehouse.Substring(15, 5);

                    string saleOrder = text.Substring(121, 20);
                    poDetailXd.Sale_Order = saleOrder.Substring(3, 17);


                    string mail = text.Substring(141, 20);
                    poDetailXd.Metro_Mail = mail.Substring(0, 5);

                    string articleNumber = text.Substring(161, 10);
                    poDetailXd.Buying_Article_Number = articleNumber.Substring(0, 7);

                    poDetailXd.FILENAME = fileName;
                    string    sql = string.Format("select * from MM_PO_DETAIL_XD where Order_Number = '{0}' and Sale_Order='{1}' and Article_Number='{2}'", poDetailXd.Order_Number, poDetailXd.Sale_Order, poDetailXd.Article_Number);
                    DataTable supplierHeaderTable = DAL.SELECT_SQL(sql);
                    int       count = DAL.IntReturn(supplierHeaderTable.Rows.Count);

                    if (count == 0)
                    {
                        poDetailXd.ADDDATE  = DateTime.Now;
                        poDetailXd.EDITDATE = DateTime.Now;
                        check = poDetailXd.Add(fileName, text);
                        result.result(check, "", poDetailXd.Order_Number);
                    }
                    else
                    {
                        poDetailXd.EDITDATE = DateTime.Now;
                        check = poDetailXd.Update(fileName, text);
                        result.result(check, "", poDetailXd.Order_Number);
                    }
                }
                catch (Exception e)
                {
                    string Category = "poDetailXd";
                    error.HandleError(fileName, text, e.Message.ToString(), Category);
                    check = false;
                    result.result(check, "", poDetailXd.Order_Number);
                }
            }
            return(result);
        }
Exemple #2
0
        public ResultDatabase_Model InsertDatabase(string text, int indicator, string fileName)
        {
            bool check = false;
            ResultDatabase_Model result = new ResultDatabase_Model();
            Response_ReadFile    error  = new Response_ReadFile();

            if (indicator == 3)
            {
                Articles_Model article = new Articles_Model();
                try
                {
                    article.Table_Indicator = DAL.IntReturn(text.Substring(0, 1));
                    article.Action_Code     = text.Substring(1, 1);

                    article.Lsp_Identification = text.Substring(2, 4);

                    string sku = text.Substring(6, 20);
                    article.Article_Number = sku.Substring(12, 8);

                    string shipFrom = text.Substring(26, 20);
                    article.Supplier_Code = shipFrom.Substring(14, 6);

                    int buyingUnit = DAL.IntReturn(text.Substring(58, 7));
                    article.Buying_Unit = DAL.DecimalReturn(DAL.ChangeValue(3, buyingUnit));

                    article.Selling_Unit = DAL.IntReturn(text.Substring(65, 4));

                    string orderUnit = text.Substring(69, 4);
                    article.Ordering_Unit = orderUnit.Substring(1, 3);


                    article.Article_Type   = DAL.IntReturn(text.Substring(73, 1));
                    article.Article_Status = DAL.IntReturn(text.Substring(75, 1));
                    article.Buyer_User_Id  = text.Substring(93, 6);
                    article.Desc_Article   = text.Substring(99, 33).Replace("'", "\"");
                    article.Packing_Type   = text.Substring(132, 2);


                    article.Article_Related = DAL.IntReturn(text.Substring(134, 20));


                    article.EAN_Code = text.Substring(154, 14);

                    string supplierArticle = text.Substring(168, 14);
                    article.Supplier_Article_Number = supplierArticle.Substring(0, 8);


                    article.Article_Desc     = text.Substring(182, 33);
                    article.Number_Mu_Carton = DAL.IntReturn(text.Substring(215, 6));
                    article.Number_Mu_Layer  = DAL.IntReturn(text.Substring(221, 6));
                    article.Number_Mu_Pallet = DAL.IntReturn(text.Substring(227, 6));

                    int cartonLength = DAL.IntReturn(text.Substring(233, 8));
                    article.Carton_Length = DAL.DecimalReturn(DAL.ChangeValue(2, cartonLength));

                    int cartonGrossweight = DAL.IntReturn(text.Substring(241, 9));
                    article.Carton_GrossWeight = DAL.DecimalReturn(DAL.ChangeValue(2, cartonGrossweight));

                    int cartonNetweight = DAL.IntReturn(text.Substring(250, 9));
                    article.Carton_NetWeight = DAL.DecimalReturn(DAL.ChangeValue(2, cartonNetweight));


                    article.Warehouse_Number = text.Substring(259, 5);

                    string dateRecord = text.Substring(264, 8);
                    int    year       = DAL.IntReturn(dateRecord.Substring(0, 4));
                    int    month      = DAL.IntReturn(dateRecord.Substring(4, 2));
                    int    day        = DAL.IntReturn(dateRecord.Substring(6, 2));
                    article.Date_Record             = new DateTime(year, month, day);
                    article.Logistic_Deposit_Type   = DAL.IntReturn(text.Substring(272, 1));
                    article.Logistic_Flow_Indicator = DAL.IntReturn(text.Substring(273, 2));
                    article.Ordering_Indicator      = DAL.IntReturn(text.Substring(275, 1));

                    article.Link_Logistic_Deposit = DAL.IntReturn(text.Substring(276, 20));

                    article.Expiry_Days = DAL.IntReturn(text.Substring(296, 3));
                    article.Expiry_Days_Checking_Indicator = DAL.IntReturn(text.Substring(299, 1));
                    article.Minimum_Expiry_Days            = DAL.IntReturn(text.Substring(300, 5));
                    article.Pallet_Indicator    = DAL.IntReturn(text.Substring(305, 1));
                    article.Number_Layer_Pallet = DAL.IntReturn(text.Substring(306, 2));
                    article.Number_Units_Inbox  = DAL.IntReturn(text.Substring(308, 5));

                    int grossVolumSelling = DAL.IntReturn(text.Substring(314, 15));
                    article.Gross_Volume = DAL.DecimalReturn(DAL.ChangeValue(3, grossVolumSelling));

                    article.Measure_Unit_GrossVolume = text.Substring(329, 3);
                    article.Packing_Type             = text.Substring(332, 2);

                    int cartonWidth = DAL.IntReturn(text.Substring(334, 8));
                    article.Carton_Width = DAL.DecimalReturn(DAL.ChangeValue(2, cartonWidth));

                    int cartonHeight = DAL.IntReturn(text.Substring(342, 8));
                    article.Carton_Height = DAL.DecimalReturn(DAL.ChangeValue(2, cartonHeight));


                    article.UOM_Carton_Size   = text.Substring(350, 3);
                    article.UOM_Carton_Weight = text.Substring(353, 3);

                    int cartonGrossVolume = DAL.IntReturn(text.Substring(356, 15));
                    article.Carton_Gross_Volume = DAL.DecimalReturn(DAL.ChangeValue(3, cartonGrossVolume));


                    article.UOM_Carton_Volume   = text.Substring(371, 3);
                    article.Selling_Unit_Length = DAL.IntReturn(text.Substring(374, 6));
                    article.Selling_Unit_Width  = DAL.IntReturn(text.Substring(380, 6));
                    article.Selling_Unit_Height = DAL.IntReturn(text.Substring(386, 6));
                    article.UOM_Selling_Size    = text.Substring(392, 3);



                    int grossweightSelling = DAL.IntReturn(text.Substring(395, 9));
                    article.Grossweight_Selling = DAL.DecimalReturn(DAL.ChangeValue(2, grossweightSelling));


                    int netwweightSelling = DAL.IntReturn(text.Substring(404, 9));
                    article.Netweight_Selling = DAL.DecimalReturn(DAL.ChangeValue(2, netwweightSelling));



                    article.UOM_Selling_Weight     = text.Substring(413, 3);
                    article.Article_Group_Number   = DAL.IntReturn(text.Substring(416, 3));;
                    article.Artice_Subgroup_Number = DAL.IntReturn(text.Substring(419, 3));
                    article.Excise_Tax_Indicator   = DAL.IntReturn(text.Substring(422, 1));

                    int exciseTaxAmount = DAL.IntReturn(text.Substring(423, 15));
                    article.Excise_Tax_Amount = DAL.DecimalReturn(DAL.ChangeValue(3, exciseTaxAmount));


                    article.High_Value_Indicator     = DAL.IntReturn(text.Substring(438, 1));
                    article.Storage_Temperature_Desc = text.Substring(439, 25);
                    article.Remark   = text.Substring(464, 33);
                    article.FILENAME = fileName;

                    string    sql      = string.Format("select * from MM_Articles where Article_Number='{0}' and Warehouse_Number= '{1}' and Supplier_Code='{2}'", article.Article_Number, article.Warehouse_Number, article.Supplier_Code);
                    DataTable skuTable = DAL.SELECT_SQL(sql);
                    int       count    = DAL.IntReturn(skuTable.Rows.Count);

                    if (count > 0)
                    {
                        article.EditDate = DateTime.Now;

                        check = article.Update(fileName, text);
                        result.result(check, article.Article_Status.ToString(), article.Article_Number);
                    }
                    else if (count == 0)
                    {
                        article.EditDate = DateTime.Now;
                        article.AddDate  = DateTime.Now;
                        check            = article.Add(fileName, text);
                        result.result(check, article.Article_Status.ToString(), article.Article_Number);
                    }
                    else
                    {
                        check = false;
                        result.result(check, article.Article_Status.ToString(), article.Article_Number);
                    }
                }
                catch (Exception e)
                {
                    string category = "article";
                    error.HandleError(fileName, text, e.Message.ToString(), category);
                    check = false;
                    result.result(check, article.Article_Status.ToString(), article.Article_Number);
                }
            }
            else if (indicator == 4)
            {
                BarcodeArticles_Model barcodeArticle = new BarcodeArticles_Model();
                try
                {
                    barcodeArticle.Table_Indicator    = DAL.IntReturn(text.Substring(0, 1));
                    barcodeArticle.Action_Code        = text.Substring(1, 1);
                    barcodeArticle.Lsp_Identification = text.Substring(2, 4);

                    string sku = text.Substring(6, 20);
                    barcodeArticle.Article_Number = sku.Substring(12, 8);

                    string barcode = text.Substring(26, 20);
                    barcodeArticle.Barcode = barcode.Substring(0, 14);

                    barcodeArticle.Warehouse_Number = text.Substring(56, 5);

                    string dateRecord = text.Substring(61, 8);
                    int    year       = DAL.IntReturn(dateRecord.Substring(0, 4));
                    int    month      = DAL.IntReturn(dateRecord.Substring(4, 2));
                    int    day        = DAL.IntReturn(dateRecord.Substring(6, 2));
                    barcodeArticle.Date_Record = new DateTime(year, month, day);

                    barcodeArticle.Barcode_Sequence_Number = DAL.IntReturn(text.Substring(69, 3));
                    barcodeArticle.FILENAME = fileName;

                    string    sql         = string.Format("select * from MM_Barcode_Articles where Article_Number='{0}' and Barcode ='{1}' and Warehouse_Number= '{2}' ", barcodeArticle.Article_Number, barcodeArticle.Barcode, barcodeArticle.Warehouse_Number);
                    DataTable altSkuTable = DAL.SELECT_SQL(sql);
                    int       count       = DAL.IntReturn(altSkuTable.Rows.Count);
                    if (count > 0)
                    {
                        barcodeArticle.Editdate = DateTime.Now;
                        check = barcodeArticle.Update(fileName, text);
                        result.result(check, "U", barcodeArticle.Article_Number);
                    }
                    else
                    {
                        barcodeArticle.AddDate  = DateTime.Now;
                        barcodeArticle.Editdate = DateTime.Now;
                        check = barcodeArticle.Add(fileName, text);
                        result.result(check, "I", barcodeArticle.Article_Number);
                    }
                }
                catch (Exception e)
                {
                    string category = "barcodeArticle";
                    error.HandleError(fileName, text, e.Message.ToString(), category);
                    check = false;
                    result.result(check, "", barcodeArticle.Article_Number);
                }
            }
            return(result);
        }