Esempio n. 1
0
 public void Add(Shipping item)
 {
     Add(item.Name, item.Price, item.ShippingType, item.Capacity);
 }
Esempio n. 2
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)&&(cellValue=="")) return;
            else if ((dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value!=null)&&(cellValue == dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
                return;
            if ((addID != -1) && (addID != e.RowIndex))
                rowsAdded = false;
            else if ((addID != -1) && (addID == e.RowIndex))
                rowsAdded = true;

            if (initState) return;
            if (shippingTypes == null) return;

            foreach(String collumn in nummericIntCollums){
                int intOut = 0;
                if (dataGridView1.Rows[e.RowIndex].Cells[collumn].Value == null) continue;
                if (!int.TryParse(dataGridView1.Rows[e.RowIndex].Cells[collumn].Value.ToString(), out intOut))
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "Zadejte číselnou hodnotu!";
                }
                else {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "";
                }
            }
            foreach (String collumn in nummericFloatCollums)
            {
                float floatOut = 0;
                if (dataGridView1.Rows[e.RowIndex].Cells[collumn].Value == null) continue;
                if (!float.TryParse(dataGridView1.Rows[e.RowIndex].Cells[collumn].Value.ToString().Replace('.',','), out floatOut))
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "Zadejte číselnou hodnotu!";
                }
                else
                {
                    dataGridView1.Rows[e.RowIndex].Cells[collumn].ErrorText = "";
                }
            }

            bool rowError = false;
            foreach (DataGridViewCell cell in dataGridView1.Rows[e.RowIndex].Cells) {
                if (cell.ErrorText != "")
                {
                    rowError = true;
                    break;
                }
            }
            ShippingType shippingTypeItem = new ShippingType(0, "");
            if (dataGridView1.Rows[e.RowIndex].Cells["ShippingTypeColumn"].Value != null)
                shippingTypeItem = getShippingType(dataGridView1.Rows[e.RowIndex].Cells["ShippingTypeColumn"].Value.ToString());
            if (shippingTypeItem.ID == 0) return;

            String name = "";
            if (dataGridView1.Rows[e.RowIndex].Cells["NameColumn"].Value != null)
                name = dataGridView1.Rows[e.RowIndex].Cells["NameColumn"].Value.ToString();

            float price = 0;
            if ((dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value.ToString()!=""))
                price = float.Parse(dataGridView1.Rows[e.RowIndex].Cells["PriceColumn"].Value.ToString());
            else return;

            float capacity = 0;
            if ((dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value != null) && (dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value.ToString() != ""))
                capacity = float.Parse(dataGridView1.Rows[e.RowIndex].Cells["CapacityColumn"].Value.ToString());
            else return;

            if (name == "") return;

            int id = 0;
            if (!rowsAdded) id = items[e.RowIndex].ID;/* id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells["IDColumn"].Value.ToString());*/
            Shipping ShippingItem = new Shipping(
                 (int)parseCell(0,e.RowIndex,"IDColumn"),
                 name,
                 price,
                 shippingTypeItem,
                 capacity
            );

            if (rowError) return;
            if (rowsAdded)
            {
                Status = "Přidávám novou položku...";
                Shippings.Add(ShippingItem);
                if (!connector.IsConnected()) return;
                dataGridView1.BeginInvoke(new Action(()=>{
                    reload();
                    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
                    //dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells.Count - 1].Selected = true;
                    //dataGridView1.BeginEdit(true);
                }));
                addID = -1;
                dataGridView1.Rows[dataGridView1.NewRowIndex].ReadOnly = false;
                dataGridView1.Rows[dataGridView1.NewRowIndex].DefaultCellStyle = dataGridView1.DefaultCellStyle;
                refresh();
            }
            else
            {
                if (items[e.RowIndex] != ShippingItem)
                {
                    Status = "Provádím úpravy...";
                    Shippings.Change(ShippingItem);
                    if (!connector.IsConnected()) return;
                }
            }
            rowsAdded = false;
            Status = ".....";
        }
Esempio n. 3
0
 public void Change(Shipping item)
 {
     SQL.RunQuery(String.Format("UPDATE `{0}` SET NAME='{1}', PRICE={2}, ID_TYPE={3}, CAPACITY={4} WHERE ID={5};", Table, item.Name.Replace("'", "''"), item.Price, item.ShippingType.ID, item.Capacity, item.ID));
 }