呵呵--到哪哪闲?
先用一周时间熟悉下一期的项目。。。。
1。。汇总相关资料
::::::::::::建crm客户关系管理10-4-22。
2。。为treeview动态(在webconfig中)设置跳转地址。
aspx::: <div id="navigateTree">
<asp:TreeView ID="TreeView1" runat="server" Height="515px" ImageSet="Arrows" >
<ParentNodeStyle Font-Bold="True" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding="0px" Font-Bold="False" Font-Overline="False"/>
<Nodes>
<asp:TreeNode Text="标准报价规则" Value="标准报价规则" Expanded="False">
<asp:TreeNode NavigateUrl="~/UI/Quotation/FromZone.aspx" Target="main" Text="始发区域"
Value="始发区域"></asp:TreeNode>
<asp:TreeNode Text="目的区域" Value="目的区域" NavigateUrl="~/UI/Quotation/ToZone.aspx"
Target="main"></asp:TreeNode>
<asp:TreeNode Text="始发地/目的地分区" Value="始发地/目的地分区"
NavigateUrl="~/UI/Quotation/FromToZone.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="服务类别" Value="服务类别" NavigateUrl="~/UI/Quotation/Service.aspx"
Target="main"></asp:TreeNode>
<asp:TreeNode Text="标准报价" Value="标准报价"
NavigateUrl="~/UI/Quotation/RateDetail.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="导出标准报价记录" Value="导出标准报价记录"
NavigateUrl="~/UI/Quotation/ExportQuotation.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="导入标准报价记录" Value="导入标准报价记录"
NavigateUrl="~/UI/Quotation/ImportQuotation.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="导出DOC标准格式报价报表" Value="导出报价报表"
Target="_blank"></asp:TreeNode>
<asp:TreeNode Text="导出DOC明细格式报价报表" Value="导出DOC明细格式报价报表"
Target="_blank"></asp:TreeNode>
<asp:TreeNode Text="导出SPS标准格式报价报表" Value="导出SPS标准格式报价报表"
Target="_blank"></asp:TreeNode>
<asp:TreeNode Text="导出SPS明细格式报价报表" Value="导出SPS明细格式报价报表"
Target="_blank"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="折扣计算规则" Value="折扣计算规则" Expanded="False">
<asp:TreeNode Text="折扣模板" Value="折扣模板"
NavigateUrl="~/UI/Discount/DiscTemplateQuery.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="设置客户折扣模板" Value="设置客户折扣模板"
NavigateUrl="~/UI/Discount/SetAccountDiscountTemplate.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="导出折扣计算规则记录" Value="导出折扣计算规则记录"
NavigateUrl="~/UI/Discount/ExportDiscountRule.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="导入折扣计算规则记录" Value="导入折扣计算规则记录"
NavigateUrl="~/UI/Discount/ImportDiscountRule.aspx" Target="main"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="附加费计算规则" Value="附加费计算规则" Expanded="False">
<asp:TreeNode Text="附加费模板" Value="附加费模板"
NavigateUrl="~/UI/Surcharge/SurchargeTemplate.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="附加费规则" Value="附加费规则"
NavigateUrl="~/UI/Surcharge/SurchargeRule.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="附加费模板与附加费规则关系" Value="附加费模板与附加费规则关系"
NavigateUrl="~/UI/Surcharge/SurchargeTemplateRule.aspx" Target="main"></asp:TreeNode>
<asp:TreeNode Text="设置客户附加费模板" Value="设置客户附加费模板"
NavigateUrl="~/UI/Surcharge/SetAccountSurchargeTemplate.aspx" Target="main"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</div>
cs:::
{
if (!IsPostBack)
{
//动态设置TreeView节点的URL
SetDynamURL(TreeView1.Nodes);
}
}
/// <summary>
/// 遍历TreeView,设置字节点的URL
/// </summary>
/// <param name="tc"></param>
protected void SetDynamURL(TreeNodeCollection tc)
{
//递归遍历TreeView的所有节点 foreach (TreeNode node in tc)
{
if (node.Text == "导出DOC标准格式报价报表")
{
node.NavigateUrl = ConfigurationManager.AppSettings["PCReport_DOC_1_URL"].ToString();
}
if (node.Text == "导出DOC明细格式报价报表")
{
node.NavigateUrl = ConfigurationManager.AppSettings["PCReport_DOC_2_URL"].ToString();
}
if (node.Text == "导出SPS标准格式报价报表")
{
node.NavigateUrl = ConfigurationManager.AppSettings["PCReport_SPS_1_URL"].ToString();
}
if (node.Text == "导出SPS明细格式报价报表")
{
node.NavigateUrl = ConfigurationManager.AppSettings["PCReport_SPS_2_URL"].ToString();
}
SetDynamURL(node.ChildNodes);
}
}
webconfig:
<appSettings>
<add key="OCS_HQ" value="OCS, OCS-SINOTRANS"/>
<add key="neiqin" value="销售内勤"/>
<add key="guanliyuan" value="管理员"/>
<add key="PCReport_DOC_1_URL" value="http://192.168.100.136/ReportServer/Pages/ReportViewer.aspx?%
2fOCS_MSCRM%2f%e6%a0%87%e5%87%86%e8%b4%b9%e7%8e%87%e8%a1%a8(DOC)&rs:Command=Render"/>
<add key="PCReport_DOC_2_URL" value="http://192.168.100.136/ReportServer/Pages/ReportViewer.aspx?%
2fOCS_MSCRM%2f%e6%98%8e%e7%bb%86%e8%b4%b9%e7%8e%87%e8%a1%a8(DOC)&rs:Command=Render"/>
<add key="PCReport_SPS_1_URL" value="http://192.168.100.136/ReportServer/Pages/ReportViewer.aspx?%
2fOCS_MSCRM%2f%e6%a0%87%e5%87%86%e8%b4%b9%e7%8e%87%e8%a1%a8(SPS)&rs:Command=Render"/>
<add key="PCReport_SPS_2_URL" value="http://192.168.100.136/ReportServer/Pages/ReportViewer.aspx?%
2fOCS_MSCRM%2f%e6%98%8e%e7%bb%86%e8%b4%b9%e7%8e%87%e8%a1%a8(SPS)&rs:Command=Render"/>
<add key="ExportPath" value="~/UI/Files/"/>
<add key="ImportPath" value="~/UI/Files/"/>
<add key="QuotationTemplatePath" value="~/UI/template/标准报价导入模板.xlt"/>
<add key="DiscountTemplatePath" value="~/UI/template/折扣导入模板.xlt"/>
<add key="CrmWebServies" value="http://192.168.0.230:5555/mscrmservices/2006/crmservice.asmx"/>
</appSettings>
3...js隐藏显示::
<script type="text/javascript">
var hideNavigateBar = 0;
function swapNavigate()
{
if(hideNavigateBar==0)
{
hideNavigateBar=1;
document.getElementById("navigateTree").style.display="none";
document.getElementById("swapNavigateSpan").innerText="显示导航栏";
}
else
{
hideNavigateBar=0;
document.getElementById("navigateTree").style.display="block";
document.getElementById("swapNavigateSpan").innerText="隐藏导航栏";
}
}
</script>
<span onclick="swapNavigate()" id="swapNavigateSpan" style="cursor:hand;">隐藏导航栏</span>
4。。。当参数是类时,在方法体类改变了类的属性,外界是否能够看到。。。能看到
《我之前的代码有个地方多余了。。就是当给facade 传入一个parameter参数时,再返回一个parameter。。不用另外定义一个新的
parameter。直接读取传入的parameter的对应属性就可以了》
5..当项目中有自定义 的异常类时,在得到异常的地方,抛出自定义的异常
6。。 为txtbox添加 回车按钮触发事件!
this.TextBox1.Attributes.Add("onkeydown", string.Format("javascript:if (13 == window.event.keyCode){{{0};return
false;}}", this.ClientScript.GetPostBackEventReference(this.Button1, "")));
7。。。取得datatable后先排序,再赋值给gridview::
//如果param.GridViewDataSource的行数大于0
if (param.GridViewDataSource != null)
{
//判断gridview的sort顺序,如果sort顺序不是空 if (!string.Empty.Equals(param.SortExp))
{
//给grid的sort顺序赋值 ///indate desc param.GridViewDataSource.DefaultView.Sort =
param.SortExp + " " + param.SortType;
}
//给Gridview绑定数据源 grvToZone.DataSource = param.GridViewDataSource.DefaultView;
}
8..把一些公共信息统一放到一个message类中。如
public class Consts
{
/// <summary>
/// Declare messages
/// </summary>
public class Messages
{
//公共信息
public const string M_Common_001 = "新增成功!<br>";
public const string M_Common_002 = "新增失败!<br>";
public const string M_Common_003 = "修改成功!<br>";
public const string M_Common_004 = "修改失败!<br>";
public const string M_Common_005 = "删除成功!<br>";
public const string M_Common_006 = "删除失败!<br>";
public const string M_ImportCommon_001 = "文件上传成功!<br>";
public const string M_ImportCommon_002 = "文件上传失败!<br>";
public const string M_ImportCommon_003 = "请确认上传的是Excel文件!<br>";
public const string M_ImportCommon_004 = "请选择要上传的文件!<br>";
public const string M_ImportCommon_005 = "请选择始发区域!<br>";
//Service画面
public const string M_Service_001 = "服务类别名称不能超过10个字符!<br>";
public const string M_Service_002 = "服务类别编号不能超过10个字符!<br>";
public const string M_Service_003 = "请输入必输项!<br>";
public const string M_Service_004 = "输入的服务类别编号已经存在!<br>";
public const string M_Service_005 = "输入的服务类别编号已被标记删除!请在数据库层修改!<br>";
public const string M_Service_006 = "输入的服务类别名称已经存在!<br>";
public const string M_Service_007 = "服务类别编号必须输入英文或数字!<br>";
public const string M_Service_008 = "请输入服务类别名称!<br>";
public const string M_Service_009 = "请输入服务类别编号!<br>";
public const string M_Service_010 = "该服务类别正在被使用,不能被删除!<br>";
public const string M_Service_011 = "输入的服务类别名称已被标记删除!请在数据库层修改!<br>";
}
public class SessionKeys
{
//通用保存状态
public const string SaveState = "SaveState";
//Service画面
public const string Service_ParameterName = "Service_ParameterName";
//FromToZone画面
public const string FromToZone_ParameterName = "FromToZone_ParameterName";
//ExportQuotation画面
public const string ExportQuotation_ParameterName = "ExportQuotation_ParameterName";
//ImportQuotation画面
public const string ImportQuotation_ParameterName = "ImportQuotation_ParameterName";
//ExportReport画面
public const string ExportReport_ParameterName = "ExportReport_ParameterName";
//DiscTemplateQuery画面
public const string DiscTemplateQuery_ParameterName = "DiscTemplateQuery_ParameterName";
//DiscTemplateMaintenance画面
public const string DiscTemplateMaintenance_ParameterName = "DiscTemplateMaintenance_ParameterName";
//导入前判断用户是否有权限
public const string purview = "销售内勤";
}
/// <summary>
/// 判断用户是否有权限访问该页面
/// </summary>
/// <param name="PageID">页面编号</param>
/// <returns></returns>
public static bool LimitUser(string userName)
{
bool bolRight = false;
ParameterFromZone param = new ParameterFromZone();
FacadeFromZone facade = new FacadeFromZone();
param.UserName = userName;
facade.QueryForRoleName(param);
if (param.droptable.Rows.Count > 0)
{
string itemCount = param.droptable.Rows[0][0].ToString();
if (itemCount.Equals("0"))
{
bolRight = false;
}
else
{
bolRight = true;
}
}
return bolRight;
}
public class SortAsc
{
#region private construtor
private SortAsc()
{
}
#endregion
public const string Ascend = "ASC";
public const string Descend = "DESC";
}
}
9。。。显示一个模态窗体
function showWin1()
{
window.showModalDialog("RateCategorySet.aspx", window,
"dialogWidth=460px;dialogHeight=350px;dialogLeft=100px;dialogTop=100px");
//location.reload("RateDetail.aspx");
document.form1.action="RateDetail.aspx";
document.form1.submit();
}
10:构造一个临时表:
/// <summary>
/// 获得数据
/// </summary>
/// <returns></returns>
public DataTable getData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id", typeof(Int32)));
dt.Columns.Add(new DataColumn("name", typeof(String)));
for (int i = 1; i < 6; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "name" + i;
dt.Rows.Add(dr);
}
return dt;
}
11。。导出为excel引用的Interop.excel.dll
using System.IO;
/// <summary>
/// 测试导出数据
/// </summary>
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bindData();
}
/// <summary>
/// 绑定gridview
/// </summary>
public void bindData()
{
this.GridView1.DataSource = this.getData();
this.GridView1.DataBind();
}
/// <summary>
/// 获得数据
/// </summary>
/// <returns></returns>
public DataTable getData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id", typeof(Int32)));
dt.Columns.Add(new DataColumn("name", typeof(String)));
for (int i = 1; i < 6; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "name" + i;
dt.Rows.Add(dr);
}
return dt;
}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
ExportExcel(this.getData());
}
/// <summary>
/// 导出Excel的方法
/// </summary>
/// <param name="path"></param>
private void ExportExcel(DataTable dt)
{
object missing = System.Reflection.Missing.Value;
//打开Excel模板文件
string modileFileName = @"D:\\test.xls";//模板文件名称
FileInfo fileExcel = new FileInfo(modileFileName);
//copy模板文件到新的文件中,并设置其属性可以更改
string newPath = fileExcel.CopyTo("d:\\temp.xls", true).FullName;
FileInfo newFile = new FileInfo(newPath);
newFile.IsReadOnly = false;
//打开新文件
Excel.Application ExcelApp = new Excel.Application();
Excel.Workbook ExcelWorkBook = ExcelApp.Application.Workbooks.Open(newPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
//将打开的Excel隐藏
ExcelApp.Visible = false;
//重命名一个sheet
Excel.Worksheet ExcelWorkSheet1 = (Excel.Worksheet)ExcelWorkBook.Worksheets[1];
ExcelWorkSheet1.Name = "用户数据";
//继续添加类似
//Excel.Worksheet ExcelWorkSheet2 = (Excel.Worksheet)ExcelWorkBook.Worksheets[2];
// ExcelWorkSheet2.Name = "标准报价数据";
#region 对第一个Sheet的操作
int rowcount1 ;
rowcount1 = (int)dt.Rows.Count;
//填充第一个Sheet的说明和表头
ExcelWorkSheet1.Cells[1, 1] = "报表测试";
ExcelWorkSheet1.Cells[2, 1] = "ID";
ExcelWorkSheet1.Cells[2, 2] = "NAME";
//填充第一个Sheet的数据
int i;
for (i = 0; i < rowcount1; i++)
{
ExcelWorkSheet1.Cells[i + 3, 1] = dt.Rows[i][0].ToString().Trim();
ExcelWorkSheet1.Cells[i + 3, 2] = dt.Rows[i][1].ToString().Trim();
}
#endregion
#region 对第二个Sheet的操作
#endregion
try
{
//给Excel文件命名
string newFilename = "标准报价_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("hhmmss") + ".xls";
//另存为Excel文件
ExcelWorkBook.SaveAs("D:\\33" + newFilename, missing, missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlExclusive, missing, missing, missing, missing, missing);
ExcelWorkBook.Close(false, null, null);
//删除Copy后的文件
newFile.Delete();
ExcelWorkSheet1 = null;
ExcelApp.Quit();
System.GC.Collect();
}
catch (Exception ex)
{
if (ex.Message != "")
{
//记录错误日志
this.Response.Write("error:" + ex.Message);
}
}
}
}