功能实现:
机械单价包含三个部分:一个是机械单价分类,一个是机械单价,一个是机械单价明细。机械分类的是一个下拉树,可以对其进行新增,删除和修改它的节点。当点击机械分类时,机械单价会出现相应的数据。
机械单价数据处理包括添加、修改、删除、复制、粘贴、导入、导出 。
对于机械单价的导出、导入:系统将自动给出一个路径,把机械单价的所有数据导入到一张Excel表。导入:先手动填写一些数据,这些数据要根据数据库的参数来写,一一对应才能导入到
机械单价的表里。导入之前先选择要导入的文件。
机械单价的点击一下机械单价的添加、会弹出一张表,进行添加。而修改、 是在datagrid里面操作的。
机械单价的复制、粘贴:复制现有的数据,复制后的数据代号后会有”复制“两字,还有整数进行区分。然后进行粘贴到最后一行。
机械单价的查询分为多条件模糊查询和多条件精确查询:查询分为:根据代号、名称、名称的首字母查询,当选中下拉框方式中的代号,如果不选中模糊先查询,则为精确查询,反之,则为模糊查询。
如果是被使用过的数据就会记录下来,你可以根据是否显示已使用来查询使用过的数据。
//一进去就查询绑定机械单价的方法
第一步:查询全部机械单价
第二步:查询全部机械单价逻辑层
public DataTable inquiremachineryunitpriceall(int Int_BuildProjectID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@BuildProjectID",SqlDbType.Int),
};
mySQL[0].Value = "inquiremachineryunitpriceall";
mySQL[1].Value = Int_BuildProjectID;
DataTable dt = niaho.DAL_SelectDB_Par("JiXieDanJia", mySQL);
return dt;
}
第三步:查询全部机械单价:控制器
public ActionResult inquiremachineryunitpriceall(string Int_BuildProjectID)
{
DataTable dt = niaho.inquiremachineryunitpriceall(Convert.ToInt32(Int_BuildProjectID));
List<Dictionary<string, object>> listReturn = ConvertHelper.DtToList(dt);
return Json(listReturn, JsonRequestBehavior.AllowGet);
}
第四步:查询全部机械单价:界面层
function BandinJixieDanJa(){
$.getJSON("/JiXieDanJia/inquiremachineryunitpriceall?Int_BuildProjectID=" + @Session["项目ID"]+"&"
,
function (data) {
$('#w机械单价').datagrid('loadData', data);
});
}
下面就是点击下拉树查询机械单价的代码:
第一步;点击下拉树查询机械单价的存储过程第二步:点击下拉树查询机械单价。逻辑层
public DataTable tongguoChaXunShuXingjiedian(int BuildProjectID, int MachineryPriceClassesID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@BuildProjectID",SqlDbType.Int),
new SqlParameter("@MachineryPriceClassesID",SqlDbType.Int),
};
mySQL[0].Value = "tongguoChaXunShuXingjiedian";
mySQL[1].Value = BuildProjectID;
mySQL[2].Value = MachineryPriceClassesID;
DataTable dt = niaho.DAL_SelectDB_Par("JiXieDanJia", mySQL);
return dt;
}
第三步:点击下拉树查询机械单价。控制器
public ActionResult tongguoChaXunShuXingjiedian(string BuildProjectID, string MachineryPriceClassesID)
{
DataTable dt = niaho.tongguoChaXunShuXingjiedian(Convert.ToInt32(BuildProjectID), Convert.ToInt32(MachineryPriceClassesID));//这就是调用逻辑层的方法
List<Dictionary<string, object>> listReturn = ConvertHelper.DtToList(dt);
return Json(listReturn, JsonRequestBehavior.AllowGet);
}
第四步:点击下拉树查询机械单价。界面层
function onClickRowMingXi(index) {
$.getJSON("/JiXieDanJia/tongguoChaXunShuXingjiedian?BuildProjectID=" + @Session["项目ID"]+"&"
+"MachineryPriceClassesID="+index.id+"&",
function (data) {
$('#w机械单价').datagrid('loadData', data); //这就是绑定数据给相应的datagrid
$('#w机械组成').datagrid('loadData',{total:0,rows:[]}); //这就是清空datagrid
});
}
//下面就是多条件查询:就以多条件的拼音码精确查询和模糊查询为例,其他多条件查询不写了
第一步:多条件查询存储过程,精确、模糊:
这是多条件的模糊查询:
下面就是精确查询的代码:
第二步:多条件查询、逻辑层
下面就是模糊、逻辑层
public DataTable JiXieDanJiashouzimuChaXun(int MachineryPriceClassesFurID, bool chcke, string guanjianzichanxun,int ID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@MachineryPriceClassesID",SqlDbType.Int),
new SqlParameter("@effectivityno",SqlDbType.Bit),
new SqlParameter("@Pinyincode",SqlDbType.Char),
new SqlParameter("@BuildProjectID",SqlDbType.Int),
};
mySQL[0].Value = "JiXieDanJiashouzimuChaXun";
mySQL[1].Value = MachineryPriceClassesFurID;
mySQL[2].Value = chcke;
mySQL[3].Value = guanjianzichanxun;
mySQL[4].Value = ID;
DataTable dt = niaho.DAL_SelectDB_Par("JiXieDanJia", mySQL);
return dt;
}
下面就是多条件,精确查询、逻辑层
public DataTable jingqueJiXieDanJiashouzimuChaXun(int MachineryPriceClassesFurID, bool chcke, string guanjianzichanxun,int ID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@MachineryPriceClassesID",SqlDbType.Int),
new SqlParameter("@effectivityno",SqlDbType.Bit),
new SqlParameter("@Pinyincode",SqlDbType.Char),
new SqlParameter("@BuildProjectID",SqlDbType.Int),
};
mySQL[0].Value = "jingqueJiXieDanJiashouzimuChaXun";
mySQL[1].Value = MachineryPriceClassesFurID;
mySQL[2].Value = chcke;
mySQL[3].Value = guanjianzichanxun;
mySQL[4].Value = ID;
DataTable dt = niaho.DAL_SelectDB_Par("JiXieDanJia", mySQL);
return dt;
}
第三步:控制器:多条件模糊和精确查询
下面就是模糊查询控制器的代码
public ActionResult JiXieDanJiashouzimuChaXun(string MachineryPriceClassesFurID, string chcke, string guanjianzichanxun,string ID)
{
DataTable dt = niaho.JiXieDanJiashouzimuChaXun(Convert.ToInt32(MachineryPriceClassesFurID), Convert.ToBoolean(chcke), guanjianzichanxun,Convert.ToInt32(ID));//这是调用逻辑层的代码
List<Dictionary<string, object>> listReturn = ConvertHelper.DtToList(dt);
return Json(listReturn, JsonRequestBehavior.AllowGet);
}
下面就是精确查询的代码
public ActionResult jingqueJiXieDanJiashouzimuChaXun(string MachineryPriceClassesFurID, string chcke, string guanjianzichanxun,string ID)
{
DataTable dt = niaho.jingqueJiXieDanJiashouzimuChaXun(Convert.ToInt32(MachineryPriceClassesFurID), Convert.ToBoolean(chcke), guanjianzichanxun,Convert.ToInt32(ID));//这是调用逻辑层的代码
List<Dictionary<string, object>> listReturn = ConvertHelper.DtToList(dt);
return Json(listReturn, JsonRequestBehavior.AllowGet);
}
第四步:多条件精确和模糊查询界面层代码
function ww(){
$('#w机械组成').datagrid('loadData',{total:0,rows:[]});
var r=document.getElementById("chaxun");//这是判断是否勾上模糊,如果勾上就进行模糊查询
if(r.checked==true){ //这是判断是否勾上模糊,如果勾上就进行模糊查询
var e = $('#TreShuXing').tree('getSelected');//这是判断是否选中节点
if(e){
$.getJSON("/JiXieDanJia/JiXieDanJiashouzimuChaXun?MachineryPriceClassesFurID=" + e.id + "&"
+"chcke="+ document.getElementById("yishiyong").checked+"&"
+"guanjianzichanxun="+$('#guanjianzichanxun').val()+"&"
+"ID="+ @Session["项目ID"]+"&",
function (data) {
$('#w机械单价').datagrid('loadData', data);
});
}
else{
$.getJSON("/JiXieDanJia/JiXieDanJiashouzimuChaXun1?chcke="+ document.getElementById("yishiyong").checked+"&"
+"ID="+ @Session["项目ID"]+"&"
+"guanjianzichanxun="+$('#guanjianzichanxun').val(),
function (data) {
$('#w机械单价').datagrid('loadData', data);
});
}
}else{//否则就进行精确查询
var e = $('#TreShuXing').tree('getSelected');//这也是判断是否选中节点
if(e){
$.getJSON("/JiXieDanJia/jingqueJiXieDanJiashouzimuChaXun?MachineryPriceClassesFurID=" + e.id + "&"
+"chcke="+ document.getElementById("yishiyong").checked +"&"
+"guanjianzichanxun="+$('#guanjianzichanxun').val()+"&"
+"ID="+ @Session["项目ID"],
function (data) {
$('#w机械单价').datagrid('loadData', data); //这就是绑定给相应的datagrid
});
}
else{
$.getJSON("/JiXieDanJia/jingqueJiXieDanJiashouzimuChaXun1?chcke="+ document.getElementById("yishiyong").checked +"&"
+"ID="+ @Session["项目ID"]+"&"
+"guanjianzichanxun="+$('#guanjianzichanxun').val(),
function (data) {
$('#w机械单价').datagrid('loadData', data); //这是绑定数据给相应的datagrid
});
}
}
}
//下面就是选中节点,点击添加弹出的窗体
下面就是添加机械单价的方法;
第一步:添加机械单价存储过程
第二步:添加机械单价逻辑层
public int Insertmachineryunitprice(int intID, int intMachineryPriceClassesFurID, string strcode, string strunit, string strname, string strremark, string mySt)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@BuildProjectID",SqlDbType.Int),
new SqlParameter("@MachineryPriceClassesID",SqlDbType.Int),
new SqlParameter("@Code",SqlDbType.Char),
new SqlParameter("@Unit",SqlDbType.Char),
new SqlParameter("@Name",SqlDbType.Char),
new SqlParameter("@Remark",SqlDbType.Char),
new SqlParameter("@Pinyincode",SqlDbType.Char),
};
mySQL[0].Value = "InsertJiXieDanJia";
mySQL[1].Value = intID;
mySQL[2].Value = intMachineryPriceClassesFurID;
mySQL[3].Value = strcode;
mySQL[4].Value = strunit;
mySQL[5].Value = strname;
mySQL[6].Value = strremark;
mySQL[7].Value = mySt;
int i = niaho.DAL_OPTableDB_Par("JiXieDanJia", mySQL);
return i;
}
第三步:添加机械单价控制器
string strText;
public ContentResult Insertmachineryunitprice(string intID, string intMachineryPriceClassesFurID, string strcode, string strunit, string strname, string strremark)
{
strText = strname;
GetChineseSpell(strText);//这是调了下面的方法,生成拼音码
int i = niaho.Insertmachineryunitprice(Convert.ToInt32(intID), Convert.ToInt32(intMachineryPriceClassesFurID), strcode, strunit, strname, strremark, mySt);//这是调用逻辑层的代码
string k = i.ToString();
return Content(k);
}
//生成拼音码的代码
string mySt = "";
public string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
mySt = myStr;
}
return myStr;
}
/// <summary>
/// 把提取的字母变成大写
/// </summary>
/// <param name="strText">需要转换的字符串</param>
/// <returns>转换结果</returns>
public string GetLowerChineseSpell(string strText)
{
return GetChineseSpell(strText).ToLower();
}
/// <summary>
/// 把提取的字母变成大写
/// </summary>
/// <param name="myChar">需要转换的字符串</param>
/// <returns>转换结果</returns>
public string GetUpperChineseSpell(string strText)
{
return GetChineseSpell(strText).ToUpper();
}
/// <summary>
/// 获取单个汉字的首拼音
/// </summary>
/// <param name="myChar">需要转换的字符</param>
/// <returns>转换结果</returns>
public string getSpell(string myChar)
{
byte[] arrCN = System.Text.Encoding.Default.GetBytes(myChar);
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
return System.Text.Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "_";
}
else return myChar;
}
//第四步:界面层的代码
function btnaddmachineryunitprice(){
var e = $('#TreShuXing').tree('getSelected');//这是获取选中的节点,选中了节点才能添加
if(e){
$.getJSON("/JiXieDanJia/Insertmachineryunitprice?intID="+ @Session["项目ID"]+"&"
+"intMachineryPriceClassesFurID="+e.id+"&"
+"strcode="+$('#txtcode').val()+"&"
+"strunit="+ $('#unit').combobox('getValue') +"&"
+"strname="+ $('#txtname').val() +"&"
+"strremark="+$('#txtremark').val()+"&"
,
function(data){
$('#txtcode').val("");//添加成功,就要清空文本
$('#unit').combobox('setValue',"");
$('#txtname').val("");
$('#txtremark').val("");
alert("添加成功");
$.getJSON("/JiXieDanJia/tongguoChaXunShuXingjiedian?BuildProjectID=" + @Session["项目ID"]+"&"
+"MachineryPriceClassesID="+ID+"&",
function (data) { //添加成功,就对数据进行一遍查询
$('#w机械单价').datagrid('loadData', data); //把数据绑定给相应的datagrid
$('#w机械组成').datagrid('loadData',{total:0,rows:[]}); //查询了一遍数据就要对数据进行一遍清空
});
$('#dialog').window('close'); //最后就把窗体给关闭
});
}else{
alert("请选中节点");
}
}
接下来就是机械单价删去的代码
第一步;删去机械单价存储过程
第二步:删去机械单价逻辑层
public int deleteunitprice(int IntMachineryPriceID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@MachineryPriceID",SqlDbType.Int),
};
mySQL[0].Value = "deleteunitprice";
mySQL[1].Value = IntMachineryPriceID;
int i = niaho.DAL_OPTableDB_Par("JiXieDanJia", mySQL);
return i;
}
遍历删去机械明细、逻辑层
public int deletemachinerydetailed(int Int_MachineryPriceID)
{
SqlParameter[] mySQL = {
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@MachineryComeposeID",SqlDbType.Char),
};
mySQL[0].Value = "deletemachinerydetailed";
mySQL[1].Value = Int_MachineryPriceID;
int i = niaho.DAL_OPTableDB_Par("JiXieDanJia", mySQL);
return i;
}
第三步:删去机械单价控制器代码
public ContentResult deleteunitprice(string IntMachineryPriceID)
{
int i = niaho.deleteunitprice(Convert.ToInt32(IntMachineryPriceID));//这是调用逻辑层的代码
string k = i.ToString();
return Content(k);
}
遍历删去机械明细:控制器代码
public ContentResult deletemachinerydetailed(string Int_MachineryPriceID)
{
int i = niaho.deletemachinerydetailed(Convert.ToInt32(Int_MachineryPriceID));//这是调用逻辑层的代码
string k = i.ToString();
return Content(k);//返回给界面层
}
第四步:删去机械单价和遍历删去机械明细,界面层代码
function deleteline(){
var JiXie = $('#w机械单价').datagrid('getSelected');//选中一行
var e = $('#TreShuXing').tree('getSelected'); //选中一行下拉树
if(e){ //判断选中下拉树才能才能执行删去 $.getJSON("/JiXieDanJia/deleteunitprice?IntMachineryPriceID="+JiXie.MachineryPriceID+"&",
function(data){//这是删去机械单价
for( var i=0;i< $('#w机械组成').datagrid('getData').rows.length;i++){
$.getJSON("/JiXieDanJia/deletemachinerydetailed?Int_MachineryPriceID="+ $('#w机械组成').datagrid('getData').rows[i].MachineryComeposeID+"&",
function(data){ //这是遍历删去机械明细
$('#w机械组成').datagrid('loadData',{total:0,rows:[]});
});
}
alert("删去成功");
$.getJSON("/JiXieDanJia/tongguoChaXunShuXingjiedian?BuildProjectID=" + @Session["项目ID"]+"&"
+"MachineryPriceClassesID="+ID+"&",
function (data) {//这是进行一遍查询
$('#w机械单价').datagrid('loadData', data);
});
});
}else{
alert("请选择下拉树");
}
}
仅供学习,禁止用于商业用途