Пример #1
0
        protected void btnInitAkcionnieCeny_Click(object sender, EventArgs e)
        {
            string ret = "";


            SaalutDataClasses1DataContext context = new SaalutDataClasses1DataContext();

            //-------------------------------

            var delStoreInfo = (from d in context.StoreInfos
                                select d).FirstOrDefault();

            string jurCo = delStoreInfo.Company;
            string jurF  = delStoreInfo.AddressFact;

            context.StoreInfos.DeleteOnSubmit(delStoreInfo);
            context.SubmitChanges();

            UKMDataBaseConnects utl = new UKMDataBaseConnects();

            utl.InitialStoreInfoIns();

            var newStoreInfo = (from d in context.StoreInfos
                                select d).FirstOrDefault();

            newStoreInfo.Company     = jurCo;
            newStoreInfo.AddressFact = jurF;
            context.SubmitChanges();
            //---------------------------------

            var pricesAkcion = (from p in context.PricesAkcionnies
                                select p).FirstOrDefault();

            if (pricesAkcion != null)
            {
                return;
            }

            var store = (from s in context.StoreInfos
                         where s.Active == true
                         select s).FirstOrDefault();

            CommittableTransaction tx = new CommittableTransaction();

            // Create a connection object and data adapter
            MySqlConnection cnx = null;

            try
            {
                cnx = new MySqlConnection(connStr);

                MySqlDataAdapter adapter = new MySqlDataAdapter();

                // = делаем текущий прайс лист магазина


                // Выбираем магазин
                string       cmdText = "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ; select item, price, version, deleted from ukmserver.trm_in_pricelist_items where pricelist_id = '" + store.ActPriceList_ID_UKM.ToString() + "'  and deleted = 0; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ; ";
                MySqlCommand cmd     = new MySqlCommand(cmdText, cnx);
                cmd.CommandTimeout = 30000;

                // Create a fill a Dataset
                DataSet ds = new DataSet();
                adapter.SelectCommand = cmd;
                adapter.Fill(ds);

                DataTable pricesAkcionnie = ds.Tables[0];
                if (pricesAkcionnie != null)
                {
                    foreach (DataRow row1 in pricesAkcionnie.Rows)
                    {
                        string  artikulA       = (string)row1[0];
                        decimal priceA         = (decimal)row1[1];
                        int     version_priceA = (int)row1[2];
                        bool    delete_priceA  = (bool)row1[3];


                        double newPriceA = Double.Parse(priceA.ToString());

                        var good = (from g in context.Goods
                                    where g.Articul == artikulA
                                    select g).FirstOrDefault();

                        if (good == null)
                        {
                            continue;
                        }

                        //+
                        PricesAkcionnie npr1 = new PricesAkcionnie();
                        npr1.GoodID      = good.ID;
                        npr1.Price       = newPriceA;
                        npr1.Version_UKM = version_priceA;
                        npr1.TimeStamp   = DateTime.Now;
                        npr1.Active      = true;
                        context.PricesAkcionnies.InsertOnSubmit(npr1);
                        context.SubmitChanges();
                        //-
                    }
                }

                tx.Commit();
            }
            catch (MySqlException ex)
            {
                ret += "Error: " + ex.ToString();
                tx.Rollback();
            }
            finally
            {
                if (cnx != null)
                {
                    cnx.Close();
                }
            }

            return;
        }