ExecuteDataRow() public static method

Executes a single SQL command and returns the first row of the resultset. A new MySqlConnection object is created, opened, and closed during this method.
public static ExecuteDataRow ( string connectionString, string commandText ) : DataRow
connectionString string Settings to be used for the connection
commandText string Command to execute
return DataRow
Ejemplo n.º 1
0
        public static PriceProcessItem TryToLoadPriceProcessItem(string filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                return(null);
            }

            uint priceItemId  = ParseId(filename);
            var  isDownloaded = IsDownloadedPrice(filename);

            if (priceItemId == 0)
            {
                return(null);
            }

            var drPriceItem = MySqlHelper.ExecuteDataRow(
                ConnectionHelper.GetConnectionString(),
                @"select distinct
  pc.PriceCode as PriceCode,
  if(pd.CostType = 1, pc.CostCode, null) CostCode,
  pc.PriceItemId,
  pd.ParentSynonym,
  pi.LastDownload
from (usersettings.pricescosts pc, usersettings.pricesdata pd)
	join usersettings.priceitems pi on pc.PriceItemId = pi.Id
where pc.PriceItemId = ?PriceItemId
	  and ((pd.CostType = 1) or (exists(select * from userSettings.pricesregionaldata prd where prd.PriceCode = pd.PriceCode and prd.BaseCost=pc.CostCode)))
	  and pd.PriceCode = pc.PriceCode
group by pi.Id",
                new MySqlParameter("?PriceItemId", priceItemId));

            if (drPriceItem == null)
            {
                return(null);
            }

            var priceCode     = Convert.ToUInt64(drPriceItem["PriceCode"]);
            var costCode      = (drPriceItem["CostCode"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drPriceItem["CostCode"]);
            var parentSynonym = (drPriceItem["ParentSynonym"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drPriceItem["ParentSynonym"]);
            var lastDownload  = (drPriceItem["LastDownload"] is DBNull) ? DateTime.MinValue : Convert.ToDateTime(drPriceItem["LastDownload"]);
            var item          = new PriceProcessItem(isDownloaded, priceCode, costCode, priceItemId, filename, parentSynonym);

            if (isDownloaded)
            {
                item.FileTime = lastDownload;
            }

            return(item);
        }
Ejemplo n.º 2
0
        public static Task <DataRow> ExecuteDataRowAsync(string connectionString, string commandText, CancellationToken cancellationToken, params MySqlParameter[] parms)
        {
            TaskCompletionSource <DataRow> taskCompletionSource = new TaskCompletionSource <DataRow>();

            if (cancellationToken == CancellationToken.None || !cancellationToken.IsCancellationRequested)
            {
                try
                {
                    DataRow result = MySqlHelper.ExecuteDataRow(connectionString, commandText, parms);
                    taskCompletionSource.SetResult(result);
                    goto IL_3F;
                }
                catch (Exception exception)
                {
                    taskCompletionSource.SetException(exception);
                    goto IL_3F;
                }
            }
            taskCompletionSource.SetCanceled();
IL_3F:
            return(taskCompletionSource.Task);
        }
Ejemplo n.º 3
0
 public static Task <DataRow> ExecuteDataRowAsync(string connectionString, string commandText, params MySqlParameter[] parms)
 {
     return(Task.Factory.StartNew <DataRow>(() => MySqlHelper.ExecuteDataRow(connectionString, commandText, parms)));
 }
Ejemplo n.º 4
0
        public void ResendPrice(WcfCallParameter paramDownlogId)
        {
            var downlogId = Convert.ToUInt64(paramDownlogId.Value);
            var drFocused = MySqlHelper.ExecuteDataRow(ConnectionHelper.GetConnectionString(),
                                                       @"
SELECT distinct
  logs.RowID as DRowID,
  logs.LogTime as DLogTime,
  logs.Addition as DAddition,
  logs.ArchFileName as DArchFileName,
  logs.ExtrFileName as DExtrFileName,
  sp.Name as DFirmName,
  r.Region as DRegion,
  if(pd.CostType = 1, concat('[Колонка] ', pc.CostName), pd.PriceName) as DPriceName,
  pim.Id as DPriceItemId,
  pd.PriceCode as DPriceCode,
  pd.ParentSynonym,
  if(pd.CostType = 1, pc.CostCode, null) DCostCode,
  st.Type as DSourceType,
  s.PricePath as DPricePath,
  s.EmailTo as DEmailTo,
  s.EmailFrom as DEmailFrom,
  s.ArchivePassword,
  pricefmts.FileExtention as DFileExtention
FROM
  logs.downlogs as logs,
  Customers.Suppliers sp,
  usersettings.pricesdata pd,
  usersettings.pricescosts pc,
  usersettings.PriceItems pim,
  farm.regions r,
  farm.sources s,
  farm.Sourcetypes st,
  farm.formrules fr,
  farm.pricefmts
WHERE
	pim.Id = logs.PriceItemId
and pc.PriceItemId = pim.Id
and pc.PriceCode = pd.PriceCode
and ((pd.CostType = 1) OR (exists(select * from userSettings.pricesregionaldata prd where prd.PriceCode = pd.PriceCode and prd.BaseCost=pc.CostCode)))
and sp.Id = pd.firmcode
and r.regioncode = sp.HomeRegion
and s.Id = pim.SourceId
and st.Id = s.SourceTypeId
and logs.ResultCode in (2, 3)
and fr.Id = pim.FormRuleId
and pricefmts.id = fr.PriceFormatId
and logs.Rowid = ?DownLogId",
                                                       new MySqlParameter("?DownLogId", downlogId));

            var filename = GetFileFromArhive(downlogId);
            var sourceArchiveFileName = filename;
            var archFileName          = drFocused["DArchFileName"].ToString();
            var externalFileName      = drFocused["DExtrFileName"].ToString();
            var extractedFile         = string.Empty;

            try {
                if (drFocused["DSourceType"].ToString().Equals("EMAIL", StringComparison.OrdinalIgnoreCase))
                {
                    // Если файл пришел по e-mail, то это должен быть файл *.eml, открываем его на чтение
                    filename      = ExtractFileFromAttachment(filename, archFileName, externalFileName);
                    extractedFile = filename;
                }
                var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(archFileName));
                if (ArchiveHelper.IsArchive(filename))
                {
                    if (File.Exists(tempDirectory))
                    {
                        File.Delete(tempDirectory);
                    }
                    if (Directory.Exists(tempDirectory))
                    {
                        Directory.Delete(tempDirectory, true);
                    }
                    Directory.CreateDirectory(tempDirectory);
                    ArchiveHelper.Extract(filename, externalFileName, tempDirectory, drFocused["ArchivePassword"].ToString());
                    filename = FileHelper.FindFromArhive(tempDirectory, externalFileName);
                    if (String.IsNullOrEmpty(filename))
                    {
                        var errorMessage = String.Format(
                            "Невозможно найти файл {0} в распакованном архиве!", externalFileName);
                        throw new FaultException <string>(errorMessage, new FaultReason(errorMessage));
                    }
                }

                if (String.IsNullOrEmpty(filename))
                {
                    return;
                }

                var priceExtention  = drFocused["DFileExtention"].ToString();
                var destinationFile = Path.Combine(Settings.Default.InboundPath,
                                                   "d" + drFocused["DPriceItemId"] + "_" + downlogId + priceExtention);

                if (File.Exists(destinationFile))
                {
                    throw new FaultException <string>(MessagePriceInQueue,
                                                      new FaultReason(MessagePriceInQueue));
                }

                File.Copy(filename, destinationFile);

                var item = new PriceProcessItem(true,
                                                Convert.ToUInt64(drFocused["DPriceCode"].ToString()),
                                                (drFocused["DCostCode"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drFocused["DCostCode"].ToString()),
                                                Convert.ToUInt64(drFocused["DPriceItemId"].ToString()),
                                                destinationFile,
                                                (drFocused["ParentSynonym"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drFocused["ParentSynonym"].ToString()));
                PriceItemList.AddItem(item);

                var priceItemId = Convert.ToUInt64(drFocused["DPriceItemId"]);
                downlogId = LogResendPriceAsDownload(priceItemId, archFileName, externalFileName, paramDownlogId.LogInformation);
                if (downlogId > 0)
                {
                    destinationFile = Path.Combine(Settings.Default.HistoryPath,
                                                   downlogId + Path.GetExtension(sourceArchiveFileName));
                    File.Copy(sourceArchiveFileName, destinationFile);
                }
                if (Directory.Exists(tempDirectory))
                {
                    FileHelper.Safe(() => Directory.Delete(tempDirectory, true));
                }
            }
            finally {
                if (File.Exists(extractedFile))
                {
                    File.Delete(extractedFile);
                }
            }
        }