wince 简单的出入库系统开发总结
作者:互联网
本机win10 系统 安装VMWare 15 ; 环境搭建:win7-sp1 、 VS2008 、WINCE6.0_CHS_SDK.msi 、vpc2007setup.exe ;
-----卡顿是肯定的
wince 应用比较少,且好多功能被阉割,所以在开发中遇到不小的阻力。 创建智能设备项目。窗体等网上都有,略过不谈。
; 只谈在开发中遇到的技术难点。
VS2008 不支持DataGridView ,所以首先选择的是listview。 前期开发都很顺利。WINCE6.0_CHS_SDK虚拟机中 展示都很好。遇到的问题是不能编辑。 考虑解决的思路跟实际应用场景相符合。因为只会对一条数据做修改。所以监控选择的行,并监控键盘输入,将输入的值拼接后放在单元格内。在这里还是可行的,但是遇到跳行的问题(首列是UUID组成的id字段。开头如果是数字,并且键盘监控到输入的数字与id 首位数字相同就会出现跳行。考虑将id放在最后隐藏,首列使用空列并隐藏不过没有尝试。遇到的朋友可以先尝试再尝试我下面的解决方案);
构造datagrid
用datagrid 实现也是遇到不能编辑的问题。 然后考虑监控选择的行与键盘输入。实现代码如下。
int selectIndex = -1;
List<char> charBuffer = new List<char>();
private void dataGrid1_KeyPress(object sender, KeyPressEventArgs e)
{
int index = this.dataGrid1.CurrentRowIndex;
if (selectIndex == -1)
{
selectIndex = index;
}
else if (selectIndex != index)
{
charBuffer.Clear();
selectIndex = index;
}
char c = e.KeyChar;
if (char.IsDigit(c) || c == '.')
{
charBuffer.Add(c);
addContext(index);
}
else if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Space)
{
charBuffer.Clear();
addContext(index);
}
}
void addContext(int index)
{
if (index < 0)
{
return;
}
string outqt = new string(charBuffer.ToArray());
if (string.IsNullOrEmpty(outqt))
{
outqt = "0";
}
if (Double.Parse(outqt) > Double.Parse(this.dataGrid1[index, 4].ToString()))
{
MessageBox.Show("出库数量不能大于在库数量!");
return;
}
this.dataGrid1[index, 3] = outqt;
showAllList[index].outQt = outqt;
}
bool first = true;
void showDataGrid()
{
this.dataGrid1.PreferredRowHeight = 60;
DataTable dt = new DataTable("MainData");
dt.Columns.Add("id");
dt.Columns.Add("goodsId");
dt.Columns.Add("goodsName");
//dt.Columns.Add("outType");
dt.Columns.Add("outQt");
//dt.Columns.Add("inType");
//dt.Columns.Add("inQt");
dt.Columns.Add("storeQt");
//dt.Columns.Add("position");
//dt.Columns.Add("goodsPrice");
//dt.Columns.Add("goodsClassify");
dt.Columns.Add("specification");
//dt.Columns.Add("belongDepartment");
//dt.Columns.Add("parentdepartmant");
//dt.Columns.Add("deviceId");
//dt.Columns.Add("manageId");
//dt.Columns.Add("factoryNumber");
//dt.Columns.Add("masterUnit");
//dt.Columns.Add("type");
//dt.Columns.Add("storeStatus"); foreach (MainData data in this.showAllList)
Graphics g = this.dataGrid1.CreateGraphics();
Font font = new Font("Arial", 8, FontStyle.Regular);
for (int i = 0; i < showAllList.Count; i++)
{
DataRow row = dt.NewRow();
row["id"] = showAllList[i].id;
row["goodsId"] = Utils.returnStr(showAllList[i].goodsId, 40, g, font);
row["goodsName"] = Utils.returnStr(showAllList[i].goodsName, 70, g, font);
//row["outType"] = data.outType;
row["outQt"] = showAllList[i].outQt ?? "0";
//row["inType"] = data.inType;
//row["inQt"] = data.inQt ?? "0";
row["storeQt"] = showAllList[i].storeQt;
//row["position"] = data.position;
//row["goodsPrice"] = data.goodsPrice;
//row["goodsClassify"] = data.goodsClassify;
row["specification"] = Utils.returnStr(showAllList[i].specification, 70, g, font);
//row["belongDepartment"] = data.belongDepartment;
//row["parentdepartmant"] = data.parentdepartmant;
//row["deviceId"] = data.deviceId;
//row["manageId"] = data.manageId;
//row["factoryNumber"] = data.factoryNumber;
//row["masterUnit"] = data.masterUnit;
//row["type"] = data.type;
//row["storeStatus"] = data.storeStatus;
dt.Rows.Add(row);
}
this.dataGrid1.DataSource = dt;
if (first)
{
this.dataGrid1.TableStyles.Clear();
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = dt.TableName;
this.dataGrid1.TableStyles.Add(style);
style.GridColumnStyles.Clear();
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "序号", MappingName = "id", Width = 0 });
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "料号", MappingName = "goodsId", Width = 40 });
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "名称", MappingName = "goodsName", Width = 70 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "出库类型", MappingName = "outType", Width = 90 });
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "出", MappingName = "outQt", Width = 30 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "入库类型", MappingName = "inType", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "入", MappingName = "inQt", Width = 20 });
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "在库", MappingName = "storeQt", Width = 37 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "库位", MappingName = "position", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "价格", MappingName = "goodsPrice", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "分类", MappingName = "goodsClassify", Width = 90 });
style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "型号", MappingName = "specification", Width = 70 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "仓库", MappingName = "belongDepartment", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "部门", MappingName = "parentdepartmant", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "设备编号", MappingName = "deviceId", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "管理编号", MappingName = "manageId", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "出厂编号", MappingName = "factoryNumber", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "单位", MappingName = "masterUnit", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "类型", MappingName = "type", Width = 90 });
//style.GridColumnStyles.Add(new DataGridTextBoxColumn { HeaderText = "状态", MappingName = "storeStatus", Width = 90 });
first = false;
}
}
该段代码中 Utils.returnStr(showAllList[i].goodsName, 70, g, font); 是用于换行的,这就引出了遇到的另一个问题。 文本内容超长不换行。
其实此处要实现很简单,就是在文本超过网格线后添加‘\r\n’,即可。
借鉴了网上用到的方法然后改写后适合自己适用的场景,不过高度限制只能展示4-5 行,勉强够用。
该方法代码如下。
public static string returnStr(string str, int width, Graphics graphics, Font font)
{
// 此处宽度可以调整
char[] c = str.ToCharArray();
int clength = c.Length;
string[] strArry = new string[clength];
int widthWord = 0;
for (int i = 0; i < clength; i++)
{
string charstr = c[i].ToString().Trim();
widthWord += (int)graphics.MeasureString(charstr, font).Width;
if (widthWord >= width)
{
widthWord = 0;
strArry[i] = "\r\n" + charstr;
}
else
{
strArry[i] = charstr;
}
}
string st = String.Join("", strArry);
return st ;
}
这里datagrid 是可以带网格线的,但是在listview 中并不带网格线,需要自己画。 网上都能查到,也是借鉴后实现的,这里一并附上希望能帮到更多人。
// wince下 listview 创建 网格线 其中SetGridLines 属于静态方法,在类内部引用后F12 生成方法添加内容即可
private const int LVM_GETEXTENDEDLISTVIEWSTYLE = 0x1037;
private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1036;
private const int LVS_EX_GRIDLINES = 0x1;
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern int SendMessageW(int hWnd, int wMsg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern int GetFocus();
public static void SetGridLines(ListView listView)
{
listView.Focus();
int hWnd = GetFocus();
int extendedStyle = SendMessageW(hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
extendedStyle |= LVS_EX_GRIDLINES;
SendMessageW(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, extendedStyle);
}
需要注意 SetGridLines 是系统自带的需要生成才能起作用。
引用该方法的地方可以放在创建listview 之前使用。
用到的下拉框,就是数据源的绑定,因为都是操作对象所以代码量并不大。
this.comboBox1.DataSource = userProjectArray;
this.comboBox1.DisplayMember = "projectitemcode";
this.comboBox1.ValueMember = "projectitemcode";
以上就是全部内容。
标签:总结,style,出入库,Add,MappingName,wince,new,dt,row 来源: https://www.cnblogs.com/a6948076/p/11655753.html