Example #1
0
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     if (!global.Bills)
     {
         global.Bills = true;
         Bills mt = new Bills(this.global);
         mt.Show();
     }
     else
     {
         MessageBox.Show("Запрашеваемое окно уже окрыто.");
     }
 }
Example #2
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            List<string> file2del = new List<string>();

            // if we have something
            if (dataMiniRoutes.Count != 0)
            {
                // finish edit of data
                dataG2.EndEdit();
                // for all found routes
                foreach (miniRouteList mrl in dataMiniRoutes)
                {
                    string sqlTime = "", sqlStatus = "", sqlRouteid = "", sqlBarcode = "", sqlTimelast = "", sqlDriver = "", sqlExsped = "", sqlCar = "", sqlUin = "", sqlStartBarcode = "";

                    // fill some data
                    Route miniRoute = mrl.getMiniRoute();
                    sqlTime = UnixTimeNow().ToString();
                    sqlTimelast = UnixTimeNow().ToString();
                    sqlStatus = "0";
                    sqlRouteid = miniRoute.id;
                    sqlBarcode = mrl.myBarcode;
                    sqlUin = mrl.myUin;
                    sqlStartBarcode = mrl.getBarcodeList();

                    // find data in datagrid (Rider,exped and car)
                    for (int i = 0; i < dataG2.RowCount; i++)
                    {
                        if (dataG2[0, i].Value.ToString() == mrl.myUin)
                        {
                            // try to get this data becose of can be empty
                            try
                            {
                                string sqlDriverBuff = dataG2[6, i].Value.ToString();
                                string[] sqlDriverRn = sqlDriverBuff.Split(';');
                                sqlDriver = sqlDriverRn[0];
                            }
                            catch (Exception) { }

                            try
                            {
                                string sqlCarBuff = dataG2[8, i].Value.ToString();
                                string[] sqlCarRn = sqlCarBuff.Split(';');
                                sqlCar = sqlCarRn[0];
                            }
                            catch (Exception) { }

                        }
                    }

                    // if all right
                    if (sqlUin != "")
                    {
                        // save main data of bill
                        string r1 = "", r2 = "", r3 = "";
                        // get name of driver
                        try
                        {
                            DataTable dataR = db.FetchAllSql("SELECT name FROM riders WHERE id = '" + sqlDriver + "'");
                            r1 = dataR.Rows[0][0].ToString();
                        }
                        catch (Exception) { }

                        // get name of expeditor
                        try
                        {
                            DataTable dataRR = db.FetchAllSql("SELECT title FROM carfaces WHERE id = ( SELECT face FROM riders WHERE id ='" + sqlDriver + "')");
                            r2 = dataRR.Rows[0][0].ToString();
                        }
                        catch (Exception) { }

                        // get the car
                        try
                        {
                            DataTable dataR = db.FetchAllSql("SELECT num,type FROM riders WHERE id = '" + sqlDriver + "'");
                            DataTable dataM = db.FetchAllSql("SELECT title FROM cartypes WHERE id = '" + dataR.Rows[0][1].ToString() + "'");
                            r3 = dataM.Rows[0][0].ToString() + " ( гос.номер: " + dataR.Rows[0][0].ToString() + ")";
                        }
                        catch (Exception) { }

                        db.FetchAllSql("INSERT INTO `bills` (time,status,routeid,barcode,timelast,driver,exsped,car,uin,startBarcodes,r1,r2,r3) VALUES " +
                        "('" + sqlTime + "','" + sqlStatus + "','" + sqlRouteid + "','" + sqlBarcode + "','" + sqlTimelast + "','" + sqlDriver + "','" + sqlExsped + "','" + sqlCar + "','" + sqlUin + "','" + sqlStartBarcode + "','" + r1 + "','" + r2 + "','" + r3 + "')");

                        // and its rows

                        foreach (rowBillData rd in rowBillDataSaved)
                        {
                            if (mrl.barcodes.Contains(rd.id))
                            {

                                db.FetchAllSql("INSERT INTO `billdata` (d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,billBarocde,billUin) VALUES " +
                                 "('" + rd.d1 + "','" + rd.d2 + "','" + rd.d3 + "','" + rd.d4 + "','" + rd.d5 + "','" + rd.d6 + "','" + rd.d7 + "','" + rd.d8 + "','" + rd.d9 + "','" + rd.d10 + "','" + rd.d11 + "','" + rd.d12 + "','" + rd.d13 + "','" + rd.d14 + "','" + rd.d15 + "','" + sqlBarcode + "','" + sqlUin + "')");

                                // set file to delte by ftp
                                if (rd.filename != "")
                                    if (!file2del.Contains(rd.filename))
                                        file2del.Add(rd.filename);
                            }

                        }

                    }

                }

                // delete file from ftp if that way upladed

                g.deleteFtpFile(file2del);

                // show created way bills
                Bills bb = new Bills(this.g);
                this.Close();
                bb.ShowDialog();

            }
            else
            {
                MessageBox.Show("Не существует ни одного маршрутного листа!");
            }
        }