聚水潭上传微信小店相关逻辑
This commit is contained in:
1 parent
625f4d9420
commit
b4fa5cacb1
26 files changed
+2570
-487
No files matched your search
@@ -9,6 +9,7 @@ using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -68,7 +69,7 @@ namespace TemuKJD.Extension
|
||||
checkBox.Enabled = true;
|
||||
|
||||
// Reset properties
|
||||
checkBox.Padding = new Padding(6,2,0,0);
|
||||
checkBox.Padding = new Padding(6, 2, 0, 0);
|
||||
checkBox.Margin = new Padding(0);
|
||||
checkBox.Text = "";
|
||||
|
||||
@@ -258,11 +259,11 @@ namespace TemuKJD.Extension
|
||||
bool isResize = false; // 是否已调整过表头
|
||||
|
||||
//合并列中某一列的列宽变化时,强制重绘表头
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
{
|
||||
if (colNameCollection.Contains(e.Column.Name))
|
||||
{
|
||||
foreach(var columnName in colNameCollection)
|
||||
foreach (var columnName in colNameCollection)
|
||||
{
|
||||
if (dgv.Columns.Contains(columnName))
|
||||
dgv.InvalidateCell(dgv.Columns[columnName].HeaderCell); // 标记单元格为需要重绘
|
||||
@@ -298,7 +299,7 @@ namespace TemuKJD.Extension
|
||||
//处理重绘事件,绘制合并表头和二级表头
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex == -1 && e.ColumnIndex >=0) // 重绘表头单元格及标题
|
||||
if (e.RowIndex == -1 && e.ColumnIndex >= 0) // 重绘表头单元格及标题
|
||||
{
|
||||
string name = dgv.Columns[e.ColumnIndex].Name;
|
||||
// 调整为复合表头
|
||||
@@ -465,7 +466,7 @@ namespace TemuKJD.Extension
|
||||
//处理重绘事件
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex >=0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
{
|
||||
string name = dgv.Columns[e.ColumnIndex].Name;
|
||||
if (colNameCollection.Contains(name))
|
||||
@@ -604,7 +605,7 @@ namespace TemuKJD.Extension
|
||||
{
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
{
|
||||
foreach(DataGridViewCell cell in cellLst)
|
||||
foreach (DataGridViewCell cell in cellLst)
|
||||
{
|
||||
if (cell.RowIndex == e.RowIndex && cell.ColumnIndex == e.ColumnIndex)
|
||||
{
|
||||
@@ -644,7 +645,7 @@ namespace TemuKJD.Extension
|
||||
//VerGridColorSelect = Color.FromArgb(129, 129, 129);
|
||||
selectColor = dgv.DefaultCellStyle.SelectionBackColor;
|
||||
//if ((dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected)
|
||||
if (cellLst.Any(c =>c.Selected))
|
||||
if (cellLst.Any(c => c.Selected))
|
||||
{
|
||||
//using (pen = new Pen(selectColor.Value))
|
||||
//{
|
||||
@@ -735,29 +736,55 @@ namespace TemuKJD.Extension
|
||||
|
||||
public static void AddImgColumn(this DataGridView dgv, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
{
|
||||
bool isScroll = false;
|
||||
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
};
|
||||
dgv.Resize += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (isScroll && 1 == 1)
|
||||
Thread.Sleep(1);
|
||||
isScroll = true;
|
||||
ShowDgvImg(dgv, dgv.Rows.Cast<DataGridViewRow>().ToList(), imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
isScroll = false;
|
||||
});
|
||||
};
|
||||
//dgv.Resize += (s, e) =>
|
||||
//{
|
||||
// ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//};
|
||||
dgv.Sorted += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
};
|
||||
dgv.RowsRemoved += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
};
|
||||
dgv.RowsAdded += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, new ConcurrentList<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (isScroll && 1 == 1)
|
||||
Thread.Sleep(1);
|
||||
isScroll = true;
|
||||
ShowDgvImg(dgv, dgv.Rows.Cast<DataGridViewRow>().ToList(), imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
isScroll = false;
|
||||
});
|
||||
};
|
||||
//dgv.RowsRemoved += (s, e) =>
|
||||
//{
|
||||
// ShowDgvImg(dgv, null, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//};
|
||||
//dgv.RowsAdded += (s, e) =>
|
||||
//{
|
||||
// ShowDgvImg(dgv, new List<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
//};
|
||||
dgv.RowPostPaint += (s, e) =>
|
||||
{
|
||||
ShowDgvImg(dgv, new ConcurrentList<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
if (e.RowIndex >= 0 && e.RowIndex < 25)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (isScroll && 1 == 1)
|
||||
Thread.Sleep(1);
|
||||
isScroll = true;
|
||||
ShowDgvImg(dgv, new List<DataGridViewRow> { dgv.Rows[e.RowIndex] }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
isScroll = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
dgv.CellValueChanged += (s, e) =>
|
||||
{
|
||||
@@ -767,79 +794,85 @@ namespace TemuKJD.Extension
|
||||
if (row.Cells[imgColumn].Value != null && row.Cells[imgColumn].Value != defaultBitmap)
|
||||
{
|
||||
row.Cells[imgColumn].Value = defaultBitmap;
|
||||
ShowDgvImg(dgv, new ConcurrentList<DataGridViewRow> { row }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (isScroll && 1 == 1)
|
||||
Thread.Sleep(1);
|
||||
isScroll = true;
|
||||
ShowDgvImg(dgv, new List<DataGridViewRow> { row }, imgColumn, imgPathColumn, isSetHttpsHttp);
|
||||
isScroll = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
public static Bitmap defaultBitmap = new Bitmap(1,1);
|
||||
static void ShowDgvImg(DataGridView dgv, ConcurrentList<DataGridViewRow> rowLst, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
|
||||
public static Bitmap defaultBitmap = new Bitmap(1, 1);
|
||||
static void ShowDgvImg(DataGridView dgv, List<DataGridViewRow> rowLst, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
{
|
||||
Task.Run(() =>
|
||||
if (rowLst == null)
|
||||
{
|
||||
if (rowLst == null)
|
||||
{
|
||||
rowLst = new ConcurrentList<DataGridViewRow>();
|
||||
rowLst.AddRange(dgv.Rows.Cast<DataGridViewRow>());
|
||||
}
|
||||
foreach (DataGridViewRow row in rowLst)
|
||||
rowLst = new List<DataGridViewRow>();
|
||||
rowLst.AddRange(dgv.Rows.Cast<DataGridViewRow>());
|
||||
}
|
||||
foreach (DataGridViewRow row in rowLst)
|
||||
{
|
||||
//if (row.Index <= 1)
|
||||
// continue;
|
||||
if (row.Displayed == false)
|
||||
{
|
||||
dgv.Invoke(new Action(() =>
|
||||
{
|
||||
if (row.Index > 1 && row.Cells[imgColumn].Displayed == false)
|
||||
{
|
||||
//dgv.Invoke(new Action(() =>
|
||||
//{
|
||||
try
|
||||
{
|
||||
if (row.Index > 0)
|
||||
row.Cells[imgColumn].Value = defaultBitmap;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
//}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (row.Index < 0)
|
||||
return;
|
||||
if (row.Index >= 0 && row.Cells[imgColumn]?.Value != null && row.Cells[imgColumn]?.Value != defaultBitmap)
|
||||
return;
|
||||
|
||||
Image image = defaultBitmap;
|
||||
if (row.Index >= 0)
|
||||
{
|
||||
string imgUrl = row.Cells[imgPathColumn]?.Value.ParseToString();
|
||||
if (isSetHttpsHttp == true)
|
||||
imgUrl = imgUrl.Replace("https://", "http://");
|
||||
string getImgError = "";
|
||||
if (!string.IsNullOrWhiteSpace(imgUrl))
|
||||
{
|
||||
image = GetHtml.GetUrlImg(imgUrl, out getImgError);
|
||||
if (!string.IsNullOrEmpty(getImgError))
|
||||
//BaseMsgForm.ShowError("图片加载失败 " + getImgError);
|
||||
image = TemuKJD.Properties.Resources.errpic;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//dgv.Invoke(new Action(() =>
|
||||
//{
|
||||
if (row.Index >= 0)
|
||||
{
|
||||
row.Cells[imgColumn].Value = image;
|
||||
}
|
||||
//}));
|
||||
if (row.Index >= 0 && row.Cells[imgColumn]?.Value != defaultBitmap)
|
||||
row.Cells[imgColumn].Value = defaultBitmap;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (row.Cells[imgColumn]?.Value == defaultBitmap || row.Cells[imgColumn]?.Value == null)
|
||||
{
|
||||
Image image = defaultBitmap;
|
||||
string imgUrl = row.Cells[imgPathColumn]?.Value.ParseToString();
|
||||
if (!string.IsNullOrWhiteSpace(imgUrl))
|
||||
{
|
||||
if (isSetHttpsHttp == true)
|
||||
imgUrl = imgUrl.Replace("https://", "http://");
|
||||
string getImgError = "";
|
||||
image = GetHtml.GetUrlImg(imgUrl, out getImgError);
|
||||
if (!string.IsNullOrEmpty(getImgError))
|
||||
//BaseMsgForm.ShowError("图片加载失败 " + getImgError);
|
||||
image = TemuKJD.Properties.Resources.errpic;
|
||||
}
|
||||
|
||||
dgv.Invoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (row.Index >= 0)
|
||||
{
|
||||
row.Cells[imgColumn].Value = image;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user