Ejemplo n.º 1
0
        /// <summary>
        /// 更新评论数
        /// </summary>
        /// <param name="songId">songId</param>
        /// <param name="count">count</param>
        public void UpdateCount(int songId, int count)
        {
            StringBuilder   updateCmd = new StringBuilder();
            MySqlConnection conn      = null;

            try
            {
                using (conn = new MySqlConnection(mysqlAddress))
                {
                    //StringBuilder updateCmd = new StringBuilder();
                    updateCmd.AppendFormat("update music_v2 set count = {0} where songId = {1}", count, songId);
                    string updateCmdstr = updateCmd.ToString();
                    //private string updateCmd = "update music_v2 set count ";
                    using (MySqlCommand cmd = new MySqlCommand(updateCmdstr, conn))
                    {
                        conn.Open();
                        //执行sql
                        cmd.ExecuteNonQuery();
                        updateCmd.Clear();
                    }
                }
            }
            catch (Exception e)
            {
                TxtLog txtlog = new TxtLog();
                txtlog.log(e.ToString() + "\n" + updateCmd + "\n", 0);
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            //MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
            //adp.SelectCommand = cmd;
            //DataSet ds = new DataSet();
            ////填充dataset
            //adp.Fill(ds);
        }
Ejemplo n.º 2
0
        public ActionResult UploadCustLoadFile()
        {
            try
            {
                HttpPostedFileBase fb         = Request.Files[0];
                string             tempGuid   = Guid.NewGuid().ToString();
                string             folderPath = Server.MapPath(CHubConstValues.ChubTempFolder);
                FileInfo           folder     = new FileInfo(folderPath);
                if (!Directory.Exists(folder.FullName))
                {
                    Directory.CreateDirectory(folder.FullName);
                }

                //fb.filename - to get short file name parse string
                string        errorLogName     = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + tempGuid + ".txt";
                string        errorLogWebName  = "/temp/" + errorLogName;
                string        errorLogFullName = folder.FullName + errorLogName;
                TxtLog        txtLog           = new TxtLog();
                StringBuilder errorMsg         = new StringBuilder();
                errorMsg.AppendLine(string.Format("Current User:{0}", Session[CHubConstValues.SessionUser].ToString()));

                string fileFullName = folder.FullName + tempGuid + ".xlsx";
                fb.SaveAs(fileFullName);

                NPOIExcelHelper excelHelper = new NPOIExcelHelper(fileFullName);
                DataTable       dt          = excelHelper.ExcelToDataTable();
                //Delete temp file
                System.IO.File.Delete(fileFullName);

                if (dt == null || dt.Rows.Count == 0)
                {
                    return(Content("No data in excel"));
                }

                //DataTable dt = ExcelHelper.GetDTFromExcel(fileFullName);
                List <ITT_CUST_LOAD> modelList = ClassConvert.ConvertDT2List <ITT_CUST_LOAD>(dt);

                if (modelList == null || modelList.Count == 0)
                {
                    return(Content("wrong excel strut"));
                }

                int successCount = 0;
                int failCount    = 0;
                foreach (var item in modelList)
                {
                    string msg = SaveCustLoadAction(item);
                    if (string.IsNullOrEmpty(msg))
                    {
                        successCount++;
                        LogHelper.WriteLog(string.Format("willBillNo:{0},data:{1}", item.WILL_BILL_NO, JsonConvert.SerializeObject(item)));
                    }
                    else
                    {
                        failCount++;
                        LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item)));
                        errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item)));
                    }
                }

                bool success = true;
                if (failCount > 0)
                {
                    txtLog.log(errorMsg.ToString(), errorLogFullName);
                    success = false;
                }
                return(Json(new RequestResult(success, string.Format("Total Lines:{0}, Success items:{1}, Fail items:{2}", modelList.Count, successCount, failCount), errorLogWebName)));
                //return Content(string.Format("Total Lines:{0}, Success items:{1}, Fail items:{2}", modelList.Count, successCount, failCount));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("save Cust load", ex);
                return(Json(new RequestResult(false, ex.Message)));
            }
        }
