示例#1
0
        public static void InsertarReferencia(string _Archivo, string _Anexo, string _Celda, int _Cantidad, string _Column, string _Row, int _Posicion)
        {
            string _Path   = ExcelAddIn.Access.Configuration.Path;
            var    Indices = new oIndices
            {
                Archivo  = _Archivo,
                Anexo    = _Anexo,
                Celda    = _Celda,
                Cantidad = _Cantidad,
                Column   = _Column,
                Row      = _Row
            };

            string jReference = JsonConvert.SerializeObject(Indices);

            if (Directory.Exists(_Path + "\\references"))
            {
                if (!File.Exists(_Path + "\\references\\" + _Archivo + ".json"))
                {
                    File.WriteAllText(_Path + "\\references\\" + _Archivo + ".json", jReference);
                }
                else
                {
                    string       _jCadena = "";
                    StreamReader _fJason  = new StreamReader(_Path + "\\references\\" + _Archivo + ".json");

                    while (_fJason.Peek() >= 0)
                    {
                        var      _json    = _fJason.ReadLine();
                        oIndices _Indices = JsonConvert.DeserializeObject <oIndices>(_json);

                        //if(Convert.ToInt32(_Row) < Convert.ToInt32(_Indices.Row))
                        //{
                        //    Match m = Regex.Match(_Indices.Celda, "(\\d+)");
                        //    string _num = "0";
                        //    if (m.Success){_num = m.Value;}

                        //    _Indices.Row = (Convert.ToInt32(_Indices.Row) + _Posicion).ToString();
                        //    _json = JsonConvert.SerializeObject(_Indices);
                        //}
                        if (_Indices.Column + _Indices.Row != _Column + _Row)
                        {
                            _jCadena += _json;
                            _jCadena += string.Format(Environment.NewLine);
                        }
                    }

                    _fJason.Close();
                    //_jCadena += string.Format(Environment.NewLine);
                    _jCadena += jReference;
                    File.WriteAllText(_Path + "\\references\\" + _Archivo + ".json", _jCadena);
                }
            }
            else
            {
                Directory.CreateDirectory(_Path + "\\references");
                if (!File.Exists(_Path + "\\references\\" + _Archivo + ".json"))
                {
                    File.WriteAllText(_Path + "\\references\\" + _Archivo + ".json", jReference);
                }
                else
                {
                    string       _jCadena = "";
                    StreamReader _fJason  = new StreamReader(_Path + "\\references\\" + _Archivo + ".json");

                    while (_fJason.Peek() >= 0)
                    {
                        _jCadena = _jCadena + _fJason.ReadLine();
                    }

                    _fJason.Close();
                    _jCadena = _jCadena + jReference;
                    File.WriteAllText(_Path + "\\references\\" + _Archivo + ".json", _jCadena);
                }
            }

            Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;
            wb.Save();
        }
示例#2
0
        public static void ActualizarReferencia(string _Archivo, string _Anexo, string _Celda, int _Cantidad, string _Column, string _Row, int CantEliminar, string Accion)
        {
            string _Path = ExcelAddIn.Access.Configuration.Path;

            if (File.Exists(_Path + "\\references\\" + _Archivo + ".json"))
            {
                string       _jCadena = "";
                StreamReader _fJason  = new StreamReader(_Path + "\\references\\" + _Archivo + ".json");

                while (_fJason.Peek() >= 0)
                {
                    var      _json    = _fJason.ReadLine();
                    oIndices _Indices = JsonConvert.DeserializeObject <oIndices>(_json);

                    if (_Indices.Anexo + _Indices.Column + _Indices.Row == _Anexo + _Column + _Row)
                    {
                        if (Accion == "E")
                        {//Eliminar
                            _Indices.Cantidad -= CantEliminar;
                        }
                        else if (Accion == "A")
                        {//Agregar
                            _Indices.Cantidad += 1;
                        }
                        _json = JsonConvert.SerializeObject(_Indices);
                    }
                    if (_Indices.Column != _Column)
                    {
                        if (_Indices.Row == _Row)
                        {
                            if (Accion == "E")
                            {//Eliminar
                                _Indices.Cantidad -= CantEliminar;
                            }
                            else if (Accion == "A")
                            {//Agregar
                                _Indices.Cantidad += 1;
                            }
                            _json = JsonConvert.SerializeObject(_Indices);
                        }
                    }
                    if (_Indices.Anexo + _Indices.Row != _Anexo + _Row)
                    {
                        if (Convert.ToInt32(_Row) < Convert.ToInt32(_Indices.Row))
                        {
                            if (Accion == "E")
                            {//Eliminar
                                _Indices.Row = (Convert.ToInt32(_Indices.Row) - CantEliminar).ToString();
                            }
                            else if (Accion == "A")
                            {//Agregar
                                _Indices.Row = (Convert.ToInt32(_Indices.Row) + 1).ToString();
                            }
                            _json = JsonConvert.SerializeObject(_Indices);
                        }
                    }

                    _jCadena += _json;
                    _jCadena += string.Format(Environment.NewLine);
                }

                _fJason.Close();
                File.WriteAllText(_Path + "\\references\\" + _Archivo + ".json", _jCadena);
                Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;
                wb.Save();
            }
        }