예제 #1
0
        public bool saveCurrentFile(string filename, CardFileFormat.Format format, bool export)
        {
            int fields = 0;

            CardWriter cardWriter = null;

            try
            {
                cardWriter = new CardWriter(filename, format);

                for (int i = 0; i < cardWriter.Fields.Length; i++)
                {
                    //column order must be the same as fields order!!
                    if (_decodeForm.CardsGrid.Columns[i].Visible)
                    {
                        fields |= cardWriter.Fields[i];
                    }
                }

                cardWriter.Write(_decodeForm.currentKey, _decodeForm.CardsGrid.GetCardsFromGrid(), fields);

                if (!export)
                {
                    _decodeForm.CurrentFileFormat = cardWriter.FileFormat;
                    _decodeForm.CurrentFileName   = filename;
                }
                else
                {
                    _decodeForm.openExportedTextFile(filename);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                TaskDialog.MessageBox(_decodeForm.DecodeForm,
                                      "Error",
                                      "Cannot save file: " + filename,
                                      frmDecode.messageSaveFailed,
                                      "",
                                      TaskDialogButtons.OK,
                                      SysIcons.Error
                                      );
                return(false);
            }
            finally
            {
                if (cardWriter != null)
                {
                    cardWriter.Close();
                }
            }
            _decodeForm.isCrfModified = false;
            return(true);
        }
예제 #2
0
        private void setCardsInClipboard(List <Card> cards)
        {
            if (cards != null && cards.Count != 0)
            {
                timeDiff = new List <double>();
                for (int j = 0; j < cards.Count; j++)
                {
                    timeDiff.Add(cards[j].timeDiff);
                }
            }
            DataObject data = new DataObject();

            //cards as a list of cards
            List <a> ListA = cards.ConvertAll <a>(delegate(Card card) { return((a)card); });

            data.SetData(CLIPBOARD_CARDS_NAME, ListA);

            //cards as text
            int fields = 0;

            MemoryStream stream     = new MemoryStream();
            CardWriter   cardWriter = new CardWriter(stream, CardFileFormat.Format.TXT);
            StreamReader reader     = new StreamReader(stream);

            for (int i = 0; i < cardWriter.Fields.Length; i++)
            {
                //column order must be the same as fields order!!
                if (_decodeForm.CardsGrid.Columns[i].Visible)
                {
                    fields |= cardWriter.Fields[i];
                }
            }

            cardWriter.Write(null, cards, fields);

            stream.Seek(0, SeekOrigin.Begin);   // reset file pointer

            data.SetText(reader.ReadToEnd());

            //set data on clipboard
            try
            {
                Clipboard.SetDataObject(data);
            }
            catch (Exception)
            {
            }
        }
예제 #3
0
파일: CarWeigh.cs 프로젝트: Strongc/sencond
 private void ThreadWrite()
 {
     _writeCardDelegate = new CardWriter(WriteCard);
     Invoke(_writeCardDelegate);
 }