예제 #1
0
        public void Init(DbType type)
        {
            Console.WriteLine("启动Tran.Init");
            using (ISqlSugarClient db = SugarDao.GetInstance(type)) //开启数据库连接
            {
                db.CommandTimeOut = 30000;                          //设置超时时间
                try
                {
                    db.BeginTran();//开启事务
                    //db.BeginTran(IsolationLevel.ReadCommitted);+3重载可以设置事世隔离级别

                    db.CommitTran();//提交事务
                }
                catch (Exception)
                {
                    db.RollbackTran();//回滚事务
                    throw;
                }
            }
        }
예제 #2
0
        //上传西服上衣尺码表
        public static bool Import_Excel_jacket(DataTable table, string size_code, string gender, out string errmsg)
        {
            using (ISqlSugarClient idb = DbRepository.GetInstance(SqlSugarRepository.DbType.SqlServer, SqlSugerHelper.SqlConnString))
                try
                {
                    //    idb.CommandTimeOut = 3000;//设置超时时间

                    List <CoatSize> list = new List <CoatSize>();

                    idb.BeginTran();

                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        #region 处理不符合要求得数据

                        DataRow row = table.Rows[i];

                        row.BeginEdit();

                        for (int a = 0; a < table.Columns.Count; a++)
                        {
                            if (row[a].ToString().IndexOf("....") > 0)
                            {
                                row[a] = row[a].ToString().Replace("....", ".");
                            }
                            if (row[a].ToString().IndexOf("...") > 0)
                            {
                                row[a] = row[a].ToString().Replace("...", ".");
                            }
                            if (row[a].ToString().IndexOf("..") > 0)
                            {
                                row[a] = row[a].ToString().Replace("..", ".");
                            }
                        }

                        row.EndEdit();

                        #endregion
                        if (!string.IsNullOrEmpty(gender))
                        {
                            object ruid;
                            if (gender == "男")
                            {
                                Entity.XF_SY_NAN_ChiMaEntity cs = new Entity.XF_SY_NAN_ChiMaEntity();

                                cs.Height = Convert.ToDecimal(table.Rows[i]["Height"]);

                                cs.FrontLength = table.Rows[i]["FrontLength"] + "";

                                cs.NetBust = table.Rows[i]["NetBust"] + "";

                                cs.FinishedBust = Convert.ToDecimal(table.Rows[i]["FinishedBust"]);

                                cs.InWaist = Convert.ToDecimal(table.Rows[i]["InWaist"]);

                                cs.FinishedHem_NoFork = Convert.ToDecimal(table.Rows[i]["FinishedHem_NoFork"]);

                                cs.FinishedHem_SplitEnds = Convert.ToDecimal(table.Rows[i]["FinishedHem_SplitEnds"]);

                                cs.ShoulderWidth = Convert.ToDecimal(table.Rows[i]["ShoulderWidth"]);

                                cs.Size_Code = size_code;

                                cs.Sleecve_Show = table.Rows[i]["FK_Sleeve_ID"] + "";

                                cs.CreateDateTime = DateTime.Now;

                                cs.IsDeleted = false;

                                cs.Status = 1;

                                cs.RowData = table.Rows[i]["Height"] + "-" + table.Rows[i]["FrontLength"] + "-" + table.Rows[i]["NetBust"] + "-" + table.Rows[i]["FinishedBust"] + "-" + table.Rows[i]["InWaist"] + "-" + table.Rows[i]["FinishedHem_NoFork"] + "-" + table.Rows[i]["FinishedHem_SplitEnds"] + "-" + table.Rows[i]["ShoulderWidth"] + "-" + table.Rows[i]["FK_Sleeve_ID"];

                                ruid = idb.Insert(cs, true);
                            }
                            else
                            {
                                Entity.XF_SY_NU_CodeSizeEntity cs = new Entity.XF_SY_NU_CodeSizeEntity();

                                cs.Height = Convert.ToDecimal(table.Rows[i]["Height"]);

                                cs.FrontLength = table.Rows[i]["FrontLength"] + "";

                                cs.NetBust = table.Rows[i]["NetBust"] + "";

                                cs.FinishedBust = Convert.ToDecimal(table.Rows[i]["FinishedBust"]);

                                cs.InWaist = Convert.ToDecimal(table.Rows[i]["InWaist"]);

                                cs.FinishedHem_NoFork = Convert.ToDecimal(table.Rows[i]["FinishedHem_NoFork"]);

                                cs.SleeveWidth = Convert.ToDecimal(table.Rows[i]["SleeveWidth"]);

                                cs.ShoulderWidth = Convert.ToDecimal(table.Rows[i]["ShoulderWidth"]);

                                cs.Size_Code = size_code;

                                cs.Sleecve_Show = table.Rows[i]["FK_Sleeve_ID"] + "";

                                cs.CreateDateTime = DateTime.Now;

                                cs.IsDeleted = false;

                                cs.Status = 1;

                                cs.RowData = table.Rows[i]["Height"] + "-" + table.Rows[i]["FrontLength"] + "-" + table.Rows[i]["NetBust"] + "-" + table.Rows[i]["FinishedBust"] + "-" + table.Rows[i]["InWaist"] + "-" + table.Rows[i]["FinishedHem_NoFork"] + "-" + table.Rows[i]["SleeveWidth"] + "-" + table.Rows[i]["ShoulderWidth"] + "-" + table.Rows[i]["FK_Sleeve_ID"];

                                ruid = idb.Insert(cs, true);
                            }


                            string req = table.Rows[i]["FK_Sleeve_ID"] + "";

                            if (req.IndexOf("      ") > 0)
                            {
                                req = req.Replace("      ", "^");
                            }

                            if (req.IndexOf("     ") > 0)
                            {
                                req = req.Replace("     ", "^");
                            }

                            if (req.IndexOf("    ") > 0)
                            {
                                req = req.Replace("    ", "^");
                            }

                            if (req.IndexOf("   ") > 0)
                            {
                                req = req.Replace("   ", "^");
                            }

                            if (req.IndexOf("  ") > 0)
                            {
                                req = req.Replace("  ", "^");
                            }

                            req = req.Replace(" ", "^");

                            req = req.Replace(":", ";");

                            string[] sleeve_arrey = req.Split('^');

                            Sleeve see = new Sleeve();
                            see.FK_CoatSize_ID = Convert.ToInt32(ruid);
                            see.Code           = sleeve_arrey[0].Split(';')[0];
                            see.Length         = Convert.ToDecimal(sleeve_arrey[0].Split(';')[1]);
                            idb.Insert(see);
                        }
                    }

                    idb.CommitTran();
                    errmsg = "";
                    return(true);
                }
                catch (Exception ex)
                {
                    idb.RollbackTran();//回滚事务
                    errmsg = ex.Message;
                    return(false);
                }
        }