/***************************************************** * - Function name : ButtonRefresh1_Click * - Description : 刷新第一个汇总表 * - Variables : object sender, EventArgs e *****************************************************/ protected void ButtonRefresh1_Click(object sender, EventArgs e) { // 查看是否已登录 if (Session["FinanceDepartmentUsername"] == null) { Response.Write("<script>alert('请先登录!');</script>"); return; } // 实例化一个DataManager服务类 DataManagerService DMS = new DataManagerService(); // 查询机型个数 int N = DMS.getPhoneKinds(); // 建立数组缓存机型编号 string[] pid = new string[N]; // 读取机型编号 int i = 0; string link = string.Format("server={0};User Id={1};password={2};Database={3}", MDB.getServer(), MDB.getUser(), MDB.getPassword(), MDB.getDatabase()); MySqlConnection mycon = new MySqlConnection(link); mycon.Open(); string sql = string.Format("select p_id from phone_table"); MySqlCommand mycmd = new MySqlCommand(sql, mycon); MySqlDataReader reader = null; reader = mycmd.ExecuteReader(); while (reader.Read()) { pid[i++] = reader[0].ToString(); } reader.Close(); mycon.Close(); // 挨个机型汇总 for (i = 0; i < N; i++) { int amount = 0; // 数量 double summary = 0; // 总价 int received = 0; // 已收货 int unreceived = 0; // 未收货 int purAmount = 0; // 总单数 // 统计数量 amount = DMS.getAmountOf("sum(pur_amount)", "purchase_detail_table", ""); // 统计总价 summary = DMS.getAmountOf("sum(p_summary)", "purchase_detail_table", ""); // 统计已收货数量 received = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pur_received='是'"); // 统计未收货数量 unreceived = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pur_received='否'"); // 统计总单数 purAmount = DMS.getAmountOf("count(*)", "purchase_detail_table", "where p_id='" + pid[i] + "'"); // 查看汇总表是否有机型记录 int hash = 0; hash = DMS.getAmountOf("count(*)", "purchase_summary_good_table", "where p_id='" + pid[i] + "'"); // 存回数据库 if (hash == 0) { // 当之前没有该机型信息汇总,插入操作 if (!DMS.saveSummary(pid[i], amount, summary, received, unreceived, purAmount, "insert")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid + "]');</script>"); } } else { // 存在汇总操作时进行更新 if (!DMS.saveSummary(pid[i], amount, summary, received, unreceived, purAmount, "update")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid + "]');</script>"); } } } // 提示完成 Response.Write("<script>alert('汇总完成');</script>"); // 刷新 Label1.Text = "上一次汇总:" + System.DateTime.Now.ToString(); bind(SELECT_GOOD_SUMMARY, 1); }
/***************************************************** * - Function name : ButtonRefresh2_Click * - Description : 刷新第二个汇总表 * - Variables : object sender, EventArgs e *****************************************************/ protected void ButtonRefresh2_Click(object sender, EventArgs e) { // 查看是否已登录 if (Session["FinanceDepartmentUsername"] == null) { Response.Write("<script>alert('请先登录!');</script>"); return; } // 实例化一个DataManager服务类 DataManagerService DMS = new DataManagerService(); // 查询供应商个数 int N = DMS.getProviders(); // 建立数组缓存供应商编号 string[] pid = new string[N]; // 读取机型编号 int i = 0; string link = string.Format("server={0};User Id={1};password={2};Database={3}", MDB.getServer(), MDB.getUser(), MDB.getPassword(), MDB.getDatabase()); MySqlConnection mycon = new MySqlConnection(link); mycon.Open(); string sql = string.Format("select pr_number from provider_table"); MySqlCommand mycmd = new MySqlCommand(sql, mycon); MySqlDataReader reader = null; reader = mycmd.ExecuteReader(); while (reader.Read()) { pid[i++] = reader[0].ToString(); } reader.Close(); mycon.Close(); // 挨个供应商汇总 for (i = 0; i < N; i++) { int amount = 0; // 数量 double summary = 0; // 总价 int kinds = 0; // 商品种类 int finished = 0; // 已完成订单 int unfinished = 0; // 未完成订单 // 统计数量 amount = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pr_number='" + pid[i] + "'"); // 统计总价 summary = DMS.getAmountOf("sum(p_summary)", "purchase_detail_table", "where pr_number='" + pid[i] + "'"); // 统计已收货数量 kinds = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pur_received='是' and pr_number='" + pid[i] + "'"); // 统计未收货数量 finished = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pur_received='否' and pr_number='" + pid[i] + "'"); // 统计总单数 unfinished = DMS.getAmountOf("count(*)", "purchase_detail_table", "where pr_number='" + pid[i] + "'"); // 查看汇总表是否有相关供应商记录 int hash = 0; hash = DMS.getAmountOf("count(*)", "purchase_summary_provider_table", "where pr_number='" + pid[i] + "'"); // 存回数据库 if (hash == 0) { // 当之前没有该机型信息汇总,插入操作 if (!DMS.saveProviderSummary(pid[i], amount, summary, kinds, unfinished, finished, "insert")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid + "]');</script>"); } } else { // 存在汇总操作时进行更新 if (!DMS.saveProviderSummary(pid[i], amount, summary, kinds, unfinished, finished, "update")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid + "]');</script>"); } } } // 提示完成 Response.Write("<script>alert('汇总完成');</script>"); // 刷新 Label2.Text = "上一次汇总:" + System.DateTime.Now.ToString(); bind(SELECT_PROVIDER_SUMMARY, 2); }
/***************************************************** * - Function name : ButtonRefresh_Click * - Description : 刷新汇总数据 * - Variables : object sender, EventArgs e *****************************************************/ protected void ButtonRefresh_Click(object sender, EventArgs e) { // 查看是否已登录 if (Session["FinanceDepartmentUsername"] == null) { Response.Write("<script>alert('请先登录!');</script>"); return; } // 实例化一个DataManager服务类 DataManagerService DMS = new DataManagerService(); // 查询售出过的机型个数 int N = DMS.getSaledPhones(); // 建立缓存数组 string[] pid = new string[N]; // 挨个汇总 int i = 0; double sum = 0; for (i = 0; i < N; i++) { int store = 0; // 库存量 int saled = 0; // 售出量 double earned = 0; // 总收入 try { // 统计库存量 store = DMS.getAmountOf("count(*)", "phone_detail_table", "where p_id='" + pid[i] + "' and saled='否'"); // 统计售出量 saled = DMS.getAmountOf("count(*)", "sale_detail_table", "where p_id='" + pid[i] + "'"); // 总收入 earned = DMS.getSaledSummary(pid[i]); sum += earned; // 查看汇总表是否有机型记录 int hash = 0; hash = DMS.getAmountOf("count(*)", "sale_summary_table", "where p_id='" + pid[i] + "'"); // 存回数据库 if (hash == 0) { // 当之前没有该机型信息汇总,插入操作 if (!DMS.saveSaledSummary(pid[i], store, saled, earned, "insert")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid[i] + "]');</script>"); } } else { // 存在汇总操作时进行更新 if (!DMS.saveSaledSummary(pid[i], store, saled, earned, "update")) { Response.Write("<script>alert('汇总过程出错[机型:" + pid[i] + "]');</script>"); } } } catch (Exception ex) { } } // 提示完成 Response.Write("<script>alert('汇总完成');</script>"); // 修改总收入显示 LabelSummary.Text = "总收入:" + sum + "元"; }