Ejemplo n.º 3
0
        public ActionResult UploadTranLoadFile()
        {
            try
            {
                HttpPostedFileBase fb         = Request.Files[0];
                string             tempGuid   = Guid.NewGuid().ToString();
                string             folderPath = Server.MapPath(CHubConstValues.ChubTempFolder);
                FileInfo           folder     = new FileInfo(folderPath);
                if (!Directory.Exists(folder.FullName))
                {
                    Directory.CreateDirectory(folder.FullName);
                }
                //fb.filename - to get short file name parse string
                string        errorLogName     = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + tempGuid + ".txt";
                string        errorLogWebName  = "/temp/" + errorLogName;
                string        errorLogFullName = folder.FullName + errorLogName;
                TxtLog        txtLog           = new TxtLog();
                StringBuilder errorMsg         = new StringBuilder();
                errorMsg.AppendLine(string.Format("Current User:{0}", Session[CHubConstValues.SessionUser].ToString()));

                string fileFullName = folder.FullName + tempGuid + ".xlsx";
                fb.SaveAs(fileFullName);

                NPOIExcelHelper excelHelper = new NPOIExcelHelper(fileFullName);
                DataTable       dt          = excelHelper.ExcelToDataTable();

                //LogHelper.WriteLog("DT data:"+dt.Rows[0][3].ToString() +"|"+ dt.Rows[0][4].ToString() + "|" + dt.Rows[0][5].ToString());
                //Delete temp file
                System.IO.File.Delete(fileFullName);

                if (dt == null || dt.Rows.Count == 0)
                {
                    return(Json(new RequestResult(false, "No data in excel")));
                }

                //DataTable dt = ExcelHelper.GetDTFromExcel(fileFullName);
                List <ITT_TRAN_LOAD> modelList = ClassConvert.ConvertDT2List <ITT_TRAN_LOAD>(dt);

                if (modelList == null || modelList.Count == 0)
                {
                    return(Json(new RequestResult(false, "wrong excel struct")));
                }

                int successCount = 0;
                int failCount    = 0;
                foreach (var item in modelList)
                {
                    if (item.INVOICE_NO != null && item.INVOICE_NO.Contains("/"))
                    {
                        string[] invoiceArray = item.INVOICE_NO.Split('/');
                        foreach (var inNo in invoiceArray)
                        {
                            ITT_TRAN_LOAD model = new ITT_TRAN_LOAD();
                            ClassConvert.DrawObj(item, model);
                            model.INVOICE_NO = inNo.Trim();

                            string msgInside = SaveTranLoadAction(model);
                            if (string.IsNullOrEmpty(msgInside))
                            {
                                successCount++;
                                LogHelper.WriteLog(string.Format("willBillNo:{0},Data:{1}", item.WILL_BILL_NO, JsonConvert.SerializeObject(item)));
                            }
                            else
                            {
                                failCount++;
                                LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item)));
                                errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item)));
                                //txtLog.log(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item)), errorLogFullName);
                            }
                        }
                    }
                    else
                    {
                        //If no invoce no , do a prefill ation
                        if (string.IsNullOrEmpty(item.INVOICE_NO))
                        {
                            TranLoadPreFill result = PreFillTranLoadAction(item.WILL_BILL_NO);
                            if (!string.IsNullOrEmpty(result.Msg))
                            {
                                failCount++;
                                LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, result.Msg, JsonConvert.SerializeObject(item)));
                                errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, result.Msg, JsonConvert.SerializeObject(item)));
                                continue;
                            }
                            else
                            {
                                //prefill action
                                item.INVOICE_NO  = result.InvoiceNo;
                                item.TRAN_TYPE   = result.TranType;
                                item.FROM_SYSTEM = result.FromSystem;
                            }
                        }

                        string msg = SaveTranLoadAction(item);
                        if (string.IsNullOrEmpty(msg))
                        {
                            successCount++;
                            LogHelper.WriteLog(string.Format("willBillNo:{0},Data:{1}", item.WILL_BILL_NO, JsonConvert.SerializeObject(item)));
                        }
                        else
                        {
                            failCount++;
                            LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item)));
                            errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item)));
                        }
                    }
                }

                bool success = true;
                if (failCount > 0)
                {
                    txtLog.log(errorMsg.ToString(), errorLogFullName);
                    success = false;
                }
                return(Json(new RequestResult(success, string.Format("Total Lines:{0}, Success items:{1}, Fail items:{2}", modelList.Count, successCount, failCount), errorLogWebName)));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("UploadTranLoadFile", ex);
                return(Json(new RequestResult(false, ex.Message)));
            }
        }