Example #1
0
        private void tsmiDeleteProduct_Click(object sender, EventArgs e)
        {
            if (this.lvProducts.SelectedItems.Count > 0){
                int idx = this.lvProducts.SelectedItems[0].Index;
                System.Data.DataRow row = this.products.Rows[idx];
                bool no_errors = true;
                int cnt = 0;
                try{
                    this.cConnection.Open();
                    string sQuery = "SELECT ISNULL(COUNT(*), 0) FROM Purchases.ReceiptContents WHERE ProductID = @Product";
                    System.Data.SqlClient.SqlCommand check_cmd = new System.Data.SqlClient.SqlCommand();
                    check_cmd.Parameters.AddWithValue( "@Product", row["ProductID"] );
                    check_cmd.Connection = this.cConnection;
                    check_cmd.CommandTimeout = 0;
                    check_cmd.CommandType = System.Data.CommandType.Text;
                    check_cmd.CommandText = sQuery;

                    cnt = (int)check_cmd.ExecuteScalar();
                }catch(System.Exception ex ){
                    no_errors = false;
                    MessageBox.Show(ex.Message);
                }finally{
                    this.cConnection.Close();
                }
                if (no_errors &&
                    (cnt > 0) &&
                     (MessageBox.Show("Найдены заказы (" + cnt.ToString() + "), содержащие выбранный продукт, переназначить (это действие нельзы отменить)?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
                    ){
                    List<Producer.Product.OrderColumn> ord = new List<Producer.Product.OrderColumn>();
                    ord.Add(Producer.Product.OrderColumn.ProductName);
                    System.Data.SqlClient.SqlCommand command = Producer.Product.Select((Guid)row["Category"], null, null, ord);
                    command.Connection = this.cConnection;
                    System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(command);
                    System.Data.DataTable tbl = new System.Data.DataTable("Products");
                    sda.Fill(tbl);

                    VisualControls.ListOptions options = new VisualControls.ListOptions(false);
                    VisualControls.ElementsList elist = new VisualControls.ElementsList(options, "Товары", "ProductName", "ProductID", tbl);
                    if (elist.ShowDialog() == DialogResult.OK){
                        if (elist.Selected.Length == 1){
                            int new_id = (int)elist.Selected[0];
                            string query = "UPDATE Purchases.ReceiptContents SET ProductID = @NewId WHERE ProductID = @OldId";
                            command = new System.Data.SqlClient.SqlCommand();
                            command.Connection = this.cConnection;
                            command.Parameters.AddWithValue("@OldId", row["ProductID"]);
                            command.Parameters.AddWithValue("@NewId", new_id);
                            command.CommandTimeout = 0;
                            command.CommandType = System.Data.CommandType.Text;
                            command.CommandText = query;

                        }
                    }

                }
            }
        }
Example #2
0
 private void tsmiByVendorFilter_Click(object sender, EventArgs e)
 {
     System.Data.SqlClient.SqlCommand command = Purchases.Vendor.Select(-1, Guid.Empty);
     command.Connection = this.cConnection;
     System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(command);
     System.Data.DataTable tbl = new System.Data.DataTable("Vendors");
     sda.Fill(tbl);
     VisualControls.ElementsList elist = new VisualControls.ElementsList( new VisualControls.ListOptions(), "Продавцы", "VendorName", "VendorID", tbl);
     if (elist.ShowDialog() == DialogResult.OK){
         int i = 0;
         Purchases.Criteria crt = new Purchases.Criteria();
         crt.Vendors = new List<Guid>(elist.Selected.Length);
         foreach (Guid vendor in elist.Selected){
             crt.Vendors.Add(vendor);
         }
         this.LoadReceipts(crt);
     }
     return;
 }
Example #3
0
        private void tsmiDeleteCategory_Click(object sender, EventArgs e)
        {
            try{
                if (this.clbxTypes.SelectedItems.Count > 0){

                    int idx = this.clbxTypes.Items.IndexOf( this.clbxTypes.SelectedItems[0] );
                    System.Data.DataRow row = this.types_table.Rows[idx];
                    this.cConnection.Open();
                    string sQuery = "SELECT ISNULL(COUNT(*), 0) FROM Producer.Products WHERE Category = @Category AND Type = @Type";
                    System.Data.SqlClient.SqlCommand check_cmd = new System.Data.SqlClient.SqlCommand();
                    check_cmd.Parameters.AddWithValue("@Category", row["Category"]);
                    check_cmd.Parameters.AddWithValue("@Type", row["TypeId"]);
                    check_cmd.Connection = this.cConnection;
                    check_cmd.CommandTimeout = 0;
                    check_cmd.CommandType = System.Data.CommandType.Text;
                    check_cmd.CommandText = sQuery;

                    int cnt = (int)check_cmd.ExecuteScalar();

                    if (( cnt > 0 ) &&
                         (MessageBox.Show("Найдены товары (" + cnt.ToString() + "), содержащие выбранный продукт, переназначить (это действие нельзы отменить)?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
                        ){
                        System.Data.SqlClient.SqlCommand command = Producer.ProductTypes.Select((Guid)row["Category"] );
                        command.Connection = this.cConnection;
                        System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(command);
                        System.Data.DataTable tbl = new System.Data.DataTable("ProductTypes");
                        sda.Fill(tbl);

                        VisualControls.ListOptions options = new VisualControls.ListOptions(false);
                        VisualControls.ElementsList elist = new VisualControls.ElementsList(options, "Подкатегории", "Name", "TypeId", tbl);
                        if (elist.ShowDialog() == DialogResult.OK)
                        {
                            if (elist.Selected.Length == 1){
                                int new_id = (int)elist.Selected[0];
                                string query = "UPDATE Producer.Products SET Type = @NewType WHERE Category = @Category AND Type = @OldType";
                                command = new System.Data.SqlClient.SqlCommand();
                                command.Connection = this.cConnection;
                                command.Parameters.AddWithValue("@OldType", row["TypeId"]);
                                command.Parameters.AddWithValue("@NewType", new_id);
                                command.Parameters.AddWithValue("@Category", row["Category"]);
                                command.CommandTimeout = 0;
                                command.CommandType = System.Data.CommandType.Text;
                                command.CommandText = query;

                            }
                        }

                    }

                }
            }catch (System.Exception ex){
                MessageBox.Show("Ошибка при удалении категории товаров:\n" + ex.Message);
            }
            return;
        }
Example #4
0
 private void tsmiByCategoryFilter_Click(object sender, EventArgs e)
 {
     System.Data.SqlClient.SqlCommand command = Producer.Categories.Select(Guid.Empty);
     command.Connection = this.cConnection;
     System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(command);
     System.Data.DataTable tbl = new System.Data.DataTable("Categories");
     sda.Fill(tbl);
     VisualControls.ElementsList elist = new VisualControls.ElementsList(new VisualControls.ListOptions(), "Категории", "CategoryName", "CategoryID", tbl);
     if (elist.ShowDialog() == DialogResult.OK)
     {
         //int i = 0;
         Purchases.Criteria crt = new Purchases.Criteria();
         crt.Categories = new List<Guid>(elist.Selected.Length);
         foreach (Guid category in elist.Selected)
         {
             crt.Categories.Add(category);
         }
         this.LoadReceipts(crt);
     }
     return;
 }