Exemple #1
0
        protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            jourID = (int)Gridview1.DataKeys[e.RowIndex].Value;

            var journ = (from j in context.PriceChangeJours
                         where j.ID == jourID
                         select j).FirstOrDefault();

            journ.Active = false;
            context.SubmitChanges();

            PriceJoursLinqDataSource1.DataBind();
            Gridview1.DataBind();

            e.Cancel = true;
        }
Exemple #2
0
        protected void NewJoursGridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int journalID = (int)NewJoursGridView1.SelectedDataKey.Value;

            var journal = (from j in context.PriceChangeJours
                           where j.ID == journalID
                           select j).FirstOrDefault();

            journal.Active = false;
            context.SubmitChanges();

            NewJoursGridView1.DataBind();
        }
Exemple #3
0
        // загрузка через кулоад по отделам
        public void SaveToLog(string type, string message)
        {
            if (context == null)
            {
                context = new SaalutDataClasses1DataContext();
            }

            Log log = new Log();

            log.TimeStamp = DateTime.Now;
            log.Type      = type;
            log.Message   = message;
            context.Logs.InsertOnSubmit(log);
            context.SubmitChanges();
        }
Exemple #4
0
        protected void AddToJournalButton1_Click(object sender, EventArgs e)
        {
            var store = (from s in context.StoreInfos
                         where s.Active == true
                         select s).FirstOrDefault();

            string barcodeText = BarcodeTextBox1.Text.Trim();
            //string counted = BarcodeTextBox2.Text.Trim();
            string counted = BarcodeTextBox2.Text.Trim();
            var    barcode = (from p in context.Barcodes
                              where p.Barcode1 == barcodeText &&
                              p.Active == true // bug fix barkode
                              select p).FirstOrDefault();

            if (barcode == null)
            {
                PriceLabel1.Text = "Ш/К не найден.";
                return;
            }

            // добавили дату алко, удаляем добавление количества
            //var lineCheck = (from l in context.PriceChangeLine
            //                 where l.JournalID == jourID
            //                 && l.GoodID == barcode.GoodID
            //                 select l).FirstOrDefault();
            //if (lineCheck != null)
            //{
            //    PriceLabel1.Text = "Товар уже в журнале. Количество добавлено";
            //    //lineCheck.Counted += Convert.ToInt32(counted);
            //    PriceChangeLine nlt = new PriceChangeLine();
            //    nlt.Active = lineCheck.Active;
            //    nlt.Akcionniy = lineCheck.Akcionniy;
            //    nlt.counted = lineCheck.counted + Convert.ToInt32(counted);
            //    nlt.Good = lineCheck.Good;
            //    nlt.GoodID = lineCheck.GoodID;
            //    nlt.ID = lineCheck.ID;
            //    nlt.ItemID_UKM = lineCheck.ItemID_UKM;
            //    nlt.JournalID = lineCheck.JournalID;
            //    nlt.NewPrice = lineCheck.NewPrice;
            //    nlt.PriceChangeJour = lineCheck.PriceChangeJour;
            //    nlt.TimeStamp = lineCheck.TimeStamp;
            //    nlt.alcoDt = AlcoDateTextBox1.Text;

            //    context.PriceChangeLine.DeleteOnSubmit(lineCheck);
            //    context.SubmitChanges();
            //    // context.PriceChangeLines.InsertOnSubmit(nlt);
            //    // context.SubmitChanges();

            //    // PriceLabel1.Text = "";
            //    BarcodeTextBox1.Text = "";
            //    BarcodeTextBox2.Text = "1";
            //    JourLinesLinqDataSource1.DataBind();
            //    JourLinesGridView1.DataBind();
            //    return;
            //}

            PriceChangeLine nl = new PriceChangeLine();

            nl.GoodID     = barcode.GoodID;
            nl.JournalID  = jourID;
            nl.ItemID_UKM = barcode.Good.Articul;
            nl.counted    = Convert.ToInt32(counted);
            nl.alcoDt     = AlcoDateTextBox1.Text;

            //var price = (from p in context.Prices
            //             where p.GoodID == barcode.GoodID
            //             && p.Active == true
            //             select p).FirstOrDefault();
            //if (price == null)
            //{

            //    nl.NewPrice = 0;
            //}
            //else
            //    nl.NewPrice = price.Price1;

            // цены укм
            // Create a connection object and data adapter
            DataTable       prices;
            decimal         price = 0;
            MySqlConnection cnx   = null;

            try
            {
                cnx = new MySqlConnection(connStr);
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                // Prices
                string       cmdText = "select item, price, version, deleted	from ukmserver.trm_in_pricelist_items where item = '"+ barcode.Good.Articul + "' and pricelist_id = '" + store.PriceList_ID_UKM.ToString() + "'  and deleted = 0 ";
                MySqlCommand cmd     = new MySqlCommand(cmdText, cnx);
                cmd.CommandTimeout = 30000;

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

                prices = ds5.Tables[0];

                if (prices != null)
                {
                    foreach (DataRow row in prices.Rows)
                    {
                        price = (decimal)row[1];
                    }
                }
            }
            catch (MySqlException ex)
            {
                nl.NewPrice = 0;
            }
            finally
            {
                if (cnx != null)
                {
                    cnx.Close();
                }
            }

            Double dPrice = 0;

            Double.TryParse(price.ToString(), out dPrice);
            nl.NewPrice = dPrice;

            nl.Active    = true;
            nl.TimeStamp = DateTime.Now;
            nl.Akcionniy = false;
            context.PriceChangeLine.InsertOnSubmit(nl);
            context.SubmitChanges();

            PriceLabel1.Text     = "";
            BarcodeTextBox1.Text = "";
            BarcodeTextBox2.Text = "1";
            JourLinesLinqDataSource1.DataBind();
            JourLinesGridView1.DataBind();
        }
        public void PrintAllQuoue()
        {
            // Get the physical path of the current application.
            string appPath         = HttpRuntime.AppDomainAppPath;
            string termLabelFolder = appPath + @"TRMLabels\";
            string termLabelExport = appPath + @"TRMExportCennic\";


            if (context == null)
            {
                context = new SaalutDataClasses1DataContext();
            }


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


            var setting = (from s in context.Settings
                           select s).FirstOrDefault();

            var cfps = (from c in context.TermoCennicQuoue
                        where c.Active == true &&
                        c.TimeStamp >= DateTime.Now.AddHours(-3)
                        select c);

            foreach (TermoCennicQuoue q in cfps)
            {
                var priceChangeJour = (from p in context.PriceChangeJours
                                       where p.ID == q.JournalID
                                       select p).FirstOrDefault();


                //Encoding enc = Encoding.GetEncoding(866);
                Encoding enc = Encoding.GetEncoding(1251);
                //Encoding enc = Encoding.GetEncoding(850);

                string filePath    = termLabelFolder + q.TermoCennic.FileLabelName;
                string toFileName  = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK").Replace(".", "").Replace(" ", "").Replace(":", "").Replace("-", "").Replace("T", "").Replace("+", "") + "_" + q.TermoCennic.FileLabelName;
                string toFilePath  = termLabelExport + toFileName;
                string batFilePath = termLabelExport + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK").Replace(".", "").Replace(" ", "").Replace(":", "").Replace("-", "").Replace("T", "").Replace("+", "") + ".bat";



                // + цена по новому
                DataTable prices;

                MySqlConnection cnx = null;
                try
                {
                    cnx = new MySqlConnection(connStr);
                    MySqlDataAdapter adapter = new MySqlDataAdapter();

                    // Prices
                    string       cmdText = "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ; select item, price, version, deleted from ukmserver.trm_in_pricelist_items where item = '" + q.Good.Articul + "' and pricelist_id = '" + store.PriceList_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 ds5 = new DataSet();
                    adapter.SelectCommand = cmd;
                    adapter.Fill(ds5);

                    prices = ds5.Tables[0];
                }
                catch (MySqlException ex)
                {
                    return;
                }
                finally
                {
                    if (cnx != null)
                    {
                        cnx.Close();
                    }
                }

                // - цена по новому


                //var price = (from p in context.Prices
                //             where p.GoodID == good.ID
                //             && p.Active == true
                //             select p).FirstOrDefault();

                string priceVal = "нет цены";
                //var price = (from p in dataContext.Prices
                //             where p.GoodID == good.ID
                //             && p.Active == true
                //             select p).FirstOrDefault();
                //if (price != null)
                //{
                //    double priceFromDB = price.Price1.Value;

                //    if (template.EdinicZa100Gr != null)
                //    {
                //        if (template.EdinicZa100Gr.Value)
                //        {
                //            priceFromDB = priceFromDB / 10;
                //        }
                //    }
                //    priceVal = priceFromDB.ToString();
                //}

                // + новая цена
                decimal price = 0;
                if (prices != null)
                {
                    foreach (DataRow row in prices.Rows)
                    {
                        price = (decimal)row[1];
                    }
                }
                if (price != 0)
                {
                    priceVal = price.ToString();
                    if (Division == "RB")
                    {
                        int priceValZap = priceVal.IndexOf(",");
                        if (priceValZap != -1)
                        {
                            priceVal = priceVal.Substring(0, priceValZap);
                        }
                    }
                    else
                    if (Division == "RF")
                    {
                        int priceValZap = priceVal.IndexOf(",");
                        if (priceValZap != -1)
                        {
                            if ((priceValZap + 3) < priceVal.Length)
                            {
                                priceVal = priceVal.Substring(0, priceValZap + 3);
                            }
                        }
                    }
                }
                // - новая цена


                StringBuilder str = new StringBuilder();

                try
                {
                    using (StreamReader sr = new StreamReader(filePath, enc))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string toStr = "";

                            toStr = sr.ReadLine();

                            // + goodName
                            if (toStr.Contains("%goodname"))
                            {
                                string        descr   = q.Good.Name;
                                StringBuilder strName = new StringBuilder();

                                descr = descr.Replace("\r\n", "\n");
                                descr = descr.Replace("\r", "\n");
                                descr = descr.Replace("\t", " ");

                                int length = descr.Length;
                                int from   = 0;

                                while (length >= q.TermoCennic.GoodNameVStroke) //количество символов в строке
                                {
                                    strName.Append(descr.Substring(from, q.TermoCennic.GoodNameVStroke.Value) + "\n");
                                    from   += q.TermoCennic.GoodNameVStroke.Value;
                                    length -= q.TermoCennic.GoodNameVStroke.Value;
                                }
                                if (length < q.TermoCennic.GoodNameVStroke.Value)
                                {
                                    strName.Append(descr.Substring(from, length));
                                }

                                string[] textParagraphs = strName.ToString().Split('\n');
                                int      i = 1;
                                foreach (string strText in textParagraphs.ToArray())
                                {
                                    using (StringFormat sf = new StringFormat())
                                    {
                                        //sf.Alignment = StringAlignment.Near;
                                        //sf.LineAlignment = StringAlignment.Near;
                                        //sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                                        sf.FormatFlags = StringFormatFlags.NoWrap;

                                        toStr = toStr.Replace("%goodname" + i.ToString() + "%", strText.Trim());
                                    }
                                    i++;
                                }

                                if (toStr.Contains("%goodname"))
                                {
                                    toStr = toStr.Substring(0, toStr.IndexOf("%"));
                                }
                            }
                            // - goodName

                            // + goodContents
                            if (toStr.Contains("%contents") && q.Good.Contents != null)
                            {
                                string        descr   = q.Good.Contents;
                                StringBuilder strName = new StringBuilder();

                                descr = descr.Replace("\r\n", "\n");
                                descr = descr.Replace("\r", "\n");
                                descr = descr.Replace("\t", " ");

                                int length = descr.Length;
                                int from   = 0;

                                while (length >= q.TermoCennic.ContentsVStroke) //количество символов в строке
                                {
                                    strName.Append(descr.Substring(from, q.TermoCennic.ContentsVStroke.Value) + "\n");
                                    from   += q.TermoCennic.ContentsVStroke.Value;
                                    length -= q.TermoCennic.ContentsVStroke.Value;
                                }
                                if (length < q.TermoCennic.ContentsVStroke.Value)
                                {
                                    strName.Append(descr.Substring(from, length));
                                }

                                string[] textParagraphs = strName.ToString().Split('\n');
                                int      i = 1;
                                foreach (string strText in textParagraphs.ToArray())
                                {
                                    using (StringFormat sf = new StringFormat())
                                    {
                                        //sf.Alignment = StringAlignment.Near;
                                        //sf.LineAlignment = StringAlignment.Near;
                                        //sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                                        sf.FormatFlags = StringFormatFlags.NoWrap;

                                        toStr = toStr.Replace("%contents" + i.ToString() + "%", strText.Trim());
                                    }
                                    i++;
                                }

                                if (toStr.Contains("%contents"))
                                {
                                    toStr = toStr.Substring(0, toStr.IndexOf("%"));
                                }
                            }
                            // - goodContents

                            toStr = toStr.Replace("%docdate%", DateTime.Now.ToString("dd.MM.yyyy"));
                            toStr = toStr.Replace("%article%", q.Good.Articul);
                            toStr = toStr.Replace("%barcode%", q.Good.Barcode);
                            toStr = toStr.Replace("%edinica%", q.Good.Edinic);
                            toStr = toStr.Replace("%producer%", q.Good.Producer + " " + q.Good.Country);

                            toStr = toStr.Replace("%company%", store.Company.ToString());
                            toStr = toStr.Replace("%address%", store.AddressFact.ToString());


                            string priceRub = "";
                            string priceKop = "";
                            if (Division == "RF")
                            {
                                int priceValZap = priceVal.IndexOf(",");
                                if (priceValZap != -1)
                                {
                                    priceRub = priceVal.Substring(0, priceValZap);
                                    if ((priceValZap + 3) <= priceVal.Length)
                                    {
                                        priceKop = priceVal.Substring(priceValZap + 1, 2);
                                    }
                                }
                                else
                                {
                                    priceValZap = priceVal.IndexOf(".");
                                    if (priceValZap != -1)
                                    {
                                        priceRub = priceVal.Substring(0, priceValZap);
                                        if ((priceValZap + 3) <= priceVal.Length)
                                        {
                                            priceKop = priceVal.Substring(priceValZap + 1, 2);
                                        }
                                    }
                                }
                            }


                            toStr = toStr.Replace("%pricerub%", priceRub);
                            toStr = toStr.Replace("%pricekop%", priceKop);



                            str.AppendLine(toStr);
                        }
                    }

                    string[] textParagraphsExport = str.ToString().Split('\n');

                    using (StreamWriter sr = new StreamWriter(toFilePath, false, enc, 512))
                    {
                        foreach (string strText in textParagraphsExport.ToArray())
                        {
                            using (StringFormat sf = new StringFormat())
                            {
                                //sf.Alignment = StringAlignment.Near;
                                //sf.LineAlignment = StringAlignment.Near;
                                //sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                                sf.FormatFlags = StringFormatFlags.NoWrap;

                                sr.WriteLine(strText.Trim());
                            }
                        }

                        sr.Flush();
                        sr.Close();
                    }

                    // + bat file
                    using (StreamWriter sr = new StreamWriter(batFilePath, false, enc, 512))
                    {
                        if (priceChangeJour != null)
                        {
                            if (priceChangeJour.Order_no > 0)
                            {
                                var mobPr = (from m in context.MobileTermoPrinters
                                             where m.Num == priceChangeJour.Order_no
                                             select m).FirstOrDefault();
                                if (mobPr != null)
                                {
                                    sr.WriteLine(@"cd " + termLabelExport);
                                    sr.WriteLine(@"copy " + toFileName + " " + mobPr.NetPath + " /b");
                                }
                                else
                                {
                                    sr.WriteLine(@"cd " + termLabelExport);
                                    sr.WriteLine(@"copy " + toFileName + " " + setting.MobileTermoPrinterNetPath + " /b");
                                }
                            }
                            else
                            {
                                sr.WriteLine(@"cd " + termLabelExport);
                                sr.WriteLine(@"copy " + toFileName + " " + setting.MobileTermoPrinterNetPath + " /b");
                            }
                        }
                        else
                        {
                            sr.WriteLine(@"cd " + termLabelExport);
                            sr.WriteLine(@"copy " + toFileName + " " + setting.MobileTermoPrinterNetPath + " /b");
                        }


                        sr.Flush();
                        sr.Close();

                        //System.Diagnostics.Process proc = new System.Diagnostics.Process();
                        //proc.StartInfo.FileName = batFilePath;
                        //proc.StartInfo.RedirectStandardError = false;
                        //proc.StartInfo.RedirectStandardOutput = false;
                        //proc.StartInfo.UseShellExecute = false;
                        //proc.Start();
                        //proc.WaitForExit();

                        //Process proc = Process.Start("cmd.exe", @"/C " + batFilePath);
                    }
                    // - bat file


                    //if (File.Exists(toFilePath))
                    //    File.Delete(toFilePath);
                    //if (File.Exists(batFilePath))
                    //    File.Delete(batFilePath);
                }
                catch (Exception e)
                {
                    return;
                }


                q.Active = false;
                context.SubmitChanges();
            }

            ExecPrinting();
        }
        public void LoadDataFromSAPERP(string[] newTP)
        {
            string werk   = "";
            string onDate = txbOnDate.Text;

            var settingsSP = (from s in context.SettingsSAPERPTbls
                              select s).FirstOrDefault();

            werk = settingsSP.Werk;

            if (werk == null || werk == "")
            {
                ErrorLabel1.Text        = "Не указан в настройках завод магазина";
                Wizard1.ActiveStepIndex = 1;
                return;
            }

            MyBackendConfig2 cfg = new MyBackendConfig2();

            try
            {
                // delete all
                var sap1Del = from p in context.SAPOUT_REST
                              select p;
                context.SAPOUT_REST.DeleteAllOnSubmit(sap1Del);
                context.SubmitChanges();
                var sap2Del = from p in context.SAPOUT_SMENA
                              select p;
                context.SAPOUT_SMENA.DeleteAllOnSubmit(sap2Del);
                context.SubmitChanges();
                //-----------------------------

                RfcDestinationManager.RegisterDestinationConfiguration(cfg);      //1
                RfcDestination prd = RfcDestinationManager.GetDestination("AEP"); //2


                RfcRepository repo = prd.Repository;//3

                IRfcFunction pricesBapi =
                    repo.CreateFunction("Y_GET_MATNR_REST"); //4
                pricesBapi.SetValue("I_WERKS", werk);        //5
                //pricesBapi.SetValue("I_DATE", onDate); //5

                IRfcTable detail1 = pricesBapi.GetTable("TAB");

                foreach (string strs in newTP)
                {
                    detail1.Append();

                    detail1.SetValue("MATNR", strs);
                    detail1.SetValue("MAKTX", "");
                    detail1.SetValue("LGORT", "");
                    detail1.SetValue("LABST", 0.0);
                    detail1.SetValue("MEINS", "");
                }

                pricesBapi.Invoke(prd); //6
                IRfcTable detail3 = pricesBapi.GetTable("TAB");


                DateTime tsmp = DateTime.Now;

                int i = 0;
                foreach (IRfcStructure elem in detail3)
                {
                    string matnr = elem[0].GetString();
                    string maktx = elem[1].GetString();
                    string lgort = elem[2].GetString();
                    double labst = elem[3].GetDouble();
                    string meins = elem[4].GetString();

                    SAPOUT_REST np = new SAPOUT_REST();
                    np.MATNR     = matnr;
                    np.MAKTX     = maktx;
                    np.LGORT     = lgort;
                    np.LABST     = labst;
                    np.MEINS     = meins;
                    np.TimeStamp = tsmp;
                    context.SAPOUT_REST.InsertOnSubmit(np);

                    if (i == 100)
                    {
                        context.SubmitChanges();
                        i = 0;
                    }
                    i++;
                }
                context.SubmitChanges();



                RfcRepository repo2 = prd.Repository;//3

                IRfcFunction pricesBapi2 =
                    repo2.CreateFunction("Y_GET_SMENA"); //4
                pricesBapi2.SetValue("I_WERKS", werk);   //5
                pricesBapi2.SetValue("I_DATE", onDate);  //5
                pricesBapi2.Invoke(prd);                 //6
                IRfcTable detail2 = pricesBapi2.GetTable("TAB");

                tsmp = DateTime.Now;

                i = 0;
                foreach (IRfcStructure elem in detail2)
                {
                    string sm_date = elem[0].GetString();
                    string smena   = elem[1].GetString();

                    SAPOUT_SMENA np = new SAPOUT_SMENA();
                    np.SM_DATE   = DateTime.Parse(sm_date);
                    np.SMENA     = smena;
                    np.TimeStamp = tsmp;
                    context.SAPOUT_SMENA.InsertOnSubmit(np);

                    if (i == 100)
                    {
                        context.SubmitChanges();
                        i = 0;
                    }
                    i++;
                }
                context.SubmitChanges();



                //String companyName = detail.
                //    GetString("NAME1");//7
                //Console.WriteLine(companyName);
                //Console.Read();
            }
            catch (RfcInvalidStateException e)
            {
                // cascade up callstack
                ErrorLabel1.Text        = "Проблема повторного подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcCommunicationException e)
            {
                // network problem...
                ErrorLabel1.Text        = "Сетевая проблема подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcLogonException e)
            {
                // user could not logon...
                ErrorLabel1.Text        = "Не правильный пользователь для подключения к SAP: " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapRuntimeException e)
            {
                // serious problem on ABAP system side...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (serious problem on ABAP system side...): " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapBaseException e)
            {
                // The function module returned an ABAP exception, an ABAP message
                // or an ABAP class-based exception...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (The function module returned an ABAP exception, an ABAP message): " + e.Message;
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);//1
            }
        }
Exemple #7
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;
        }
        public void LoadDataFromSAPERP()
        {
            string werk       = "";
            var    settingsSP = (from s in context.SettingsSAPERPTbls
                                 select s).FirstOrDefault();

            werk = settingsSP.Werk;

            if (werk == null || werk == "")
            {
                ErrorLabel1.Text        = "Не указан в настройках завод магазина";
                Wizard1.ActiveStepIndex = 1;
                return;
            }

            MyBackendConfig cfg = new MyBackendConfig();

            try
            {
                // delete all
                var sapPricesDel = from p in context.SAPPriceTbls
                                   select p;
                context.SAPPriceTbls.DeleteAllOnSubmit(sapPricesDel);
                context.SubmitChanges();
                //-----------------------------

                RfcDestinationManager.RegisterDestinationConfiguration(cfg);      //1
                RfcDestination prd = RfcDestinationManager.GetDestination("AEP"); //2


                RfcRepository repo       = prd.Repository;    //3
                IRfcFunction  pricesBapi =
                    repo.CreateFunction("Y_GET_MATNR_PRICE"); //4
                pricesBapi.SetValue("I_WERKS", werk);         //5
                pricesBapi.Invoke(prd);                       //6
                IRfcTable detail = pricesBapi.GetTable("TAB");

                int i = 0;
                foreach (IRfcStructure elem in detail)
                {
                    string matnr  = elem[0].GetString();
                    double kbetr  = elem[1].GetDouble();
                    string kschl  = elem[2].GetString();
                    string assort = elem[3].GetString();

                    SAPPriceTbl np = new SAPPriceTbl();
                    np.MATNR  = matnr;
                    np.KBETR  = kbetr;
                    np.KSCHL  = kschl;
                    np.ASSORT = assort;
                    context.SAPPriceTbls.InsertOnSubmit(np);

                    if (i == 100)
                    {
                        context.SubmitChanges();
                        i = 0;
                    }
                    i++;
                }
                context.SubmitChanges();



                //String companyName = detail.
                //    GetString("NAME1");//7
                //Console.WriteLine(companyName);
                //Console.Read();
            }
            catch (RfcInvalidStateException e)
            {
                // cascade up callstack
                ErrorLabel1.Text        = "Проблема повторного подключения к SAP";
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcCommunicationException e)
            {
                // network problem...
                ErrorLabel1.Text        = "Сетевая проблема подключения к SAP";
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcLogonException e)
            {
                // user could not logon...
                ErrorLabel1.Text        = "Не правильный пользователь для подключения к SAP";
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapRuntimeException e)
            {
                // serious problem on ABAP system side...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (serious problem on ABAP system side...)";
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            catch (RfcAbapBaseException e)
            {
                // The function module returned an ABAP exception, an ABAP message
                // or an ABAP class-based exception...
                ErrorLabel1.Text        = "Серьезная проблема на стороне SAP обратитесь в службу поддержки SAP (The function module returned an ABAP exception, an ABAP message)";
                Wizard1.ActiveStepIndex = 1;

                Log l = new Log();
                l.Message   = e.Message;
                l.Type      = "SAP";
                l.TimeStamp = DateTime.Now;
                context.Logs.InsertOnSubmit(l);
                context.SubmitChanges();
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(cfg);//1
            }
        }
Exemple #9
0
        protected void CennicButton1_Click(object sender, EventArgs e)
        {
            int      newJournalID = 0;
            DateTime tst          = DateTime.Now;

            // создадим темповый журнал
            if (GoodsGridView1.Rows.Count != 0)
            {
                PriceChangeJour np = new PriceChangeJour();
                np.Change_log_id_UKM = 0;
                np.Order_no          = 0;
                np.InUse             = false;
                np.TimeStamp         = tst;
                np.Active            = true;
                context.PriceChangeJours.InsertOnSubmit(np);
                context.SubmitChanges();
            }
            else
            {
                return;
            }

            var journTMP = (from t in context.PriceChangeJours
                            where t.TimeStamp == tst
                            select t).FirstOrDefault();

            newJournalID = journTMP.ID;


            PrintTemplateCart templCart = (PrintTemplateCart)Session["PrintTemplateCart"];

            foreach (PrintTemplateCartItem item in templCart)
            {
                var good = (from g in context.Goods
                            where g.ID == item.JourLineID
                            select g).FirstOrDefault();
                if (good == null)
                {
                    continue;
                }

                if (CheckBox1WhithoutPrice.Checked == true)
                {
                    var prs = (from p in context.Prices
                               where p.GoodID == good.ID &&
                               p.Active == true
                               select p).FirstOrDefault();
                    if (prs == null)
                    {
                        continue;
                    }
                }

                PriceChangeLine nl = new PriceChangeLine();
                nl.Good       = good;
                nl.JournalID  = newJournalID;
                nl.ItemID_UKM = good.Articul;
                Price price = (from p in context.Prices
                               where p.GoodID == good.ID &&
                               p.Active == true
                               select p).FirstOrDefault();
                if (price != null)
                {
                    nl.NewPrice = price.Price1.Value;
                }
                else
                {
                    nl.NewPrice = 0;
                }
                nl.Active    = true;
                nl.TimeStamp = tst;
                context.PriceChangeLine.InsertOnSubmit(nl);
            }
            context.SubmitChanges();


            //foreach (GridViewRow row in GoodsGridView1.Rows)
            //{
            //    Label GoodIDLabel1 = (Label)row.FindControl("GoodIDLabel1");
            //    DropDownList PrintTemplateDropDownList1 = (DropDownList)row.FindControl("PrintTemplateDropDownList1");

            //    int goodid = Int32.Parse(GoodIDLabel1.Text);
            //    int printTempl = Int32.Parse(PrintTemplateDropDownList1.SelectedValue);

            //    var good = (from g in context.Goods
            //                where g.ID == goodid
            //                select g).FirstOrDefault();
            //    if (good == null)
            //        continue;

            //    PriceChangeLine nl = new PriceChangeLine();
            //    nl.Good = good;
            //    nl.JournalID = newJournalID;
            //    nl.ItemID_UKM = good.Articul;
            //    Price price = (from p in context.Prices
            //                   where p.GoodID == goodid
            //                   && p.Active == true
            //                   select p).FirstOrDefault();
            //    if (price != null)
            //        nl.NewPrice = price.Price1.Value;
            //    else
            //        nl.NewPrice = 0;
            //    nl.Active = true;
            //    nl.TimeStamp = tst;
            //    context.PriceChangeLine.InsertOnSubmit(nl);
            //}
            //context.SubmitChanges();


            string url = "CennicList.aspx?ID=" + newJournalID.ToString();

            ////string redirectScript = "<script>window.open('" + url + "');</script>";
            ////Response.Write(redirectScript);


            Response.Redirect(url);
        }