Пример #1
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            string myStream;

            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = this.saveFileDialog1.FileName) != null)
                {
                    //save list
                    string sPath;
                    string sFilename;
                    int    iSeparator = myStream.LastIndexOf('\\');
                    sFilename = myStream.Substring(iSeparator + 1);
                    sPath     = myStream.Substring(0, iSeparator);
                    MFG.Files.CSV.CCsvWriter writer = new MFG.Files.CSV.CCsvWriter(sPath, sFilename);

                    foreach (DataGridViewRow dgvr in this.dataGridView1.Rows)
                    {
                        var aLine = new string[2];
                        aLine[0] = dgvr.Cells[0].Value.ToString();
                        aLine[1] = dgvr.Cells[1].Value.ToString();
                        writer.AddToFile(aLine);
                    }
                }
            }
        }
Пример #2
0
        //protected void AddSODetailLineWithTaxCode(DataRow dr, string sSONumber, string sLine)
        //{
        //    var conn = new jbConnection(this.M_DBNAME, this.M_DBSERVER);
        //    string sDifferentialQty;
        //    string sDifferentialDate;

        //    string taxCode = GetTaxCodeFromSO(sSONumber);

        //    string sMaterial = dr[0].ToString();
        //    string sPlant = dr[13].ToString();

        //    if (dr[22].ToString() != "")
        //    {
        //        this.M_CUSTOMER_ID = dr[22].ToString();
        //    }

        //    if (sPlant == "0")
        //    {
        //        MessageBox.Show("'Plant 0'...EDI essaie de crée une ligne alors qu'il devrait ne rien faire.");
        //    }

        //    if (dr[3] == DBNull.Value)
        //    {
        //        sDifferentialQty = dr[4].ToString();
        //    }
        //    else
        //    {
        //        sDifferentialQty = dr[3].ToString();
        //    }

        //    if (dr[10] == DBNull.Value)
        //    {
        //        sDifferentialDate = "0";
        //    }
        //    else
        //    {
        //        sDifferentialDate = dr[10].ToString();
        //    }

        //    var address = conn.GetData("SELECT Address FROM Address WHERE Customer LIKE '"
        //     + this.M_CUSTOMER_ID + "' AND Ship_To_ID LIKE '" + EscapeSQLString(dr[13].ToString()) + "'");

        //    try
        //    {
        //        if (address.Rows.Count < 1)
        //        {
        //            throw new MissingAddressFieldException("Le plant de livraison " + dr[13].ToString() +
        //             " n'existe pas dans votre base de données.");
        //        }
        //    }
        //    catch (MissingAddressFieldException e)
        //    {
        //        MessageBox.Show(e.Message);
        //        throw e;
        //    }

        //    var addressID = (address.Rows[0][0]).ToString();
        //    var dtInvCosting = conn.GetData("SELECT Inv_Cost_Method FROM Preferences");
        //    var sInvCostingMethod = dtInvCosting.Rows[0][0].ToString();

        //    string sQuery = "SELECT Material, Selling_Price, Price_UofM, Stocked_UofM, Cost_UofM, Sales_Code, Rev FROM Material WHERE Material LIKE '" + EscapeSQLString(sMaterial) + "'";


        //    var dtMaterialInfo = conn.GetData(sQuery);

        //    string sUnitPrice = dtMaterialInfo.Rows[0][1].ToString();
        //    string sPriceUofM = dtMaterialInfo.Rows[0][2].ToString();
        //    string sOrderQty = dr[4].ToString();
        //    string sStockUofM = dtMaterialInfo.Rows[0][3].ToString();
        //    string sCostUofM = dtMaterialInfo.Rows[0][4].ToString();
        //    object oSalesCode = dtMaterialInfo.Rows[0][5];
        //    object oRev;

        //    if (this.M_CUSTOMER_ID == "PRINOTH")
        //    {
        //        oRev = dr[15].ToString();
        //    }
        //    else
        //    {
        //        oRev = dtMaterialInfo.Rows[0][6];
        //    }

        //    var arPromisedDate = this.FormatJBDate(dr[9].ToString());
        //    string sPromisedDate = arPromisedDate[1] + "/"
        //    + arPromisedDate[0] + "/" + arPromisedDate[2];

        //    string sTotalPrice = (Convert.ToDouble(sUnitPrice) * Convert.ToDouble(sOrderQty)).ToString();

        //    string sStatus = this.M_SO_CREATION_STATUS;

        //    sQuery = "INSERT INTO SO_Detail (Sales_Order, SO_Line, Ship_To, Status, Make_Buy, Unit_Price, "
        //    + "Price_UofM, Total_Price, Order_Qty, Stock_UofM, Deferred_Qty, Promised_Date, Material, Cost_UofM ,"
        //    + "ObjectID, Unit_Cost, Shipped_Qty, Returned_Qty";

        //    if (oSalesCode != DBNull.Value)
        //    {
        //        sQuery += ", Sales_Code";
        //    }

        //    if (oRev != DBNull.Value)
        //    {
        //        sQuery += ", Rev";
        //    }

        //    if (!String.IsNullOrWhiteSpace(taxCode))
        //    {
        //        sQuery += ", Tax_Code";
        //    }

        //    sQuery += ") VALUES ('" + EscapeSQLString(sSONumber) + "', '" + EscapeSQLString(sLine) + "', " + EscapeSQLString(addressID) + ", '" + EscapeSQLString(sStatus) + "', 'M', " + EscapeSQLString(sUnitPrice)
        //    + ", '" + EscapeSQLString(sPriceUofM) + "', " + EscapeSQLString(sTotalPrice) + ", " + EscapeSQLString(sOrderQty) + ", '" + EscapeSQLString(sStockUofM) + "'"
        //    + ", " + EscapeSQLString(sOrderQty) + ", '" + EscapeSQLString(sPromisedDate) + "', '" + EscapeSQLString(sMaterial) + "', '" + EscapeSQLString(sCostUofM) + "', '" + EscapeSQLString(Guid.NewGuid().ToString()) + "', 0, 0, 0";

        //    if (oSalesCode != DBNull.Value)
        //    {
        //        sQuery += ", '" + EscapeSQLString(oSalesCode.ToString()) + "'";
        //    }

        //    if (oRev != DBNull.Value)
        //    {
        //        sQuery += ", '" + EscapeSQLString(oRev.ToString()) + "'";
        //    }

        //    if (!String.IsNullOrWhiteSpace(taxCode))
        //    {
        //        sQuery += ", '" + EscapeSQLString(taxCode) + "'";
        //    }

        //    sQuery += ")";

        //    conn.SetData(sQuery);

        //    var dtLatestSoDetail = conn.GetData("SELECT MAX(SO_Detail) FROM SO_Detail");

        //    sQuery = "INSERT INTO Delivery (SO_Detail, Requested_Date, Promised_Date, Promised_Quantity, Remaining_Quantity, ObjectID) "
        //    + "VALUES (" + EscapeSQLString(dtLatestSoDetail.Rows[0][0].ToString()) + ", '" + EscapeSQLString(sPromisedDate) + "', '" + EscapeSQLString(sPromisedDate) + "', "
        //    + EscapeSQLString(sOrderQty) + " , " + EscapeSQLString(sOrderQty) + ", '" + EscapeSQLString(Guid.NewGuid().ToString()) + "')";

        //    conn.SetData(sQuery);


        //    this.UpdateSOTotalPrice(sSONumber);
        //    this.AddToHistory(new string[] { sDifferentialQty, sDifferentialDate, sUnitPrice, sOrderQty });
        //}

        protected void AddToHistory(string[] arrValues)
        {
            string sDirPath       = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/EDI-History/";
            string sFileNameStart = "Rapport-" + DateTime.Now.ToShortDateString().Replace("/", "-");
            string sFileName      = "";


            if (!Directory.Exists(sDirPath))
            {
                Directory.CreateDirectory(sDirPath);
            }

            sFileName = "History.csv";

            var dumpWriter = new MFG.Files.CSV.CCsvWriter(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\EDI-History\\", sFileName);

            /*
             * 0 - Date of the Write
             *
             *
             *
             * 1 - Pull Qty,
             * 2 - Push Qty,
             * 3 - Diff Qty,
             *
             * 4 - Pull Qty Value,
             * 5 - Push Qty Vallue,
             * 6 - Diff Qty Value,
             *
             *
             *
             * 7 - Pull Days,
             * 8 - Push Days,
             * 9 - Diff Days,
             *
             * 10 - Pull Days Value,
             * 11 - Push Days Value,
             * 12 - Diff Days Value
             */

            var arrValuesToWrite = new string[13] {
                "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"
            };

            var dtToday = System.DateTime.Now;

            arrValuesToWrite[0] = dtToday.Year + "/" + dtToday.Month + "/" + dtToday.Day;

            if (System.Convert.ToInt32(arrValues[0]) > 0) //This is a quantity pull
            {
                arrValuesToWrite[1] = arrValues[0];
                arrValuesToWrite[3] = arrValues[0];

                arrValuesToWrite[4] = (System.Convert.ToInt32(arrValues[0]) * System.Convert.ToDouble(arrValues[2])).ToString();
                arrValuesToWrite[6] = (System.Convert.ToInt32(arrValues[0]) * System.Convert.ToDouble(arrValues[2])).ToString();
            }
            else if (System.Convert.ToInt32(arrValues[0]) < 0) //This is a quantity push
            {
                arrValuesToWrite[2] = (System.Convert.ToInt32(arrValues[0]) * -1).ToString();
                arrValuesToWrite[3] = arrValues[0];

                arrValuesToWrite[5] = (System.Convert.ToInt32(arrValues[0]) * -1 * System.Convert.ToDouble(arrValues[2])).ToString();
                arrValuesToWrite[6] = (System.Convert.ToInt32(arrValues[0]) * System.Convert.ToDouble(arrValues[2])).ToString();
            }

            if (System.Convert.ToInt32(arrValues[1]) < 0) //This is a date pull
            {
                arrValuesToWrite[7] = (System.Convert.ToInt32(arrValues[1]) * -1).ToString();;
                arrValuesToWrite[9] = (System.Convert.ToInt32(arrValues[1]) * -1).ToString();;

                arrValuesToWrite[10] = (System.Convert.ToInt32(arrValues[3]) * System.Convert.ToDouble(arrValues[2])).ToString();
                arrValuesToWrite[12] = (System.Convert.ToInt32(arrValues[3]) * System.Convert.ToDouble(arrValues[2])).ToString();;
            }
            else if (System.Convert.ToInt32(arrValues[1]) > 0) //This is a date push
            {
                arrValuesToWrite[8] = arrValues[1];
                arrValuesToWrite[9] = arrValues[1];

                arrValuesToWrite[11] = (System.Convert.ToInt32(arrValues[3]) * System.Convert.ToDouble(arrValues[2])).ToString();
                arrValuesToWrite[12] = (System.Convert.ToInt32(arrValues[3]) * -1 * System.Convert.ToDouble(arrValues[2])).ToString();
            }

            dumpWriter.AddToFile(arrValuesToWrite);
        }